Hi guys I'm trying to read the voltage from a 12 v battery i have a perfect 3:1 voltage divider but i can't seem to get any accurate readings i think something is wrong with my formulas and i can't seem to grasp it. here is what i have so far if anyone can help.
TRISA = %11111111
TRISB = %00000000
TRISC = %00000000
DEFINE OSC 20
DEFINE LCD_DREG PORTB 'LCD data port
DEFINE LCD_DBIT 4 'LCD data starting bit 0 or 4
DEFINE LCD_RSREG PORTB 'LCD register select port
DEFINE LCD_RSBIT 1 'LCD register select bit
DEFINE LCD_EREG PORTB 'LCD enable port
DEFINE LCD_EBIT 0 'LCD enable bit
DEFINE LCD_BITS 4 'LCD bus size 4 or 8
DEFINE LCD_LINES 2 'Number lines on LCD
Define ADC_BITS 10 ' Set number of bits in result
Define ADC_CLOCK 0 ' Set clock source
Define ADC_SAMPLEUS 50' Set sampling time in uS
ADCON1 = 142
bat_volts var word
Start:
ADCIN porta.0, bat_volts
bat_volts = (bat_volts */500)>> 2
LCDout $FE, 1 , " Voltage In"
LCDout $FE, $C0, " ", dec(bat_volts/100 *3),".",dec1 bat_volts, " V"
pause 200
goto start
end
Bookmarks