• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

A PICkit 2 Tip For Program Monitoring

Visitor

Active 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)
 

Latest threads

EE World Online Articles

Loading

 
Top