Question on SXB integers (going below 0 is what?)
I am trying to modify the SXB Example code for the Clock / Timer. This counts up and I want it to count down to tell me how many days and hours or so till Christmas. I have adapted it for the Sure Electronics 0832 display. In the attached code, you will see in the interupt for 'secs' that checks this byte variable for any number below or lower than zero (0). The attached code and Youtube video is currently set up now to skip 0 and just go back to 59.
If I change it to check for a number lower than 0, then the ascii that is displayed is strange like: I5, then counts down to H5, etc.. Where is this comming from. Are numbers less then 0 negative or does it equal 128 or something?
http://www.youtube.com/watch?v=qfYYjz1V1lg
Update_Timer:
INC ms ' update ms counter
IF ms = 1000 THEN ' check for 1 second
ms = 0
DEC secs
IF secs = 0 THEN ' check for new minute
[b]'IF secs < 0 THEN ' This is what it should be but get strange display chars[/b]
secs = 59
DEC mins
IF mins = 0 THEN ' check for new hour
mins = 59
DEC hrs
IF hrs = 0 THEN ' check for new day
hrs = 23
DEC days
IF days = 0 THEN
days = 99
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
If I change it to check for a number lower than 0, then the ascii that is displayed is strange like: I5, then counts down to H5, etc.. Where is this comming from. Are numbers less then 0 negative or does it equal 128 or something?
http://www.youtube.com/watch?v=qfYYjz1V1lg


Comments
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Does that byte of memory hold "A", 65, $41 or %01000001 ?
Yes it does...
·
secs = 15
times(3) = secs / 10··' times(3) = 15 / 10 = 1 (rounded)
times(3) = times(3) + $30·' times(3) = $31 or "1"
times(4) = __REMAINDER··' times(4) = 5
times(4) = times(4) + $30·' times(4) = $35 or "5"
secs = 255
times(3) = secs / 10··' times(3) = 255 / 10 = 25 (rounded)
times(3) = times(3) + $30·' times(3) = $49 or "I"
times(4) = __REMAINDER··' times(4) = 5
times(4) = times(4) + $30·' times(4) = $35 or "5"
This solves the problem of that code running before time values have been initialized. This method does the same thing, though may be considered less elegant:
This fixes the wrap-under from what a byte does to what you want it to do as a time register.
Post Edited (JonnyMac) : 11/2/2009 5:55:31 PM GMT
I'll try it out tonight.