The debug statement in picBasic Pro is a limited version of asynchronous serial communication. You have to define the debug port and pin, the baud rate, and the mode at the top of your program, and you can’t change any of these settings within the progam. Once that’s done, though, sending messages to the PC is a snap. Connect the whatever pin you use on te PIC to debug to the serial input of a PC (pin 2 on a DB-9 serial connector), and connect pin 5 of the DB-9 connector to ground. Then open HyperTerminal, set the baud rate to 9600, and run this program.
Here’s a photo of the connections:
And here’s the schematic for the DB-9 connector (note: the above diagram does not include the 22Kohm resistor shown in this schematic):
Note the different modes you can use to display a variable. To see the ASCII value, just print the variable itself. For decimal, use DEC; hexadecimal, use HEX; for a binary representation, use BIN. This example shows the same value in all of these.
' debug example for picBasic Pro ' open the file with the definitions that we need: INCLUDE "modedefs.bas" ' Set Debug pin port DEFINE DEBUG_REG PORTC ' Set Debug pin BIT (RC6 in this case) DEFINE DEBUG_BIT 6 ' Set Debug baud rate DEFINE DEBUG_BAUD 9600 ' Set Debug mode: 0 = true, 1 = inverted DEFINE DEBUG_MODE 1 ' set up constant value for linefeed (ASCII value 10) lf CON 10 ' set up constant value for carriage return (ASCII value 13) cr CON 13 myVar VAR BYTE main: For myVar = 0 to 255 ' print the variable as a decimal: Debug "myVar as a decimal: ", DEC myVar ' print it as a binary number: Debug " as binary: ", BIN myVar ' print it as a hexadecimal number: Debug " as hex: ", HEX myVar ' print the ascii value (and end the line): Debug " as ascii: ", myVar, lf, cr Next GoTo main