Just for the record, the examples I posted are valid, tried and tested...
Not knowing how you are manipulating your code and Buttons behind the scenes doesn't help... but, if your Seconds Button for example incremented the Seconds every time you pressed or held it...
That will give you a variable 'Seconds' which will contain a (Decimal) value in the range 0-59.Code:While SecondsButton=0 Seconds=Seconds+1 If Seconds>59 then Seconds=0 Pause 250 Wend
Running it through either if the routines I posted previously you get...
DecimalByte Decimal (HEX) = BCDByte Decimal (HEX)
0-9 ($00-$09) = 0-9 ($00-$09)
10-19 ($0A-$13) = 16-25 ($10-$19)
20-29 ($14-$1D) = 32-41 ($20-$29)
30-39 ($1E-$27) = 48-57 ($30-$39)
40-49 ($28-$31) = 64-73 ($40-$49)
50-59 ($32-$3B) = 80-89 ($50-$59)
...which then can be used for the Seconds Register for the timer chip.
Now those routines are only valid for the range 0-99 giving a BCD of $00-$99, which is fine if you are setting clocks as you're only interested in 0-59 worst-case anyway.
The way you've implimented things seems kinda hard work, if individually you are incrementing units seperately from the tens.
Of course it didn't... that routine pulls the units and tens digits out a DECIMAL number to construct (encode) the BCD - not to decode the BCD... you weren't asking for that in your original post! To construct DECIMAL from BCD, you can do something simple like...Melanie, I still couldn't that snippet of code you supplied to work right. Using Dig 0 and Dig 1 to pick the 1's and 10's digits out of the BCD didn't give the desired results...
Code:DecimalByte=(BCDByte>>4)*10+(BCDByte & $0F)








Bookmarks