Microchip likes to switch things around a bit from time to time. Some PICs have the A/D channel select & conversion clock select bits in ADCON0. Some newer versions have moved a few bits into ADCON1. Of course this totally screws up 3rd party compilers with nifty
commands like ADCIN for using the A/D modules...;o}
ADCIN expects the first version. Where channel select & conversion clock select bits are in ADCON0.
Until MeLabs changes the PBP library commands to catch up, you'll need to do it the old yuck fashioned way.
This should work. If not let me know. Unfortunately, I don't have a 16F685 to test it out on.
Code:
@ DEVICE PIC16F685,MCLR_OFF,WDT_OFF,INTRC_OSC_NOCLKOUT,PROTECT_OFF
adcVar VAR WORD ' Create variable to store result
' Set PORTA to all input
TRISA = %11111111
' Set up ADCON1
ADCON0 = %10000001 ' right justify for 10-bit, select AN0 channel, A/D module enabled
ADCON1 = %00110000 ' A/D conversion clock = Frc
Pause 500 ' Wait .5 second
HIGH PORTB.6 ' Turn on status LED
main:
ADCON0.1=1 ' Set GO/DONE bit to start A/D conversion
WHILE ADCON0.1=1 ' Wait for it to complete
WEND
adcVar.HighByte = ADRESH ' Read high-byte of result
adcVar.LowByte = ADRESL ' Read low-byte of result
serout portb.7, 6, ["S.1 =", #adcVar]
Pause 10 ' Wait.01 second
GoTo main ' Do it forever
END
Bookmarks