This page describes a small development tool I have built for the MicroChip pic16f877. I'm always looking for ways to maximize the integration of hardware and software development in my work. This simple interface fits the bill, and I hope there are others out there that will find it useful. Thanks to MicroChip's Mike Garbutt, and their appnote #AN732 for help with the bootload function.

THE HARDWARE



This is all that's needed. The MAX232A takes care of the level translation between the PC's RS232 port and the '877 TX and RX pins. I built this as a dongle for the RS232 cable, and added four long leads (Vdd,Gnd,RX,TX) that clip to the '877. That way, the hardware interface is nearly invisible while I am working on a project.

The resistor and led are for testing, and can be hung on almost any pin. Notice that the RC6, RC7 pins are dedicated only if the usart is enabled, so they are available to user code. It's a good idea to pull the RC7(26) pin up to Vdd with 10K, to prevent noise when the interface is disconnected and the usart is enabled.



THE SOFTWARE

It's all in this file if you'd like to try this at home: monitor.zip (55 k) All this HTML is in there so you can see it offline. Unzip it to its own directory.
Thanks to Jean-Pierre Lessard for monitor3.zip -his revision defaults to 4MHz clock, 9600 baud, and communicates through Ptelnet on a Palm Visor.

These are the critical files:
jmon2.hex -- This is the hex data file that must be programmed to the '877. It resides in program memory @0000-0003 and 1e00-1fff, and once it is there, the chip should never again need its programming mode. (as long as you don't mess up and poke the resident code!)

jmon2.asm -- The source is specific to the '877 running at 20MHz, 19200 baud. This was assembled with MPASM in MPLAB. Do what you will with it, but please let me know if you find improvements that work.

subs.inc -- More source. These are the subroutines, especially those that may be useful to call in user code.

blink.* -- Blink is a little program for testing user code with the monitor. It resides at 0aaa in program memory. Once it's loaded, you can find it using the monitor, and poke at it directly. It needs an led on PORTC,0 to blink.


OPERATING THE MONITOR

Assuming you have a '877 programmed with jmon2.hex, driven with a 20MHz clock, connected to a COM port on a PC with a terminal program running (Hyperterm is fine, and free with the Windows OS):

Set the port parameters at direct to com, 19200 baud, 8-n-1, flow control none, ANSI emulation, ASCII line delay = 30, character delay = 0. If anything gets flaky, you can change these delays, but there is quite a bit to do between lines when writing flash memory, so give the '877 the time it needs. These settings are the first things to check if there is trouble.

The Monitor will wait for a reset to pin 1 of the PIC. When it receives a hard reset, it will wait for about four seconds for a key (any key) from the PC. If it doesn't get one, it will check for user code and begin executing it. If there is no user code in place, it will wait in a loop for another reset. Keep in mind that a hard reset will always result in a four second delay with this chip. I did this to avoid tying up an input pin as a flag. The monitor does not change any memory contents on hard reset. It doesn't change memory unless you load a new program or do a poke command to a specific location. There's not much in the way of error checking. For example, any four keys at an address prompt will be processed. Always be careful what you poke.

Commands: 0 - peek and poke flash memory (anykey scrolls up, 'p' to poke,'esc' to return)
1 - peek and poke RAM registers
2 - peek and poke EEPROM memory
3 - load a program from the terminal (send *.hex as a text file from terminal,* indicates success)
4 - run user code
5 - parse and load hex file lines anywhere
6 - hexdump eeprom data memory
7 - input and jump to a vector anywhere

'esc' key will return to the command line, 'P' will initiate a poke at any memory address you peek.

Now, with your terminal program running, push the reset button and hit a key on the keyboard. If you hit a key in time, you should see the following in your terminal window:

Here's a session exercising all commands 0-7:
-hard reset + key <0>
==================================================

>F$>0000
0000 301E
0001 008A
0002 2E0B
0003 3FFF
0004 3FFF
0005 3FFF P!!=1234
0005 1234
0006 1234
0007 3FFF
==================================================

>D$>00a0
00A0-12
00A1-34
00A2-56
00A3-00 P!!=78
00A3-78
00A4-FF
00A5-00
==================================================

>E$>00
00-12
01-34
02-56
03-FF P!!=78
03-78
04-FF
05-FF
06-FF
==================================================

>U>
>:060000008A150A12AA2A6B*
>:0C155400831203138701831603138730F2*
>:1015600081008701831203130B1DB42A0B11F00BAA*
>:10157000B42A0A30F00001308706B42A00000000C7*
>:02400E00
>:00000001FF

==================================================

>R
==================================================

>!!U>
>:10157000B42A0A30F00001308706B42A00000000C7*
==================================================

>EE
12345678FFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
==================================================

>J0aaa


There are useful subroutines in the monitor that can be called by user code. You may want to include them as equates in your header file if you plan to use the usart in your programs(watch your variables). These subroutines are underutilized in the monitor, because I got so fixed on keeping it within the two-page space. You are probably already noticing that user code could monitor almost anything in the chip from here.

FLASHREAD equ
FLASHWRITE equ
GETDATA equ
GETDIGIT equ
GETHEXBYTE equ
GETHEXWORD equ
OUTNYB equ
SENDBYTE equ
SENDCRLF equ
SERIALSETUP equ
SERRX equ
SERTX equ


mail