strange variable behavior
Mikael S
Posts: 60
Hello!
im programming a realtime clock. and im using the DS1302 chip.
Everything works fine. But i want to change the time during runtime. I have made a clockset procedure with 3 buttons.
This happends:
The user presses on the button for hours
hr = hr + 1
and then presses the set buton. The program then sends the hr variable to the time set. And it works perfectly until you want to set 16 hrs, then it sets the clock to "10". But it works perfectly up to 15. Same goes for the minutes.
Ive done so it sends the hr variable to debug, and it shows the right numbers, but something screws it up.
What am i doing wrong?
im programming a realtime clock. and im using the DS1302 chip.
Everything works fine. But i want to change the time during runtime. I have made a clockset procedure with 3 buttons.
This happends:
The user presses on the button for hours
hr = hr + 1
and then presses the set buton. The program then sends the hr variable to the time set. And it works perfectly until you want to set 16 hrs, then it sets the clock to "10". But it works perfectly up to 15. Same goes for the minutes.
Ive done so it sends the hr variable to debug, and it shows the right numbers, but something screws it up.
What am i doing wrong?
Comments
When reading values back into the Stamp, you reverse the process. You do have to keep in mind that some of the upper bits of the DS1302 registers have special functions (like set 12/24h mode). Again, read the datasheet for details.
I get the same problem with minutes greater then 30, should i add a specific number for that to?
Like this: ds1302 = ((minutes / 10) * 16) + (minutes // 10)
The same thing works for any decimal to BCD conversion.