Search this site (www.microchipC.com).




 

Debugging with a serial port

Connect your PIC micro to your computer for powerful debugging. The screenshot below illustrates this perfectly.



An in-circuit debugger such as the MPLab-ICD can almost provide the same information. However, a serial link is superior in some ways. It provides a history of program events, unlike a debugger which can only provide the current state of the program. The best tools are a combination of an MPLab-ICD and a serial link.

To receive/transmit keystrokes in the terminal, simply include the following C statements in your program:

setup_serial(); //setup RX and TX for hardware serial
x=getch(); //waits for a character pressed in the terminal, eg: returns 'a' if keystroke 'a' typed

putch('a'); //prints 'a' on the terminal
putch(0x4A); //prints binary 0x4A to the terminal
putst("PICKG v1.01"); //prints strings to the terminal
putchhex(0x4A); //prints an ascii number to the terminal, namely the 2 ascii characters "4A"
putchdec(56789); //prints a decimal number to the terminal, the 5 ascii characters "56789"


If you want a library of C routines for serial communication, the bootloader source code has an example. See bootloader >>

The information on how to build or purchase an RS232 - to - PIC adaptor is contained on the PAS12 adaptor page >