gamersat678
Junior Member level 1
For the past day I've been trying to get adc to work and generate a voltage reading (0-5v) using either pin ra0 or ra2. I just can't get my code to work. I'm programming in Mikrobasic. Does anyone have any source plus a simple circuit schematic to show me how this works, or example source that would work with the built in parts of the pickit2 starter kit?
This is what I have.
This is what I have.
Code:
program ADC
dim adc_rd as word
main:
ANSEL = 0xff ' Configure AN2 pin as analog
TRISA =%1111111 ' PORTA is input
ANSELH = 0 ' Configure other AN pins as digital I/O
TRISC = 0
TRISB = 0 ' PORTB is output
'ADCON1 = %01100000
while (TRUE)
'Read pin ra2
adc_rd = ADC_Read(2) '*5/1023 ' get ADC value from 2nd channel
if adc_rd>1 then
portc.1=1
end if
portc.0=1
delay_ms(100)
wend
portc.0=0
end.