All,
Good evening. I am using the PIC18F2423 and am trying to use the ADC with PICBasic Pro. To test it's functionality, I am using a modified version of Project 5 from Chuck Hellebuyck's Programming PIC uCs with PicBasic. Depending in the AD reading, the uC should lights up LEDs attached to PortC (with current-limiting resistors).
Unfortunately, I can only get one LED to briefly flash on, then off.
Note I am using a 4MHz crystal for the uCs clock, and am trying to use the uCs RC oscillator for the A/D conversion. I'm pretty sure my problem is something with the settings in the ADC control register. My program is as follows:
'Define ADCIN Parameters
Define ACD_CLOCK 3
Define ADC_SAMPLEUS 16
'Configure Microcontroller I/O Ports
TrisA = %11111111
TrisB = %00000000
TrisC = %00000000
'Define Constants and Variables
VOLT var word
Init:
PortB = %11111111
PortC = %00000000
ADCON1 = %00001100
ADCON2 = %10000111 'A/D Conversion clock select
LOOP:
ADCON0 = %00000001
ADCIN 0, VOLT
PAUSEUS 14
LEDtst1:
if VOLT > 400 then tst2
PortC = %00000001
GOTO cont
tst2:
if VOLT > 1200 then tst3
PortC = %00000011
GOTO cont
tst3:
if VOLT > 2000 then tst4
PortC = %00000111
GOTO cont
tst4:
if VOLT > 2800 then tst5
PortC = %00001111
GOTO cont
tst5:
PortC = %00011111
cont:
Pause 100
GOTO LOOP
END
Bookmarks