Humlan
08-11-2005, 07:13 PM
I need to convert a hexadecimal number to a decimal number, but can't figure out how to go about it.
I get seconds, minutes and hours from a DS1302 RTC chip via SHIFTIN, but the values are in hex, so I need to convert them to decimal in order to do decimal calculations with the numbers.
I've looked in all the help files, manuals and other PDFs I could find. Even a forum search for "convert hex" turns up dry.
Is this such a basic question that I'm the only one who is stumped by it? http://forums.parallax.com/images/smilies/confused.gif
I want to calculate the number of seconds since the RTC was reset. It's for an intervalometer with display, to be used with my Canon 350D camera for time-lapse photography.
HIGH CS1302
SHIFTOUT DataIO, Clock, LSBFIRST, [RdBurst]
SHIFTIN DataIO, Clock, LSBPRE, [bytRTCSecs, bytRTCMins, bytRTCHrs]
' Here I'd like to convert the hex values from the RTC chip to decimal, so the following code would work
wrdRTCSecs = (bytRTCSecs + (bytRTCMins * 60) + (bytRTCHrs * 3600))
LOW CS1302
wrdGoalSecs = 3240 ' Just an example decimal figure
wrdSecsToDisplay = wrdGoalSecs - wrdRTCSecs ' The number of seconds to be displayed
' Display the counter on the LCD
SEROUT pnLCD, conLCD, [conLCDTopHrs, DEC2 (wrdSecsToDisplay / 3600), conLCDTopMins, DEC2 ((wrdSecsToDisplay // 3600) / 60), conLCDTopSecs, DEC2 ((wrdSecsToDisplay // 3600) // 60) ]
Thanks in advance!
/Jonas
I get seconds, minutes and hours from a DS1302 RTC chip via SHIFTIN, but the values are in hex, so I need to convert them to decimal in order to do decimal calculations with the numbers.
I've looked in all the help files, manuals and other PDFs I could find. Even a forum search for "convert hex" turns up dry.
Is this such a basic question that I'm the only one who is stumped by it? http://forums.parallax.com/images/smilies/confused.gif
I want to calculate the number of seconds since the RTC was reset. It's for an intervalometer with display, to be used with my Canon 350D camera for time-lapse photography.
HIGH CS1302
SHIFTOUT DataIO, Clock, LSBFIRST, [RdBurst]
SHIFTIN DataIO, Clock, LSBPRE, [bytRTCSecs, bytRTCMins, bytRTCHrs]
' Here I'd like to convert the hex values from the RTC chip to decimal, so the following code would work
wrdRTCSecs = (bytRTCSecs + (bytRTCMins * 60) + (bytRTCHrs * 3600))
LOW CS1302
wrdGoalSecs = 3240 ' Just an example decimal figure
wrdSecsToDisplay = wrdGoalSecs - wrdRTCSecs ' The number of seconds to be displayed
' Display the counter on the LCD
SEROUT pnLCD, conLCD, [conLCDTopHrs, DEC2 (wrdSecsToDisplay / 3600), conLCDTopMins, DEC2 ((wrdSecsToDisplay // 3600) / 60), conLCDTopSecs, DEC2 ((wrdSecsToDisplay // 3600) // 60) ]
Thanks in advance!
/Jonas