unsigned int temp_res;
void main() {
ANSEL = 0x04; // Configure AN2 pin as analog
ANSELH = 0; // Configure other AN pins as digital I/O
C1ON_bit = 0; // Disable comparators
C2ON_bit = 0;
TRISA = 0xFF; // PORTA is input
TRISC = 0; // PORTC is output
TRISB = 0; // PORTB is output
do {
temp_res = ADC_Read(2); // Get 10-bit results of AD conversion
PORTB = temp_res; // Send lower 8 bits to PORTB
PORTC = temp_res >> 8; // Send 2 most significant bits to RC1, RC0
} while(1);
}
program ADC_on_LEDs
dim temp_res as word
main:
ANSEL = 0x04 ' Configure AN2 pin as analog
ANSELH = 0 ' Configure other AN pins as digital I/O
C1ON_bit = 0 ' Disable comparators
C2ON_bit = 0
TRISA = 0xFF ' PORTA is input
TRISB = 0 ' PORTB is output
TRISC = 0 ' PORTC is output
while (TRUE)
temp_res = ADC_Read(2) ' Get 10-bit results of AD conversion
PORTB = temp_res ' Send lower 8 bits to PORTB
PORTC = word(temp_res >> 8) ' Send 2 most significant bits to RC1, RC0
wend
end.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 unsigned int temp_res; void main() { ANSEL = 0x04; // Configure AN2 pin as analog ANSELH = 0; // Configure other AN pins as digital I/O TRISA = 0xFF; // PORTA is input TRISC = 0; // PORTC is output TRISB = 0; // PORTB is output do { temp_res = ADC_Read(2); // Get 10-bit results of AD conversion PORTB = temp_res; // Send lower 8 bits to PORTB PORTC = temp_res >> 8; // Send 2 most significant bits to RC1, RC0 } while(1); }
CM1CON0 = 0x80;
CM2CON0 = 0x80;
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?