In SX Microcontrollers, SX/B Compiler and SX-Key Tool, tdodds wrote: Tracy Allen at Berkeley has a great writeup on the subject and code for the Basic Stamp. I ported the divide-by-ten subroutine from his document to my SX28 board and it works perfectly. Below is the SX/B code: DEVICE sx28,oscxt2, turbo,stackx,optionx,BOR26 FREQ 8_000_000 ArrayByte VAR byte (12) send VAR byte TmpB1 VAR Byte temp VAR Byte TmpW1 VAR Word WX VAR Word WY VAR Word RM VAR Byte TX_BYTE SUB 1,2 'transmit byte Bin32DEC SUB 1,4 ''Create ASCII string from double word Start: Bin32DEC 0,0,0,128 'ENTER 32 BIT NUMBER -Param1 (leftmost) is least significant byte For J = 0 to 9 ArrayByte(J) = ArrayByte(J) + 48 Tx_Byte ArrayByte(J) Next Pause 2000 Goto Start TX_BYTE: SEROUT Send, N9600, __PARAM1 ' send the byte return Bin32DEC: WX = __WPARAM34 'Most significant word WY = __WPARAM12 'Least significant word for I = 9 to 0 Step -1 TmpW1 = WX//10 'high remainder temp = TmpW1_LSB WX = WX/10 'high word quotient TmpW1 = WY//10 'remainder calc TMPB1 = TmpW1_LSB RM = temp * 6 RM = RM//10 RM = RM + TmpB1 WY = WY/10 'Low word quotient TmpW1 = RM/10 'WY = (WY/10)+(RM/10)+(temp*6553)+(Temp*6/10) WY = TmpW1 + WY TmpW1 = temp*6553 WY = WY + TmpW1 TmpB1 = Temp*6 TmpB1 = TmpB1/10 WY = WY + TmpB1 RM = RM//10 'final remainder Arraybyte(I) = RM next return ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=453571#m453903 Need assistance? Send an email to the Forum Administrator at sysadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2010 (http://www.dotNetBB.com)