Sertxd Hex Formatter

erco

Senior Member
Is there a format character to display the hexadecimal value of a variable using the sertxd command?
 

inglewoodpete

Senior Member
Not as such. I include the following subroutine to display nibbles or bytes (with or without a leading $-sign) for debugging when required:

Rich (BB code):
'
' ----- ShowHex: Send Hexadecimal value to PE Terminal -----------------------------------------
'
'        Send a  byte  as hex to terminal on the programming lead
'        Send a nibble as hex to terminal on the programming lead
'        Alternate "D" entries cause a leading $ sign to be sent
'
'        Entry:   ShowByte    (byte) data to be transmitted
'        Exit:    ShowByte    (byte) unchanged
'        Used:    Temp        (byte)
'
Symbol mskLoNibble = %00001111 'Define nibble mask
'
ShowHexD:SerTxd("$")           'Alternate entry
ShowHex: bTemp = ShowByte >> 4 'Get high nibble
         GoSub SHexNib2        'Show it
         GoTo SHexNibl
ShowNibD:SerTxd("$")           'Alternate entry
SHexNibl:bTemp = ShowByte And mskLoNibble
SHexNib2:bTemp = bTemp + "0"   'Convert to ASCII
         If bTemp > "9" Then   'Separate out and
            bTemp = bTemp + 7  ' correct over-
         EndIf                 ' decimal part.
         SerTxd(bTemp)         'Display it
         Return
Edit (1) Reformatted for new forum software
Edit (2) Oops: too much of a hurry. I see that Buzby did that below!
 
Last edited:

erco

Senior Member
Thanks iwp, that's very helpful. iButtons have their engraved serial number in hex, which is baffling my students.

@Rev Ed: a future PE version might benefit from a built-in hex convert or display function,
 

lbenson

Senior Member
>a future PE version might benefit from a built-in hex convert or display function

I'd second that--with serial out, "$" prefix to signify hex (as # prefix signifies numeric), and % to signify binary.
 

Technical

Technical Support
Staff member
For the ibutton case you could simply use 'debug' instead of 'sertxd' and display the code explorer debug data in hex.
 

Buzby

Senior Member
Tidy now !

Rich (BB code):
'
' ----- ShowHex: Send Hexadecimal value to PE Terminal -----------------------------------------
'
'        Send a  byte  as hex to terminal on the programming lead
'        Send a nibble as hex to terminal on the programming lead
'        Alternate "D" entries cause a leading $ sign to be sent
'
'        Entry:   ShowByte    (byte) data to be transmitted
'        Exit:    ShowByte    (byte) unchanged
'        Used:    Temp        (byte)
'
Symbol mskLoNibble = %00001111 'Define nibble mask
'
ShowHexD:SerTxd("$")           'Alternate entry
ShowHex: bTemp = ShowByte >> 4 'Get high nibble
         GoSub SHexNib2        'Show it
         GoTo SHexNibl
ShowNibD:SerTxd("$")           'Alternate entry
SHexNibl:bTemp = ShowByte And mskLoNibble
SHexNib2:bTemp = bTemp + "0"   'Convert to ASCII
         If bTemp > "9" Then   'Separate out and
            bTemp = bTemp + 7  ' correct over-
         EndIf                 ' decimal part.
         SerTxd(bTemp)         'Display it
         Return
 
Top