I am trying to read 0v-150v on the LCD but I am having a rough time figuring it out. I have this code from a book by Dogan Ibrahim which explains how to read 0-5000mV on the LCD. I understood his code but I am trying to be able to read 150v but running into problems with values too big for word variable and converting from 5v to 150v. Can someone take a look at this short code and say if it is possible. If not does anyone know how this can be done. I try not to ask too many questions as I read a lot on the forum, but I am stuck and need some help. My thinking is after setting the voltage divider to as close as possible to 5 volts for the pic and 255 (adc) out would be the top end I would need to do some conversion but everthing I have tried I run into problems with overloading the word type variable. I have worked it out on paper and it works, but I stumble with decimals in the code. The pic is 16F73
Thanks to all.
' Variables
'
Res Var Word ' A/D converter result
Volts1 Var Word ' First part of result in mV
Volts2 Var Word ' Second part of result in mV
'
' Constants
'
Conv1 Con 19 ' 5000/256 = 19.53, this is the decimal part
Conv2 Con 53 ' This is the fractional part
TRISA = 1 ' RA0 (AN0) is input
TRISB = 0 ' PORT B is output
PAUSE 500 ' Wait 0.5sec for LCD to initialize
'
' Initialize the A/D converter
'
ADCON1 = 0 ' Make AN0 to AN4 as analog inputs,
' make reference voltage = VDD
ADCON0 = %11000001 ' A/D clock is internal RC, select channel AN0
' Turn on A/D converter
LCDOUT $FE, 1 ' Clear LCD
AGAIN:
'
' Start A/D conversion
'
ADCIN 0, Res ' Read Channel 0 data
Volts1 = Res * Conv1 ' Multiply by 19
Volts2 = Res * Conv2 ' Multiply by 53
Volts2 = Volts2 / 100
Volts1 = Volts1 + Volts2 ' Result in mV
LCDOUT $FE,2,"V=",DEC4 Volts1 ' Display result
PAUSE 1000 ' Wait 1 second
GOTO AGAIN ' Repeat
END ' End of program
Bookmarks