3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

Microdot - wrist watch LED pattern timepiece

Step 2Programming and Micro selection

Programming and Micro selection
«
  • microdotbits.jpg
  • microdoticsp.jpg
I am pretty familiar with programming and PIC 16F88 and had a few lying around from other projects. It seemed an obvious choice to save learning a new instruction set or new lot of onchip peripherals. This device has two ports A,B a selection of things like a serial i/f, A/D converter, a nice comfortable 8kb Flash rom and scads of memory...a whole 368 bytes of ram. One thing that was also handy was that it had pins for an onboard oscillator which could be connected to a common 32.768khz watch crystal for timekeeping and low power modes. The timekeeping oscillator can run even when the device was in low power mode. Lastly it could wake up when it detected a change on some of the pins (pins 4-7/portb have wake on change of state capability).

Because this was to be as small as possible I used a 20pin SOIP 16F88. This was a 300MIL wide version, Microchip have a 150mil SSOIP (skinny, small outline package), but considering the device was to be hand prototyped, I wanted to use a bigger easier to handle chip.

Obviously a SOIP package wont fit in a programmer so I had to use ICSP....which resulted in a whole lot of grief! ICSP is a way of programming the microcontroller, while it is still in a circuit. ICSP stands for In Circuit Serial Programming and is commonly used to program 'blank' boards, or update software without unsoldering/socketing the microcontroller.

Firstly I didn't read enough about ICSP to add the right circuitry to handle ICSP in my first prototype. Then I didn't read the microchip datasheet regarding a couple of extra pins on the 20pin 16F88SOIP. These pins are the AVss and AVdd pins. They normally provide the reference voltages for the A/D converter.

I took a while to figure out that these pins must be connected (I connected to GND/Vdd) for ICSP to work.

Also important is to have a proper reset circuit for the MCLR pin. This is very important so the ICSP program can reset the microcontroller, prior to doing its programming.

See the main picture in this section. It shows the MCLR pin connected to Vss via a pullup resistor and a diode. The pullup is necessary, because for ICSP to work you should really have the MCLR configured as a reset pin, rather than a input pin (more on this later). The diode prevents the Vpp voltage from the ICSP programmer which can be around 13V from damaging the rest of the circuit.
The picture also shows the connections for Vdd and AVdd connected together as for GND/AVss.

Refer to the Eagle schematic files for full schematic( or in the next section) but in the main picture note the little 'X' shaped symbols. These are SMD pads, there are no connectors in this device so SMD pads are used to solder power connections and the ICSP connection. The ICSP pins are arranged on the board in a convienient location. Short lengths of wire connect to a 10pin IDC header (pretty standard for ICSP programmers). The sub picture shows this arrangement.

They are also used to solder in the watch crystal. In the 16F88 the PGD and PGC pins are also the T1OSO and T1OSI pins which are used to connect an external crystal to the PIC T1 oscillator to make a real time clock. Fortunately you can also use these when programming via ICSP as well.....if you are careful.
If the oscillator is going when the ICSP programmer tries to use the pins, the ICSP programmer is going to have trouble. You need to add a delay at the start of your program. The code fragment below shows this in action. Note I'm also disabling the external oscillator as soon as possible after startup just for good measure :
void main()
{
unsigned char i;
unsigned short nDelay;
t1con = 0; //disable timer1 as soon as we reset
osccon = 0x76; //set for internal 8MHz clock
while( (osccon & 0x04)==0); //and wait for clock to settle and be ready

//setup peripherals
porta = 0;
portb = 0;
cmcon = 0x07; //disable comparator output, do now to set trisa properly
trisa = 0xff; //All set to input at startup
trisb = 0xff; //all pins in portb set to input
ansel = 0x00; //no analog in this cct....important step often forgotten, I did!!

delay_s(2); //allow programmer time to do stuff... VERY IMPORTANT

Lastly in the main picture note the symbol SMJ100 which is bridged in the upper top left hand corner called SJ100. This was to be used in an emergency if I accidentally programmed in a configuration that disabled the MCLR pin and couldn't stop the watch oscillator stuffing up the ICSP PGD/PGC pins. This is another handly Eaglecad library part, a simple SMD link. By bridging it on my board it is a convienient place to unbridge if necessary. This would be necessary in the above situation. Normally you only connect the MCLR pin (to reset the chip), the GND pin (for reference) and the PGD/PGC pins to use ICSP. In practice the programmer will reset the chip, send magic control signals to the processor via PGD/PGC and get it to be receptive for some new data lovin'.
However if the processor is busy doing other things and is not going to respond to a reset, you need to yank it's power rail to get it's attention. In this case the Vdd pin of the ICSP programmer needs to be connected to the circuit. I would cut the bridge, connect a wire to the Vdd SMD pad (the little 'X' symbol nearby) and give the processor new instructions. In the end when I downloaded dodgy code, I just powered up the cct from the programmer without using this system. If you had a more complex or power hungry circuit you should have some way of disconnecting the processor from the circuit power rail and connect it to the Vdd pin on your programmer.

So in summary to do successful ICSP remember:
- setup a proper reset circuit with protection diode and pullup resistor
- connect AVdd/AVss to the power rails if you are not using them (and the chip has them, only for 20pin 16F88...not for other versions).
- in your layout, put the ICSP connections somewhere sensible and easy to get at.
- have a way of isolating the processor power from the cct power and connecting ICSP Vdd for emergencies
- avoid emergencies by ensuring that the PGD/PGC pins are ready for use as soon as possible after a reset.
« Previous StepDownload PDFView All StepsNext Step »

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
26
Followers
7
Author:rgbphil
update later