PDA

View Full Version : SEROUT WORD variable problem



Tobias
- 19th April 2009, 09:35
I am using a 16F877A with a NewHaven serial display

The code is quite lengthy so I will only post relevant parts. My problem is SEROUT'ing a variable that is a WORD so first I set up the variables as this

Stage1OnS data word 100
Stage1OffS data word 110
Stage2OnS data word 200
Stage2OffS data word 220
Stage3OnS data word 300
Stage3OffS data word 330
Stage4OnS data word 400
Stage4OffS data word 440
Stage5OnS data word 500
Stage5OffS data word 550
Stage6OnS data word 600
Stage6OffS data word 660
Stage7OnS data word 700
Stage7OffS data word 770
Stage8OnS data word 800
Stage8OffS data word 880
Stage9OnS data word 900
Stage9OffS data word 990
Stage10OnS data word 1000
Stage10OffS data word 1010

then in a section of the code I SEROUT some of the above mentioned variables

Serout LCD,T9600,[Prefix,$45,LcdLine2, "10 ", #PreOn," ", #PreOff, Prefix,$45,LcdLine3,"1 ", #CurOn, " " , #CurOff, " ON", Prefix,$45,LcdLine4, "2 ", #NxtOn, " ", #NxtOff]

The CurOn, CurOff, NxtOn, and NxtOff variables show up on the LCD correctly.

The PreOn and PreOff do not. I am sure this is because the variables exceed 255. I have tried taking Low and High byte of PreOn and Preoff into another variable like variable=PreOn.LowByte+PreOn.HighByte yet the code does not complile.

What am I missing to get a full DATA WORD to display on my LCD?
Thanks in advance.
Toby

Tobias
- 19th April 2009, 09:40
Here is all the code


DEFINE OSC 20

Start var PortB.0 'Input to start timers
Up1 var PortB.1 'Up button to change seconds
Down1 var PortB.2 'Down button to change seconds.
Up01 var PortB.3 'Up button to change tenths of second.
Down01 var PortB.4 'Down button to change tenths of second.
Up001 var PortB.5 'Up button to change hundredths of a second
Down001 var PortB.6 'Down button to change hundredths of a second
Tool var PortB.7 'Button to change to diffent menu
UpStage var PortA.0 'Button to change stages
DownStage var PortA.1 'Button to change stages
LCD VAR PortC.0 'LCD output

StageCounter var byte
Stage1OnS data word 100
Stage1OffS data word 110
Stage2OnS data word 200
Stage2OffS data word 220
Stage3OnS data word 300
Stage3OffS data word 330
Stage4OnS data word 400
Stage4OffS data word 440
Stage5OnS data word 500
Stage5OffS data word 550
Stage6OnS data word 600
Stage6OffS data word 660
Stage7OnS data word 700
Stage7OffS data word 770
Stage8OnS data word 800
Stage8OffS data word 880
Stage9OnS data word 900
Stage9OffS data word 990
Stage10OnS data word 1000
Stage10OffS data word 1010

test var word

Stage1On VAR word
Stage1Off VAR word
Stage2On VAR word
Stage2Off VAR word
Stage3On VAR word
Stage3Off VAR word
Stage4On VAR word
Stage4Off VAR word
Stage5On VAR word
Stage5Off VAR word
Stage6On VAR word
Stage6Off VAR word
Stage7On VAR word
Stage7Off VAR word
Stage8On VAR word
Stage8Off VAR word
Stage9On VAR word
Stage9Off VAR word
Stage10On VAR word
Stage10Off VAR word
Checker var byte
CurStage var Byte
PreOn var Byte
PreOff var byte
CurOn Var byte
CurOff var byte
NxtOff var Byte
NxtOn var byte
SubStage var byte
BL var byte

Prefix con $FE ' needed before each command
LcdCls CON $51 ' clear LCD (use PAUSE 5 after)
LcdLine1 CON $00 ' move cursor to line 1
LcdLine2 con $40 ' move curson to line 2
LcdLine3 con $14 ' move curson to line 3
lcdLine4 con $54 ' move curson to line 4
LcdCol1 con $00 ' move cursor to column 1
LcdCR CON $0D ' move pos 0 of next line
LcdOn CON $41 ' LCD on; cursor off, blink off
LcdHome con $46
Backlight con $53 ' Backlighting 1-8
Contrast con $52 ' Contrast 1-50
CursorPS con $45 'Cursor Position
CursorOn con $47 'Cursof On
CursonOff con $48 'Cursor Off

OPTION_REG.7 = 0 'Pull Ups enabled
INTCON.7=0
ADCON0.0 =0

StageCounter = 1

Include "Elapsed.bas"
Include "modedefs.bas" ' Mode definitions for Serout
gosub ClearScreen
'---------Display Start-Up Info-------
Serout LCD, T9600, [Prefix,LcdHome,"xBase Computing",Prefix,CursorPS,LcdLine2,"Timer"]
pause 2000
gosub ClearScreen

Pause 2000

gosub Read_Data

'------------Sets up backlighting--------------
Repeat
iF Tool = 0 and UpStage = 0 tHEN
BL = 8
endif

iF Tool = 0 and DownStage = 0 tHEN
BL = 8
endif

Gosub Change_Stage

Gosub Change_Time
until Start = 0
'Repeat 'Transbrake button pushed
' HDSRPM = 0
' LDSRPM = 0
' DSRPMCounter = 0
'Until Start = 1

Gosub StartTimer
Gosub ClearScreen
Serout LCD,T9600,["On"]

gosub StopTimer



Change_Stage:
If UpStage = 0 then
if StageCounter < 10 then
StageCounter = StageCounter +1
endif
endif

If DownStage = 0 then
if StageCounter >1 then
StageCounter = StageCounter -1
endif
endif

Gosub Set_Display
return

Change_Time:
If Up1 = 0 then
Stage1on= Stage1On + 1
endif
return

Set_Display:
Select Case StageCounter
Case 1
CurStage = 1
PreOn = Stage10On
PreOff =Stage10Off
CurOn = Stage1On
CurOff = Stage1Off
NxtOn = Stage2On
NxtOff = Stage2Off
Gosub Display_Stage
Case 2
CurStage = 2
PreOn = Stage1On
PreOff =Stage1Off
CurOn = Stage2On
CurOff = Stage2Off
NxtOn = Stage3On
NxtOff = Stage3Off
Gosub Display_Stage
Case 3
CurStage = 3
PreOn = Stage2On
PreOff =Stage2Off
CurOn = Stage3On
CurOff = Stage3Off
NxtOn = Stage4On
NxtOff = Stage4Off
Gosub Display_Stage
Case 4
CurStage = 4
PreOn = Stage4On
PreOff =Stage4Off
CurOn = Stage5On
CurOff = Stage5Off
NxtOn = Stage6On
NxtOff = Stage6Off
Gosub Display_Stage
Case 5
CurStage = 5
PreOn = Stage4On
PreOff =Stage4Off
CurOn = Stage5On
CurOff = Stage5Off
NxtOn = Stage6On
NxtOff = Stage6Off
Gosub Display_Stage
Case 6
CurStage = 6
PreOn = Stage5On
PreOff =Stage5Off
CurOn = Stage6On
CurOff = Stage6Off
NxtOn = Stage7On
NxtOff = Stage7Off
Gosub Display_Stage
Case 7
CurStage = 7
PreOn = Stage6On
PreOff =Stage6Off
CurOn = Stage7On
CurOff = Stage7Off
NxtOn = Stage8On
NxtOff = Stage8Off
Gosub Display_Stage
Case 8
CurStage = 8
PreOn = Stage7On
PreOff =Stage7Off
CurOn = Stage8On
CurOff = Stage8Off
NxtOn = Stage9On
NxtOff = Stage9Off
Gosub Display_Stage
Case 9
CurStage = 9
PreOn = Stage8On
PreOff =Stage8Off
CurOn = Stage9On
CurOff = Stage9Off
NxtOn = Stage10On
NxtOff = Stage10Off
Gosub Display_Stage
Case 10
CurStage = 10
PreOn = Stage9On
PreOff =Stage9Off
CurOn = Stage10On
CurOff = Stage10Off
NxtOn = Stage1On
NxtOff = Stage1Off
Gosub Display_Stage
end select

Display_Stage:
Select Case StageCounter
Case 1

gosub FirstLine
Serout LCD,T9600,[Prefix,$45,LcdLine2, "10 ", #test," ", #PreOff, Prefix,$45,LcdLine3,"1 ", #CurOn, " " , #CurOff, " ON", Prefix,$45,LcdLine4, "2 ", #NxtOn, " ", #NxtOff]
pause 5000
Case 2
gosub FirstLine
Serout LCD,T9600,[Prefix,LcdLine2, "10", #PreOn," ", #PreOff, Prefix,LcdLine3, "1 ", #CurOn, " " , #CurOff, "OFF",Prefix,LcdLine4, "2 ", #NxtOn, " ", #NxtOff]
end select
return

ClearScreen:
Serout LCD, T9600, [Prefix,LcdCLS]
pause 5
Return

SetBackLight:
Serout LCD, T9600, [Prefix,Backlight,BL]
pause 5
Return

FirstLine:
Serout LCD, T9600, [Prefix,LcdHome,"Stage On Off"]
return

Read_Data:
Read 0, Stage1On.LowByte
REad 1, Stage1On.HighByte
Read 2, Stage1Off.LowByte
REad 3, Stage1Off.HighByte

Read 4, Stage2On.LowByte
REad 5, Stage2On.HighByte
Read 6, Stage2Off.LowByte
REad 7, Stage2Off.HighByte

Read 8, Stage3On.LowByte
REad 9, Stage3On.HighByte
Read 10, Stage3Off.LowByte
REad 11, Stage3Off.HighByte

Read 12, Stage4On.LowByte
REad 13, Stage4On.HighByte
Read 14, Stage4Off.LowByte
REad 15, Stage4Off.HighByte

Read 16, Stage5On.LowByte
REad 17, Stage5On.HighByte
Read 18, Stage5Off.LowByte
REad 19, Stage5Off.HighByte

Read 20, Stage6On.LowByte
REad 21, Stage6On.HighByte
Read 22, Stage6Off.LowByte
REad 23, Stage6Off.HighByte

Read 24, Stage7On.LowByte
REad 25, Stage7On.HighByte
Read 26, Stage7Off.LowByte
REad 27, Stage7Off.HighByte

Read 28, Stage8On.LowByte
REad 29, Stage8On.HighByte
Read 30, Stage8Off.LowByte
REad 31, Stage8Off.HighByte

Read 32, Stage9On.LowByte
REad 33, Stage9On.HighByte
Read 34, Stage9Off.LowByte
REad 35, Stage9Off.HighByte

Read 36, Stage10On.LowByte
REad 37, Stage10On.HighByte
Read 38, Stage10Off.LowByte
REad 39, Stage10Off.HighByte
return

Tobias
- 19th April 2009, 10:04
after drinking heavily I think I am getting this sorted out. I tried this part of code

read 38, Test.LowByte
read 39, Test.highbyte

and then used 'test' as a variable to SEROUT. If there is a better way to do this let me know
Thanks again
Toby

rsocor01
- 19th April 2009, 11:20
Tobias,

Try reading one variable at a time and see what's the value. Anyways I can see that you have in your program
PreOn = Stage10On
PreOff =Stage10Off
but you defined Stagexxxxx as word but defined PreOn and PreOff as bytes. This might be a problem if the Stagexxxxx variables go above 255. I would define PreOn and PreOff as words and see what happens.

Robert