Code to help with debugging SX/B programs...
RobotWorkshop
Posts: 2,307
Hello,
I was working on one of my projects using SX/B and wanted an easy way to send
debugging data to a PC to help see what was going on in my code. I used the built
in RS-232 port on the SX48 DIP module kit to send data to the host PC. Sending a
specific character is easy and has been shown quite a few times on this forum. I
wanted a quick way to send the Hexidecimal representation of each byte to the
Serial Port (followed by a space) and came up with the following code as another
subroutine. It only has one byte passed to it and converts the value to be sent
to the serial port for debugging.
Just define BaudDbg as a constant like "T9600" and define DbgSer as the pin
you want to use to send the debug data one. Also make sure to define the pin
as an output!
TX_ByteDbg SUB 1 ' Transmit character to debug port
TX_ByteDbgHex SUB 1 ' Transmit Hex value to debug port
.
.
.
'
' Use: TX_ByteDbg char
' -- 'Transmits 'char' over serial connection
TX_ByteDbg:
tmpB1 = __PARAM1 ' get the passed byte value
SEROUT DbgSer, BaudDbg, tmpB1 ' Send the byte
RETURN
TX_ByteDbgHex:
tmpB1 = __PARAM1 ' get the passed byte value
tmpB2 = tmpB1 // 16 ' Get the low nybble digit (0-15)
tmpB1 = tmpB1 / 16 ' Get the high nybble digit (0-15)
tmpB1 = tmpB1 +$30
IF tmpB1 > $39 THEN
tmpB1 = tmpB1 + 7
ENDIF
tmpB2 = tmpB2 +$30
IF tmpB2 > $39 THEN
tmpB2 = tmpB2 + 7
ENDIF
SEROUT DbgSer, BaudDbg, tmpB1 ' Send the upper nybble
SEROUT DbgSer, BaudDbg, tmpB2 ' Send the lower nybble
SEROUT DbgSer, BaudDbg, 32 ' Send a trailing space
RETURN
I just wrote this code today as I needed something quick to help me debug a problem
(which it did). I suppose it could be optimized a bit but perhaps some of you will find
it useful.
Best Regards,
Robert
I was working on one of my projects using SX/B and wanted an easy way to send
debugging data to a PC to help see what was going on in my code. I used the built
in RS-232 port on the SX48 DIP module kit to send data to the host PC. Sending a
specific character is easy and has been shown quite a few times on this forum. I
wanted a quick way to send the Hexidecimal representation of each byte to the
Serial Port (followed by a space) and came up with the following code as another
subroutine. It only has one byte passed to it and converts the value to be sent
to the serial port for debugging.
Just define BaudDbg as a constant like "T9600" and define DbgSer as the pin
you want to use to send the debug data one. Also make sure to define the pin
as an output!
TX_ByteDbg SUB 1 ' Transmit character to debug port
TX_ByteDbgHex SUB 1 ' Transmit Hex value to debug port
.
.
.
'
' Use: TX_ByteDbg char
' -- 'Transmits 'char' over serial connection
TX_ByteDbg:
tmpB1 = __PARAM1 ' get the passed byte value
SEROUT DbgSer, BaudDbg, tmpB1 ' Send the byte
RETURN
TX_ByteDbgHex:
tmpB1 = __PARAM1 ' get the passed byte value
tmpB2 = tmpB1 // 16 ' Get the low nybble digit (0-15)
tmpB1 = tmpB1 / 16 ' Get the high nybble digit (0-15)
tmpB1 = tmpB1 +$30
IF tmpB1 > $39 THEN
tmpB1 = tmpB1 + 7
ENDIF
tmpB2 = tmpB2 +$30
IF tmpB2 > $39 THEN
tmpB2 = tmpB2 + 7
ENDIF
SEROUT DbgSer, BaudDbg, tmpB1 ' Send the upper nybble
SEROUT DbgSer, BaudDbg, tmpB2 ' Send the lower nybble
SEROUT DbgSer, BaudDbg, 32 ' Send a trailing space
RETURN
I just wrote this code today as I needed something quick to help me debug a problem
(which it did). I suppose it could be optimized a bit but perhaps some of you will find
it useful.
Best Regards,
Robert
Comments
Thanks for posting your debugging subroutine.
I noticed that you define TX_ByteDbg but never seem to call it. I assume you meant to use it to save program space and probably meant to replace your three SEROUT calls with something like the following:
This should not affect how the subroutines work, just home much program space they consume.
- Sparks
You are definitely right and I should just call TX_BtyeDbg from within the Hex routine to save space. I hadn't put that in place yet but will as I clean up the program i'm using it in.
What wasn't shown is that I had called the TX_ByteDbg from a few other places whenever I wanted to send out status. One routine prints stored text strings (to make it look pretty) and other times I just send the ASCII code of the character I wanted to use for status. When I needed to display Hex bytes I then call the TX_ByteDbgHex routine above. I posted that portion since I hoped others would find the conversion to Hex useful.
Robert