Strange problem adding a variable
Look at this screen shot of PST. I indicated on the picture the 2 different results I get by only adding a long variable to the program. It doesn't matter what I name it but it messes up the result.

I can go from this:
to this:
and not even use the variable "don" in the code and it will make the PST display as I marked it.
Here's the main code I am using. It's just a "playground" of sorts trying to learn some routines so it's a bit messy:
Edit: PUB Clock_Menu is the bit of code that prints to PST.
I have attached an archive of the whole code.
What is wrong?

I can go from this:
VAR long MM_DD_YYYY, DW_HH_MN_SS, YYYY long key byte dig2[2], tch
to this:
VAR long MM_DD_YYYY, DW_HH_MN_SS, YYYY long don, key byte dig2[2], tch
and not even use the variable "don" in the code and it will make the PST display as I marked it.
Here's the main code I am using. It's just a "playground" of sorts trying to learn some routines so it's a bit messy:
Edit: PUB Clock_Menu is the bit of code that prints to PST.
' Serial Test V1_3
' For the 4D display
' Feb 15 2013
CON
_clkmode = xtal1 + pll16x 'Standard clock mode * crystal frequency = 80 MHz
_xinfreq = 5_000_000
MS_001 = 80_000_000 / 1_000
TX = 16 '0 ' Yellow
RX = 17 '1 ' White
RST = 18 '2 ' Green
BAUD = 115_200
TSTPIN = 19
VAR
long MM_DD_YYYY, DW_HH_MN_SS, YYYY
long key
byte dig2[2], tch
OBJ
disp : "4D_SPE_Driver_V0_1_Decn"
term : "FullDuplexSerial"
str : "Simple_Numbers"
clock : "s-35390A_GBSbuild_02_09_2011" ' Seiko RTC driver
PUB Demo | r
disp.Start(RX, TX, RST, BAUD) ' communicate with 4D display
term.start(31, 30, %0000, 115_200) ' start terminal using PST
clock.start
outa[TSTPIN]~~
dira[TSTPIN]~~
pause(500) ' delay for PST
term.str(@ver) ' display version on PST
pause(2500) ' Pause for 4D after powerup
r := \disp.Clear_Scrn ' Clear screen
r := \disp.Text_BG_Color(BLACK) ' Change text BG color to BLACK
r := \disp.Set_Font($0000) ' Set Font
r := \disp.Text_Inverse($0000) ' Text inverse
r := \disp.Text_Width($0002) ' Set font width
r := \disp.Text_X_Gap($0000) ' Pixel gap between characters
r := \disp.Text_FG_Color(WHITE) ' Change text color to WHITE
r := \disp.Text_Bold($0000) ' Text bold command
r := \disp.Put_String(@ver) ' Display text from DAT section
r := \disp.Text_FG_Color(BLUE) ' Change text FG color to BLUE
r := \disp.Text_BG_Color(YELLOW) ' Change text BG color to YELLOW
r := \disp.Text_Width($0001) ' Set font width
r := \disp.Text_X_Gap($0000) ' Pixel gap between characters
r := \disp.Text_Bold($0001) ' Text bold command
r := \disp.Put_String(@text) ' Display text from DAT section
r := \disp.Text_Bold($0000) ' Text bold command
r := \disp.Text_BG_Color(BLACK) ' Change text BG color to BLACK
r := \disp.Set_Font($0000) ' Set Font
r := \disp.Text_Inverse($0000) ' Text inverse
r := \disp.Text_FG_Color(LIME) ' Change text color to LIME
disp.Put_String(clock.FmtDateTime)
r := \disp.Draw_Rect($0064, $0064, $0110, $0100, RED) ' Draw hollow rectangle in RED
r := \disp.Char_Width($41) ' Width in pixels of character "A"
r := \disp.Char_Hght($41) ' Height in pixels of character "A"
r := \disp.Text_BG_Color(BLACK) ' Change text BG color to BLACK
r := \disp.Text_FG_Color(LIME) ' Change text color to LIME
r := \disp.Set_Font($0000) ' Set Font
r := \disp.Text_Width($0000) ' Set font width
r := \disp.Text_X_Gap($0000) ' Pixel gap between characters
r := \disp.Text_Bold($0000) ' Text bold command
r := \disp.Text_Inverse($0000) ' Text inverse
r := \disp.Put_String(@text2) ' Display text from DAT section
Pause(3000)
'disp.Clear_Scrn
'pause(500)
Main_Menu
PUB Main_Menu | x, y
disp.Clear_Scrn
disp.Move_Cursor($0000, $0019)
disp.Text_BG_Color(BLACK)
disp.Text_FG_Color(LIME)
disp.Text_Width($0002)
disp.Text_Height($0002)
disp.Put_String(@menu)
disp.Draw_Rect($000A, $0020, $0096, $006B, RED) ' x1, y1, x2, y2
disp.Draw_Rect($00AA, $0020, $0136, $006B, RED)
disp.Move_Cursor($0004, $000F)
disp.Text_FG_Color(WHITE)
disp.Text_Bold($0000)
disp.Text_Width($0001)
disp.Text_Height($0001)
disp.Put_String(@clkset1)
disp.Draw_Rect($014A, $0020, $01D6, $006B, RED)
disp.Draw_Rect($000A, $0075, $0096, $00BB, RED)
disp.Draw_Rect($00AA, $0075, $0136, $00BB, RED)
disp.Draw_Rect($014A, $0075, $01D6, $00BB, RED)
disp.Draw_Rect($000A, $00CA, $0096, $010B, RED)
disp.Draw_Rect($00AA, $00CA, $0136, $010B, RED)
disp.Draw_Rect($014A, $00CA, $01D6, $010B, RED)
disp.Touch_Region($000A, $0020, $01D6, $010B) ' Sets touch region to only encompass the button area
disp.Touch_Set($0000)
{
repeat
if (disp.Touch_Get($0000) & $FF) == $01 ' Shows x y coordinates in hex
term.str(string("X: "))
term.dec((\disp.Touch_Get($0001) & $FFF))
term.tx($20)
term.hex((\disp.Touch_Get($0001) & $FFF), 3)
term.str(string(" Y: "))
term.dec((\disp.Touch_Get($0002) & $FFF))
term.tx($20)
term.hex((\disp.Touch_Get($0002) & $FFF), 3)
term.tx(13)
pause(20)
}
'info
repeat
if (\disp.Touch_Get($0000) & $FF) == $01 ' Shows x y coordinates in hex
x := \disp.Touch_Get($0001) & $FFF
y := \disp.Touch_Get($0002) & $FFF
case x
$00A..$096:
case y
$020..$06B:
term.str(string("Button 1", 13))
$075..$0BB:
term.str(string("Button 4", 13))
$0CA..$10B:
term.str(string("Button 7", 13))
$0AA..$136:
case y
$020..$06B:
term.str(string("Button 2", 13))
Clock_Menu
$075..$0BB:
term.str(string("Button 5", 13))
$0CA..$10B:
term.str(string("Button 8", 13))
$14A..$1D6:
case y
$020..$06B:
term.str(string("Button 3", 13))
$075..$0BB:
term.str(string("Button 6", 13))
$0CA..$10B:
term.str(string("Button 9", 13))
x := 0
y := 0
pause(50)
PUB Clock_Menu | i, i2, i3, r, x, y, chr, idx, idx2, idx3
r := \disp.Clear_Scrn
disp.Draw_Rect($010A, $001F, $01D6, $010B, RED) ' Outside box
disp.Draw_Line($014E, $001F, $014E, $010B, RED) ' First vertical line
disp.Draw_Line($0192, $001F, $0192, $00D0, RED) ' Second Vertical line
disp.Draw_Line($010A, $005A, $01D6, $005A, RED) ' First horizontal line
disp.Draw_Line($010A, $0095, $01D6, $0095, RED) ' Second horizontal line
disp.Draw_Line($010A, $00D0, $01D6, $00D0, RED) ' Third horizontal line
disp.Text_Bold($0000)
disp.Text_Width($0003)
disp.Text_Height($0003)
x := $02
y := $0E
repeat idx from 1 to 3
disp.Move_Cursor(x, y)
y := y + $03
chr := idx + $30
disp.Put_Char(chr)
x := $05
y := $0E
repeat idx from 4 to 6
disp.Move_Cursor(x, y)
y := y + $03
chr := idx + $30
disp.Put_Char(chr)
x := $07
y := $0E
repeat idx from 7 to 9
disp.Move_Cursor(x, y)
y := y + $03
chr := idx + $30
disp.Put_Char(chr)
disp.Move_Cursor($09, $0E)
disp.Put_Char("0")
disp.Move_Cursor($09, $10)
disp.Put_String(@enter)
disp.Touch_Region($010A, $001F, $01D6, $010B) ' Sets touch region to only encompass the number keypad area
idx := 0
'key1 := 0
MM_DD_YYYY := 0
'DW_HH_MN_SS := 0
'longfill(@MM_DD_YYYY, 0, 1)
longfill(@YYYY, 0, 1)
longfill(@DW_HH_MN_SS, 0, 1)
repeat
Get_Touch2
disp.Text_Width($0001)
disp.Text_Height($0001)
disp.Move_Cursor($0004, $0001)
disp.Put_String(@year)
'if key > $30
if tch == $01
case idx
0..3:
YYYY.byte[idx] := key ' Year 4 bytes - 1 word
repeat i from 0 to 3
disp.Put_Char(byte[@YYYY][i])
MM_DD_YYYY := (MM_DD_YYYY*10) + (Byte[@YYYY][i]-$30)
if idx == 3
disp.Move_Cursor($0005, $0001)
disp.Put_String(@month)
term.dec(idx)
term.tx($20)
term.hex(MM_DD_YYYY, 8)
term.tx($20)
term.hex(YYYY, 8)
term.tx(13)
4..5:
{ MM.byte[idx] := key ' Month 2 bytes
repeat i from 4 to 5
disp.Put_Char(byte[@MM][i])
disp.Move_Cursor($0005, $0001)
disp.Put_String(@month)
MM_DD_YYYY.byte[idx] := key ' Month 2 bytes
repeat i from 4 to 5
disp.Put_Char(byte[@MM][i])
MM_DD_YYYY := (MM_DD_YYYY*10) + (Byte[@MM][i]-$30)
if idx == 5
disp.Move_Cursor($0006, $0001)
disp.Put_String(@date)
term.dec(idx)
term.tx($20)
term.hex(MM_DD_YYYY, 8)
term.tx($20)
term.hex(MM, 4)
term.tx(13)
6..7:
term.dec(idx)
term.tx($20)
term.hex(key, 2)
term.tx(13)
disp.Move_Cursor($0006, $0001)
disp.Put_String(@date)
MM_DD_YYYY.byte[idx] := key ' Date 2 bytes
repeat i from 6 to 7
disp.Put_Char(byte[@MM_DD_YYYY][i])
if idx == 7
disp.Move_Cursor($0008, $0001)
disp.Put_String(@day1)
disp.Move_Cursor($0009, $0001)
disp.Put_String(@day2)
disp.Move_Cursor($000B, $0001)
disp.Put_String(@day3)
8:
term.dec(idx)
term.tx($20)
term.hex(key, 2)
term.tx(13)
'idx2 := idx - 7
disp.Move_Cursor($0008, $0001) ' Day 1 byte
disp.Put_String(@day1)
disp.Move_Cursor($0009, $0001)
disp.Put_String(@day2)
disp.Move_Cursor($000B, $0001)
disp.Put_String(@day3)
DW_HH_MN_SS.byte[idx - 8] := key
disp.Put_Char(byte[@DW_HH_MN_SS][idx - 8])
if idx == 8
disp.Move_Cursor($000C, $0001)
disp.Put_String(@hour)
9..10:
'idx2 := idx - 7
disp.Move_Cursor($000C, $0001)
disp.Put_String(@hour)
DW_HH_MN_SS.byte[idx - 8] := key ' Hour 2 bytes
repeat i2 from 1 to 2
disp.Put_Char(byte[@DW_HH_MN_SS][i2])
if idx == 10
disp.Move_Cursor($000D, $0001)
disp.Put_String(@minute)
11..12:
'idx2 := idx - 7
disp.Move_Cursor($000D, $0001)
disp.Put_String(@minute)
DW_HH_MN_SS.byte[idx - 8] := key ' Minutes 2 bytes
repeat i2 from 3 to 4
disp.Put_Char(byte[@DW_HH_MN_SS][i2])
DW_HH_MN_SS.byte[5] := $30 ' Seconds 2 bytes
DW_HH_MN_SS.byte[6] := $30 }
idx ++
if idx == 13
term.str(string("Date buffer: "))
repeat i from 0 to 7
term.hex(byte[@MM_DD_YYYY][i], 2)
term.tx($20)
term.tx(13)
term.str(string("Time buffer: "))
repeat i3 from 0 to 7
term.hex(byte[@DW_HH_MN_SS][i3], 2)
term.tx($20)
clock.Set24HourMode(1)
clock.SetDateTime(byte[@MM_DD_YYYY][3], { <- Month
} byte[@MM_DD_YYYY][2], { <- Day
} word[@MM_DD_YYYY][0] - 2000, { <- Year
} byte[@DW_HH_MN_SS][3], { <- (day of week)
} byte[@DW_HH_MN_SS][2], { <- Hour
} byte[@DW_HH_MN_SS][1], { <- Minutes
} byte[@DW_HH_MN_SS][0]) { <- Seconds }
disp.Move_Cursor($0002, $0014)
disp.Put_String(clock.FmtDateTime)
pause(1000)
quit
disp.Move_Cursor($0002, $0014)
disp.Put_String(clock.FmtDateTime)
pause(50)
Main_Menu
PUB Get_Touch1(idx) | r
r := \disp.Touch_Get($0000)
r := r & $FF
case r
$00:
'term.str(string("No Touch", 13))
$01:
term.str(string("Touch "))
term.dec(idx)
term.tx(13)
$02:
term.str(string("Release "))
term.dec(idx)
term.tx(13)
$03:
term.str(string("Moving "))
term.dec(idx)
term.tx(13)
'term.hex(r, 2)
'term.tx(13)
PUB Get_Touch2 | x, y
key := 0
if (tch := \disp.Touch_Get($0000) & $FF) == $01 ' If screen is touched
x := \disp.Touch_Get($0001) & $FFF ' Get x, y coordinates
y := \disp.Touch_Get($0002) & $FFF
case x
$10B..$14D:
case y
$020..$059:
key := $31
'term.str(string("1", 13))
$05B..$094:
key := $34
'term.str(string("4", 13))
$096..$0CF:
key := $37
'term.str(string("7", 13))
$0D1..$10A:
key := $30
'term.str(string("0", 13))
$14F..$191:
case y
$020..$059:
key := $32
'term.str(string("2", 13))
$05B..$094:
key := $35
'term.str(string("5", 13))
$096..$0CF:
key := $38
'term.str(string("8", 13))
$0D1..$10B:
key := $45
'term.str(string("Enter", 13))
$193..$1D5:
case y
$020..$059:
key := $33
'term.str(string("3", 13))
$05B..$094:
key := $36
'term.str(string("6", 13))
$096..$0CF:
key := $39
'term.str(string("9", 13))
$0D1..$10B:
key := $45
'term.str(string("Enter", 13))
x := 0
y := 0
pub SetClock | state
Prompt(String("Enter year (2000-2099)"),true)
MM_DD_YYYY.word[0] := getSerVal(4)
Prompt(String("Enter month (01-12)"),true)
MM_DD_YYYY.byte[3] := getSerVal(2)
Prompt(String("Enter date (01-31)"), true)
MM_DD_YYYY.byte[2] := getSerVal(2)
Prompt(String("Enter day of week where 0=SUN 1=MON 2=TUE 3=WED 4=THU 5=FRI 6=SAT"), true)
DW_HH_MN_SS.byte[3] := getSerVal(1)
Prompt(String("Enter hour 0-23 "),true)
DW_HH_MN_SS.byte[2] := getSerVal(2)
Prompt(String("Enter minute (01-59)"),true)
DW_HH_MN_SS.byte[1] := getSerVal(2)
DW_HH_MN_SS.byte[0] := 0 ' Set seconds to 0
Prompt(String("Enter 24 hour mode 0=12Hr 1=24Hr"), true)
state := getSerVal(1)
clock.Set24HourMode(state)
clock.SetDateTime(byte[@MM_DD_YYYY][3], { <- Month
} byte[@MM_DD_YYYY][2], { <- Day
} word[@MM_DD_YYYY][0] - 2000, { <- Year
} byte[@DW_HH_MN_SS][3], { <- (day of week)
} byte[@DW_HH_MN_SS][2], { <- Hour
} byte[@DW_HH_MN_SS][1], { <- Minutes
} byte[@DW_HH_MN_SS][0]) { <- Seconds }
term.tx(13)
term.str(clock.FmtDateTime)
term.tx(13)
pub getSerVal(lim) : value | bytesread, tmp, x, place
term.RxFlush
bytesread := 0
value := 0
place := 1
repeat while bytesread < lim
tmp := term.Rx
if ((tmp == 10) OR (tmp ==13) OR (tmp == "*"))
QUIT
if (tmp => ("0")) and (tmp =< ("9"))
dig2[bytesread] := tmp
bytesread++
repeat x from (bytesread - 1) to 0
value := value + ((dig2[x]-"0") * place)
place := place * 10
pri Prompt(msg, CR)
term.str(msg)
if CR
term.tx(13)
PUB Reset ' Display reset
outa[RST]~
pause(1)
outa[RST]~~
PUB pause(ms) | t
t := cnt
repeat ms
waitcnt(t += MS_001)
pub TestPin
outa[TSTPIN]~
pause(1)
outa[TSTPIN]~~
DAT
ver byte "Serial Test V1_3 for 4D Display",10,10,13,0
text byte "This is just to test the text display capabilities of the 4D 4.3 display. Looking to see how word wrap works.",10,10,13,0
text2 byte "The Text Inverse command sets the text to be inverse, and returns the previous inverse status",10,10,13,0
menu byte "Main Menu", 0
clkset1 byte "Set Clock", 0
clkset2 byte "1 2 3",13,10,10,10
byte "4 5 6",13,10,10,10
byte "7 8 9",13,10,10,10
byte "0 ENTER",0
crlf byte $13, $0A, 0
enter byte " Enter",0
year byte "Enter year (2000-2099): ",0
month byte "Enter month (01-12): ",0
date byte "Enter date (01-31): ",0
day1 byte "0=SUN 1=MON 2=TUE 3=WED",0
day2 byte "4=THU 5=FRI 6=SAT",0
day3 byte "Enter day of week: ",0
hour byte "Enter hour (0-23): ",0
minute byte "Enter minute (01-59): ",0
RED word $F800
GREEN word $0400
LIME word $07E0
WHITE word $FFFF
BLACK word $0000
BLUE word $001F
YELLOW word $FFE0
I have attached an archive of the whole code.
What is wrong?


Comments
MM_DD_YYYY := (MM_DD_YYYY*10) + (Byte[@YYYY]-$30)
be
MM_DD_YYYY := (MM_DD_YYYY*10) + (Byte[@YYYY][idx]-$30)
or
MM_DD_YYYY := (MM_DD_YYYY*10) + (key-$30)
Sometimes we fear the worst when it's ourselves we have to blame!
Thanks for your help!
Don