Sending a 32 bit value out a serial port
pogertt
Posts: 33
I have an application that requires a value greater than 65535 to be output in a serial string.
46 ** 4000· =· 184000· or··· h2······ hCECO
If the upper word is 0, the result is less than 65536
if it is 1, then make HU =6553 and save the left over 6 for later.
If it is 2, then make HU =(65536 *2 = 131072) \ 10 for 13107 and save the 2 for later.
hCECO =52928· then / by 10 for 5292 and save the 8.
13107 + 5292 =18399
The left over 2 +8 =10 so if this is over 9, add one to 18399 for 18400, then subtract 10 from the 2+8 variable.
output the variable representing the 18400, followed by the variable representing the saved remainders, and you have now sent a 32 bit value out the serial port using a controler that likes 16 bit numbers.
Pogertt
46 ** 4000· =· 184000· or··· h2······ hCECO
If the upper word is 0, the result is less than 65536
if it is 1, then make HU =6553 and save the left over 6 for later.
If it is 2, then make HU =(65536 *2 = 131072) \ 10 for 13107 and save the 2 for later.
hCECO =52928· then / by 10 for 5292 and save the 8.
13107 + 5292 =18399
The left over 2 +8 =10 so if this is over 9, add one to 18399 for 18400, then subtract 10 from the 2+8 variable.
output the variable representing the 18400, followed by the variable representing the saved remainders, and you have now sent a 32 bit value out the serial port using a controler that likes 16 bit numbers.
Pogertt

Comments
I hope this helps.· Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering
' {$STAMP BS2pe} ' {$PBASIC 2.5} ' demo shows conversion of 32 bit binary double precision variable to decimal display ' Tracy Allen, www.emesystems.com ' Enter 8 hex digits at the keyboard, including leading zeros if necessary. z1 VAR WORD ' two words form double prec (32 bit) variable z1:z0 z0 VAR WORD rm1 VAR NIB ' remainders, for calculation rm0 VAR BYTE flag VAR BIT ' for leading zero suression nub VAR NIB(10) ' this array stores 10 possible digis idx VAR NIB ' index DO DEBUG CR, "Please enter 8 hex digits (e.g. 0FDB9753): " DEBUGIN HEX4 z1, HEX4 z0 DEBUG CR, "Decimal value = " GOSUB showDubDec10zBS2 LOOP showDubDec10zBS2: ' enter here with z1:z0 FOR idx=0 TO 9 ' 10 bytes hold 10 digits, peal off remainders of each divide by 10 rm1=z1 // 10 ' high remainder z1=z1 / 10 ' high word of quotient rm0=((rm1*6//10) + (z0//10)) ' remainder calc, value from 0 to 18 z0=(rm1*6553) + (rm1*6/10) + (z0/10) + (rm0/10) 'low word of quotient rm0=rm0 // 10 ' final remainder nub(idx)=rm0 ' store up digits from lsd to msd NEXT ' idx next digit ' -- printout routine, digits stored in nib array flag=0 ' flag allows leading zero suppression in display FOR idx=9 TO 0 ' print digits, most significant first, suppress leading zeros rm0 = nub(idx) ' from memory msd first IF rm0>0 OR idx=0 THEN flag=1 IF flag THEN DEBUG DEC1 rm0 ' print the ascii code, suppress leading zeros NEXT RETURN▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
I have been using your·math·routines for calculating DDS values (32 bits +) .
Many thanks·for such wondeful tools.
But being lazy and so far not fully understnding the "magic" , do you have a sample·code for decimal to hex conversion - I need more that 5 digits decimal precision.
Thanks in advance.
I better look at the code you just published and see if I can modify it for hex.
Sorry