Hi Jeff,
> This code did the trick. Thing is, it was no different than my
> previous attempts except for using B4-B7 instead of B0-B3.
> There must be a trick I'm missing somewhere.
I'm not sure why it wouldn't work for you assuming you had everything connected per your LCD DEFINE's.
I'm sure if you look "very" carefully at how you had everything physically connected, then look at your previous LCD DEFINE's - you'll find your answer.
For your A/D try this. It's using the previous 16F88 LCD example that's already working for you - so it should work as-is.
Note: 1st measure your +Vref (ground & Vdd). If it's < or > 5V, then simply change the quanta value.
Example: If you measure 4.95V from gnd & Vdd, then +Vref = 4.95V : Quanta=4.95V/1023*256=1.238=1238.
The result is fairly accurate @ +/- ~0.01V.
@ DEVICE INTRC_OSC, LVP_OFF, WDT_OFF, MCLR_OFF
define OSC 8
Define LCD_DREG PORTB
Define LCD_DBIT 4
Define LCD_RSREG PORTB
Define LCD_RSBIT 3
Define LCD_EREG PORTB
Define LCD_EBIT 2
DEFINE LCD_COMMANDUS 2000
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
Quanta con 1251 ' +Vref = 5V : Quanta=5V/1023*256=1.251
Line1 CON $80
ADval var word ' Create ADval word-sized variable to store result
TRISA = %11111111 ' Set PORTA to all input
CMCON = %00000111 ' Disable analog comparators
ANSEL = %00000001 ' Set PORTA.0 = A/D in, rest digital
ADCON1 = %10000000 ' Right Justify A/D result
OSCCON = %01110000 ' INTRC = 8MHz
Pause 500 ' Wait for LCD to startup
loop:
ADCIN 0, ADval ' Read A/D on RA0
ADval = (ADval*10) */ Quanta
LCDOUT $FE, 1 ' Clear LCD
LCDOUT $FE, Line1+3,dec ADval dig 4,".",dec4 ADval,"Vdc"
Pause 1000
Goto loop ' Do it forever
Bookmarks