Hi all,
I've finished my experiment circuit to learn how to handle with ADC,capture, processing it and send out it's readings.
The circuit , using a 16F88 and a LM35 temp sensor reads temp. and voltage and sends the values to a LCD.
I used 10bit resolution, removed last digit from result and added a constant value to calibrate the temperature ( because i get a difference of +- 4ºC ).
For the voltage, since i'm reading from 13V, i used 3 resistor as voltage divider. Then again i added a constant value to calibrate the result.
The code is working and reason for this Thread is only to get feedback from you experient users about the code.
Please let me know you thoughts and tips if this can be improved
Thanks
Here is the code :
Codestart:
output portb.7
low portb.7
Define osc 4
' Define LCD pins
Define LCD_DREG PORTB
Define LCD_DBIT 0
Define LCD_RSREG PORTB
Define LCD_RSBIT 4
Define LCD_EREG PORTB
Define LCD_EBIT 5
Define LCD_BITS 4
'variables
va1 var word
va2 var word
a var byte
b var byte
c var byte
d var byte
e var byte
f var byte
g var byte
pause 200 'init LCD
lcdout $fe,1 'clear LCD
lcdout $fe,2," Voltage/Temp" 'lcd intro
pause 2500
lcdout $fe,1 'clear LCD
'Define ADCIN parameters
Define ADC_BITS 10 ' Set number of bits in result ( 8 or 10 bits )
Define ADC_CLOCK 3 ' Set clock source (3=rc)
Define ADC_SAMPLEUS 50 ' Set sampling time in uS
input porta.0
input porta.1
ADCON1 = %00000001 ' Set PORTA analog
loop:
ADCIN 0, va1 'Store ADC value to va1
va1=va1/10 'remove last digit
ADCIN 1, va2 'Store ADC value to va2
va2=va2/10 'divide by 10 to get xx,xºc
va2=va2 - 42 'calibration setting
va1=va1/10 'remove last digit
va1=va1*2 'multiply to compensate voltage divider
va1=va1+0179 'calibration setting
a=va2 dig 0 ' separate digits
b=va2 dig 1 ' separate digits
c=va2 dig 2 ' separate digits
d=va1 dig 0 ' separate digits
e=va1 dig 1 ' separate digits
f=va1 dig 2 ' separate digits
g=va1 dig 3 ' separate digits
high portb.7 'Led on indicating code running
lcdout $fe,2,"VOLTAGE..",#g,#f,",",#e,#d,"V" 'Show values Line 1 - Voltage
lcdout $fe,$c0,"TEMP.....",#c,#b,",",#a,"C" 'Show values Line 2 - Temperature
pause 250 'pause between readings
Goto loop
End
Bookmarks