In SX Microcontrollers, SX/B Compiler and SX-Key Tool, JonnyMac wrote: If you declare [i]secs01[/i] and [i]secs10[/i] as aliases of [i]secs[/i] then the second line: [code]secs10 = secs >> 4[/code] will always return 0. Unfortunately, the ease-of-use of the BASIC Stamp and its great language features have made many of us lazy and that shows up when we switch to a core processor like the SX. The great thing about SX/B, however, is that it's easy to extend the language via subroutines and functions. I do this: [code]DEC2BCD FUNC 1, 1 BCD2DEC FUNC 1, 1[/code] ... and then code those functions like this (both accept and return one byte): [code]DEC2BCD: tmpB1 = __PARAM1 ' get parameter tmpB2 = tmpB1 / 10 ' isolate 10s SWAP tmpB2 ' move to upper nibble tmpB2 = tmpB2 | __REMAINDER ' add lower nibble RETURN tmpB2 BCD2DEC: tmpB1 = __PARAM1 ' get parameter tmpB2 = tmpB1 >> 4 ' isolate high nibble tmpB2 = tmpB2 * 10 ' convert to decimal tmpB1 = tmpB1 & $0F ' isolate ones tmpB2 = tmpB2 + tmpB1 ' add them RETURN tmpB2[/code] Note on DEC2BCD: You have to be careful about using __REMAINDER; this code works because the SWAP instruction does not modify __PARAM1 (an alias of __REMAINDER) -- you will usually use __REMAINDER immediately after the division. I've tested these routines with values 0..99 and $0..$99 -- they work. ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=180424#m180489 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2007 (http://www.dotNetBB.com)