Here's where copy-paste has gotten you into trouble all over again.
All pic's aren't the same, so what you did/copied for one device may not work for another.
You need to actually read the datasheet for the part you're using, or at least
check that the register settings you have in your code match up to the chip.
For example, here are some comments for what you had:
Code:
Device=18F43K22
// THIS DOES NOT SET "PORTE as digital (LCD)"
// ADCON1 selects the positive and negative reference for the ADC
ADCON1 = $07 // PORTE as digital (LCD)
// THIS IS TRUE
TRISA.0 = 1 // configure AN0 as an input
// THIS DOES NOT "set analogue input on PORTA.0"
// IT SELECTS THE SPECIAL TRIGGER FROM CTMU
ADCON1.7 = 1 // set analogue input on PORTA.0
DelayMS (500)
LCD.Cls
Output(led)
// IF THE ABOVE HAD DONE WHAT YOU WANTED, IT WAS TO NO AVAIL
// SINCE CALLING "SetAllDigital" NOW WILL WIPE OUT MOST/ALL THE ABOVE SETTINGS
SetAllDigital
And here's the real mind-blower... you don't have to set a pin's analog/digital mode to use the ADC.
As long as the pin is an input (use the INPUT statement) you can convert it.
You really only need to set a pin to analog mode to disable the digital input buffer which will not be happy with analog voltages at its input.
You DO, however have to set the "digital" pins to "digital mode" since they all power up as analog by default, and a pin in analog mode will always read as a '0' to the digital input.
Since all of that is probably gibberish, here are some tips
- use SetAllDigital at the beginning or your program, before you start doing anything else.
there is a subroutine called SetAnalogPort in the file SetDigitalIO.bas that you can use after that to set the one or two pins you want to use
with the ADC back to analog mode. That way you won't have to figure out the difference between how this works for all the different chips.
- use 'output' and 'input' statements and skip using the TRISx registers
- don't set a register when you have no idea what it does
Here's an example which sets all pins to digital except for RA0
Code:
device =18F43K22
include "setdigitalio.bas"
SetAllDigital
input(PORTA.0)
SetAnalogPort(AN0, ANA)
// rest of your code...