Hello,
I have written code for 10-bit A/D conversion with PIC18F2455, but not working properly, value on LCD display is not correct.
I used sample code from melbas written for 10-bit A/D conversion on LCD for PIC18F4550.
I only changed values for define LCD registers and bits.
http://melabs.com/samples/LABXUSB-18F4550/adci10xu.htm
I using 20MHz external oscillator.
What is problem?
Thank you
Here is my code:
Define LOADER_USED 1
DEFINE OSC 48
' Define LCD registers and bits
Define LCD_DREG PORTB
Define LCD_DBIT 4
Define LCD_RSREG PORTC
Define LCD_RSBIT 7
Define LCD_EREG PORTC
Define LCD_EBIT 6
DEFINE LCD_BITS 4 ' 4-bit data bus
DEFINE LCD_LINES 2 ' LCD - 2 lines
' Define ADCIN parameters
Define ADC_BITS 10 ' Set number of bits in result
Define ADC_CLOCK 3 ' Set clock source (3=rc)
Define ADC_SAMPLEUS 50 ' Set sampling time in uS
adval var word ' Create adval to store result
TRISA = %11111111 ' Set PORTA to all input
ADCON1 = %00001010 ' Set PORTA analog...
ADCON2 = %10000000 ' ...and right justify result
Pause 500 ' Wait .5 second
loop: ADCIN 0, adval ' Read channel 0 to adval
Lcdout $fe, 1 ' Clear LCD
Lcdout "Value: ", DEC adval ' Display the decimal value
Pause 100 ' Wait .1 second
Goto loop ' Do it forever
End
Bookmarks