A PICkit 2 Tip For Program Monitoring

Status
Not open for further replies.

Visitor

Well-Known Member
When developing code, it's often handy to observe variables at certain points, or to see when certain parts of code are executed. One way to gain some insight into program execution is to flash an LED at certain points or if a variable is within a certain range.

If you use a PICkit 2 with the GUI, you have a serial monitor available. You can print out variables and messages about program execution. This can be very valuable during debugging.

Here's a trick that makes the PICkit 2 UART tool even easier to use. If the language you use supports a software UART, you need to know about this trick. The code below is for Swordfish Basic but this trick should be simple in most languages.

The PICkit 2 uses the I/O normally used for ICSP data as its UART input pin. This is RB7 on 28 pin devices. If a software UART is set up with RB7 as the UART output pin, monitoring program execution is as simple as launching the PICkit 2 UART tool after loading code. No need to move any cables.

There is one other switch we must make with the software UART. The UART signal must be inverted, as is usually done with a MAX232 chip.

Code:
Include "suart.bas"


//Software UART setuo
UART.SetBaudrate(sbr9600)  //set the baud rate
UART.SetMode(umTrue)  //invert the signal

UART.SetTX(PORTB.7)    //set the TxD pin to ICSP DAT


//To print the value of a variable

UART.Write("The variable = ", DecToStr(MyVariable), 13, 10)
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…