Search this site (www.microchipC.com).




 

Using the MPLab-ICD to run C code written for the 12C672

A while ago, a obtained some 12C672 chips. They are a great little 8-pin micro, with 2k of memory. Unfortunately, they are not flash upgradable.

I have an MPLab-ICD, which uses a 16F876 to perform in-circuit debugging. Looking through the datasheets for both of these micros, I noticed that they use the same core instruction set, and the same registers. The 12C672 is basically a cut-down 16F876, with a smaller pin count, a few less peripherals, and less memory.

So, I thought to myself, why cant I use my Mplab-ICD to run native Hi-Tech C code written for 12C672?

The Hardware

First, I looked at the pins on an 16F876, and asked myself "Which pins are equivalent to the 12C672?". Then, I made an adaptor to convert the 28-pin socket of the MPLab-ICD to the 8-pin socket of the 12CE674.

This still isnt enough, so I added an adaptor board, that supplied the 10k pullup resistor for the 16F876 and a 4Mhz crystal.

The pinouts are as follows:

Pin N on 28-pin 16F876 >> >> goes to pin N on 8-pin 12C672
20 (VDD) 1 (VDD)
21 (RB0) 5 (GP2)
22 (RB1) 6 (GP1)
23 (RB2) 3 (GP4)
24 (RB3) 2 (GP5)
25 (RB4) 7 (GP0)
26 (RB5) 4 (GP3)
8 (GND or VSS) 8 (GND or VSS)

The Software

I asked myself "If I want to run native 12C672 code on a 16F876, how would I modify the 16F876 header file to suit?"

The 12CE672 (8-pin micro) uses 6 general purpose pins, GP0 to GP5. The 16F876 (28-pin micro) has RB0 to RB5.

So, I modified the 16F876 header file to replace every RR0 with a GP0, and so on.

In the same manner, I went through the rest of the 16F876 header file, and made the register and pin names match the 12C672. Registers that didnt exist on the 12C672, I removed.

So, if you want to run C code written for the 12C672, on an MPLab-ICD, use the following lines:

//using Hi-Tech C
#define _12CE674 USED
#include "xc672icd.h" //see download section for this file

If you want to compile that native C code directly for a 12C672, use the following line:

//using Hi-Tech C
#include <pic.h> //direct for 12C672

Later on, I extended this concept. Get a piece of C code for the 12C672, add the appropriate header files, and then use the following line.

#define ICD_EMULATION_OF_12C672 TRUE //or FALSE for compiling directly to the 12C672

This entire process took 18 months.

Why you can trust this method

I developed an entire project using this method, in a commercial setting. The method has been maturing for the last 12 months. The code transfers flawlessly between the emulated system and a real 12C672 chip, I've never had any problems.

Limitations of this method

You cannot use A/D in your project (I didnt use it in mine so I didnt add it). This would require modifying the hardware (running the RAx ports to the appropriate pins), and modifying the header file.

Download

These sample projects for MPLab show how to debug Hi-Tech C code for the 12C672, in real time, on an MPLab-ICD. Download.

Summary

This technique works great. Enjoy!