Ok, if you load your code into MPLAB (
www.microchip.com) and run it, you will see the following error generated....
"ADC-W0010: A Minimum of 2 TADs are required before another conversion should be started."
In other words, you need to leave a delay before starting another conversion. Depending how fast you are clocking this device, will depend on how long you need to wait.
So something like......
clrf 0x30
wait_2tad:
decfsz 0x30,f
goto wait_2tad ;wait 256 clks
This will wait 256 clks, but this may be too short/long, check it out
Also a.....
movlw 0x7f
movwf TRISA
After (or before) your TRISC wouldn't go amis, I know it's supposed to power-up as inputs, but it's good practice to included it.
Just another problem waiting to get you is that this processor has 2 inturupt vectors at 0x04 and 0x08, if you put code into these areas and don't disable all the int's then fun things will start to happen!
Just go over the data sheet again, pages 181->187, it takes you step by step through the ADC.
I may have also missed the setting of another register, just got that feeling
PIC's have a habit of not playing nice, and the data sheets don't always spell it out (well only after you know what went wrong, and you find it!).
Anyone else got any input (i.e. tell me what I have missed!)?
List p=18f452,f=inhx32
#include <p18f452.inc>
org 0x0000
clrf PORTC
movlw 0x00
movwf TRISC
movlw 0x7f
movwf TRISA
movlw B'11000000'
movwf ADCON1
movlw B'11000001'
movwf ADCON0
again:
bsf ADCON0, GO
Wait:
btfsc ADCON0,GO ;Wait for conversion to complete
goto Wait
movf ADRESH,W ;Write A/D result to PORTC
movwf PORTC ;LEDs
clrf 0x30
wait_2tad:
decfsz 0x30,f
goto wait_2tad ;wait 256 clks
goto again
end
Hope this helps