PDA

View Full Version : Missing "TENS" digit



yasky1
- 8th October 2012, 00:38
I made a 5 volt meter to monitor circuits. I have redesigned the circuit to monitor 12 volts. The circuit works fine, no issues there. My problem is in my program. The program doesn't show the "TENS" digit on the LCD Display. When I connect voltage to monitoring terminal, the LCD displays 2.05 volts instead of 12.05 volts. Could you look at my program and let me know where I need to modify it. Thanks, Greg

mackrackit
- 8th October 2012, 03:25
Please post your code, not a PDF.

yasky1
- 8th October 2012, 03:31
'@ DEVICE HS_OSC, WDT_OFF, BOD_OFF


'***************************DEFINITIONS*********** ***************
Define LCD_DREG PORTD
Define LCD_DBIT 4
Define LCD_RSREG PORTE
Define LCD_RSBIT 0
Define LCD_EREG PORTE
Define LCD_EBIT 1
define OSC 4
TRISA = %00001011

'**************************VARIABLES************** ****************

x var word
y var word
z var word
v var byte
r var byte
v2 var byte
v3 var byte
t var byte
v4 var byte
v5 var byte
v6 var byte
w var byte
v7 var byte
v8 var byte
v9 var byte
n var word
m var byte
v10 var byte
v11 var byte
v12 var byte

'ADCON1 = 4 ' Set PortA 0, 1, 3 to A/D inputs
ADCON1 = 2 ' Set PortA 0, 1, 2, 3, 4 to A/D inputs
Low PORTE.2 ' LCD R/W line low (W)
Pause 100 ' Wait for LCD to start

Goto mainloop ' Skip subroutines


'************************SUBROUTINES************** ************************

getad: ' Subroutine to read A/D Converter
PAUSEUS 50 ' Wait for A/D channel acquisition time
ADCON0.2 = 1 ' Start conversion
WHILE ADCON0.2 ' Wait for it to complete
WEND
Return


getx: ' Subroutine to read x value
ADCON0 = $41 ' Set A/D to Fosc/8, Channel 0, On
Gosub getad
x = ADRESH
' Calculations to convert x value to volts
v = 5 * x / 255 * 4 ' Added * 4 to multiply reading back to 12 volts
r = 5 * x // 255 * 4
v2 = 100 * r / 255
v3 = 100 * r // 255
v3 = 10 * v3 / 255
IF (v3 >= 5) THEN v2 = v2 + 1
IF (v2 >= 100) THEN
v = v + 1
v2 = 0
ENDIF
Return


gety: ' Subroutine to read y value
ADCON0 = $49 ' Set A/D to Fosc/8, Channel 1, On
Gosub getad
y = ADRESH

v4 = 5 * y / 255 ' Calculations to convert y value to volts
t = 5 * y // 255
v5 = 100 * t / 255
v6 = 100 * t // 255
v6 = 10 * v6 / 255
IF (v6 >= 5) THEN v5 = v5 + 1
IF (v5 >= 100) THEN
v4 = v4 + 1
v5 = 0
ENDIF
Return


getz: ' Subroutine to read z value
ADCON0 = $59 ' Set A/D to Fosc/8, Channel 3, On
Gosub getad
z = ADRESH

v7 = 5 * z / 255 ' Calculations to convert y value to volts
w = 5 * z // 255
v8 = 100 * w / 255
v9 = 100 * w // 255
v9 = 10 * v9 / 255
IF (v9 >= 5) THEN v8 = v8 + 1
IF (v8 >= 100) THEN
v7 = v7 + 1
v8 = 0
ENDIF
Return



getn: ' Subroutine to read n value
ADCON0 = $51 ' Set A/D to Fosc/8, Channel 2, On
Gosub getad
n = ADRESH

v10 = 5 * n / 255 ' Calculations to convert y value to volts
m = 5 * n // 255
v11 = 100 * m / 255
v12 = 100 * m // 255
v12 = 10 * v12 / 255
IF (v12 >= 5) THEN v11 = v11 + 1
IF (v11 >= 100) THEN
v10 = v10 + 1
v11 = 0
ENDIF
Return

'**********************MAINLOOP******************* ********************


mainloop:
Gosub getx ' Get x value
Gosub gety ' Get y value
Gosub getz ' Get z value
gosub getn ' Get n value

Lcdout $fe, 1, DEC1 v, ".", DEC2 v2, " V1 " 'send to LCD
lcdout $fe, $14, dec1 v4, ".", dec2 v5, " V2" 'send to LCD
lcdout $fe, $c0, dec1 v7, ".", dec2 v8, " V3 " 'send to LCD
lcdout $fe, $14, dec1 v10, ".", dec2 v11, " V4" 'send to LCD
Pause 100 ' Do it about 10 times a second

if x<125 and y>125 and z>125 and n>125 then high PortD.1 '125 = 2.5V
if y<125 and x>125 and z>125 and n>125 then high PortD.0
if z<125 and x>125 and y>125 and n>125 then high PortD.2
if n<125 and x>125 and y>125 and z>125 then high PortD.3

Goto mainloop ' Do it forever

End

Dave
- 8th October 2012, 11:53
You are telling the lcdout command to send only 2 individual digits."DEC1 v, ".", DEC2 v2" I see nowhere that you are sending the full value. Also the variables are sized as bytes. The maximum value you can have is 255.

Sherbrook
- 8th October 2012, 12:18
At a quick glance I would suggest changing
Lcdout $fe, 1, DEC1 v, ".", DEC2 v2 to
Lcdout $fe, 1, DEC2 v, and the same for the 3 following lines

Phil