DS1302 Object Output
GCX
Posts: 3
Hello guys, I'm totally newbie with the spin programming and so the question might be really dumb but anyways...
For the newest project I need to compare the current time (hour particularly) with certain decimal values like "if hour > 12" but, as I understand, the "readTime" method in the DS1302 object from OBEX returns binary values. So, how should I convert them to decimal? The second question is: I've compared the "config" method settings with the ds1302 datasheet and seems that it's set to 24-hour scheme (which I actually need), is that correct?
Thanks very much.
For the newest project I need to compare the current time (hour particularly) with certain decimal values like "if hour > 12" but, as I understand, the "readTime" method in the DS1302 object from OBEX returns binary values. So, how should I convert them to decimal? The second question is: I've compared the "config" method settings with the ds1302 datasheet and seems that it's set to 24-hour scheme (which I actually need), is that correct?
Thanks very much.
Comments
A value stored in a memory location is not inherently stored as Decimal or Hex, it is always stored as a binary number. When we display it in decimal we are choosing to format the output to view the value in that manner, same as Hex. So if the hour is 12 it won’t matter whether it is in Binary or Decimal format…the variable will contain the value 12. Now if it was a formatted value then the format would make a difference, but this would only be possible if the value was BCD or string. I would try displaying the returned value as if it were decimal.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
if heure > 10
outa[noparse][[/noparse]0]~~
wouldn't work. So is there a way to bring those values to decimal format?
Forest, did you also had to evaluate the current time in decimal presentation?
Do you have any way to hook up an output device (a VGA, TV, or serial LCD)? If so, hook it up and print the values in hexadecimal. If they look like this: $0, $1, $2, ...$9, $a, $b, $c then the output is unformated, normal, numbers. If they are $0, $1, ... $9, $10, $11, $12 then you are in binary-coded-decimal.
One other thing to check for - the 1302 can run in either 12 or 24 hour mode. Make sure that you are running the chip in the mode you thought you were....
decimalVal := ( bcdVal / 16 * 10 ) + ( bcdVal & $F )
Hippy, I've already tried that one and it didn't work, which is really strange.
decimalVal := ( ( bcdVal & $7 ) / 16 * 10 ) + ( bcdVal & $F ) ' For 0..59 BCD
decimalVal := ( ( bcdVal & $3 ) / 16 * 10 ) + ( bcdVal & $F ) ' For 0..23 BCD
decimalVal := ( ( bcdVal & $1 ) / 16 * 10 ) + ( bcdVal & $F ) ' For 0..12 BCD
Have you checked what the raw binary data values are which come back ? If it's I2C but not being correctly addressed all data can end up as $FF.