Serial Output Routines
It is nice for debugging purposes to use a general I/O pin for displaying debugging data to a PC, rather than using the USART pin, which may be tied up for other purposes. The routines described here let the used define the port, pin, baud rate, and polarity (true or inverted) of the output.
The following #DEFINE statements are needed in your main() routine:
#define DEBUG_REG
PORTB
The port to use for the serial output
#define DEBUG_BIT 7
The bit to use for serial output
#define
DEBUG_POLARITY TRUE|INVERTED
default is TRUE: direct to RS232
Inverted means via a MAX232 or equivalent
#define DEBUG_TRIS
TRISB
If this is defined, the pin will be set to output in the routine, and then restored to its
original value on exit.
The baud rate is set by either a #DEFINE if you want to use
the pauseus routine, or by a Const statement if you want to use
the delayus routines. The formula is
DEBUG_DELAY = (1000000 / (baud rate)) - (52 / Osc freq
in mHz).
const DEBUG_DELAY =
102
' To use the Basic18 delayus() routine
#define DEBUG_DELAY
102 ' To use the
pauseus()
routine
Click on a routine name to see the code
debugc(character)
send character (a single
byte)
debugs(string)
send the character string in string
debugnl() or
debugCRLF()
send a new line (return
plus line feed)
DumpMem(addr(var),
len,
string)
Puts the contents of RAM,
in hex, formatted as groups of 4 bytes (8 hex characters) into a string. Useful
for debugging.
Parameters:
var - the RAM variable where the dump
will start
len - the length, in bytes, of RAM to dump
string - a string into which the data will be
placed. It must twice as large as len
Example:
dim x as single
dim s(12) as string
DumpMem(addr(x),4,s)