mikroC
- C Compiler for Microchip PIC microcontrollers
mikroC
making it simple...
140
MikroElektronika:
Development
tools
-
Books
-
Compilers
page
Library Example
/* This code snippet reads analog value from channel 2 and displays
it on PORTD (lower 8 bits) and PORTB (2 most significant bits). */
unsigned temp_res;
void main() {
ADCON1 = 0x80;
// Configure analog inputs and Vref
TRISA = 0xFF;
// PORTA is input
TRISB = 0x3F;
// Pins RB7, RB6 are outputs
TRISD = 0;
// PORTD is output
do {
temp_res = Adc_Read(2);
// Get results of AD conversion
PORTD = temp_res;
// Send lower 8 bits to PORTD
PORTB = temp_res >> 2;
// Send 2 most significant bits to RB7, RB6
} while(1);
}
Kommentare zu diesen Handbüchern