|
Example: My First AD Conversion
The following code sample is one simple loop for performing AD conversion on MCU PORTA and displaying results on PORTB. Examine these lines and note that our humble example deals with highly complicated task of AD conversion. mikroC spares you from consulting the manual for specific MCU, code adjustments for different PIC models, and address arithmetic... Just let the compiler take care of it - simply and efficiently.
int temp_res;
void main() {
ADCON1 = 0x80; // Configure analog inputs and Vref
TRISA = 0xFF; // PORTA is input
TRISB = 0x3F; // RB7, RB6 pins are output
TRISD = 0; // PORTD is output
do {
temp_res = Adc_Read(2);
PORTD = temp_res; // send lower 8 bits to PORTD
PORTB = temp_res >> 2;
// send two most significant bits to PORTB, pins RB7,RB6
} while (1);
}
|