#define ADC_BUS PORTC
#define ADC_OUT PINC
#define CS_HIGH (ADC_BUS |= 0x01)
#define CS_LOW (ADC_BUS &= 0x0E)
#define DIN_HIGH (ADC_BUS |= 0x02)
#define DIN_LOW (ADC_BUS &= 0x0D)
#define CLK_HIGH (ADC_BUS |= 0x08)
#define CLK_LOW (ADC_BUS &= 0x03)
unsigned int ADC_MCP3202(void) {
unsigned char ADC_Count = 0;
unsigned int ADC_Data_Temp = 0;
CS_HIGH;
CS_LOW;
DIN_HIGH;
CLK_LOW;
CLK_HIGH;
CLK_LOW;
DIN_HIGH;
CLK_HIGH;
CLK_LOW;
DIN_LOW;
CLK_HIGH;
CLK_LOW;
DIN_HIGH;
CLK_HIGH;
CLK_LOW;
CLK_HIGH;
CLK_LOW;
for(ADC_Count=0; ADC_Count<12; ADC_Count++) {
ADC_Data_Temp = ADC_Data_Temp << 1;
CLK_HIGH;
if((ADC_OUT >> 2))
ADC_Data_Temp = ADC_Data_Temp | 0x01;
CLK_LOW;
}
CS_HIGH;
CLK_HIGH;
return ADC_Data_Temp;
}