A PC-Based Development Programmer For The PIC16C84: 1997 Microchip Technology Inc. DS00589A-page 1
A PC-Based Development Programmer For The PIC16C84: 1997 Microchip Technology Inc. DS00589A-page 1
A PC-Based Development Programmer For The PIC16C84: 1997 Microchip Technology Inc. DS00589A-page 1
AN589
Author:
Robert Spur
Analog Design Specialist, Inc.
INTRODUCTION
This application note describes the construction of a
low cost serial programmer which uses a PC with a parallel (Centronix printer) port to control a PIC16C84.
This programmer has the capability of programming a
PIC16C84 microcontroller, and reading back internal
data without removing the device from the target circuit.
This feature is very useful in applications where
changes in program code or program constants are
necessary to compensate for other system features.
For example, an embedded control system may have to
compensate for variances in a mechanical actuators
performance or loading. The basic program can be programmed and tested during design phase. The final
program and control constants can be easily added
later in the production phase without removing the
microcontroller from the circuit.
Automatic software and performance upgrades can
also be implemented in-system. Upon receiving new
system software via disk or modem, a control
processor with the included programming code could
perform
in-circuit
reprogramming
of
other
microcontrollers in the system.
This programmer can load program code, part
configuration, and EEPROM data into the PIC16C84.
In read back mode, it can verify all data entries.
PROGRAMMING DESCRIPTION
The PIC16C84 microcontroller is placed into programming mode by forcing a low logic level on RB7 (pin 13)
and RB6 (pin 12) while MCLR (pin 4) is first brought low
to reset the part, and then brought to the program/verify
voltage of 12 to 14V. The MCLR pin remains at the program/verify voltage for the remainder of the programming or verification.
DS00589A-page 1
AN589
DETAILED CIRCUIT DESCRIPTION
FIGURE 1:
PROGRAMER SCHEMATIC
LS244 (pin 20)
U1
VPP (13.5V)
D3
PC PARALLEL D4
INTERFACE
GND
D2
R1
2k
18, 25
ACK
D5
BUSY
PE
DS00589A-page 2
MCLR (pin 4)
D1
1N4148
R2
2k
R3
2k
PIC16C84
INTERFACE
GND (pin 5)
U2
74LS244
DATA (RB7, pin 13)
18
10
7
19
D1
R5
750
C2
68 F
10V
Q2
2N3904
1
D0
R4
2k
Q1
2N3906
+5 VDC
LM340-5
C1
22 F
35V
17
U2
74LS244
CLOCK (RB6, pin 12)
3
11
12
AN589
SOFTWARE DESCRIPTION
The listed code provides a hardware-software interface
to a standard PC parallel (Centronix) interface port. The
code can be adapted to a microprocessor parallel interface port by substituting an output command for the
biosprint command.
Control software can transfer the PIC16C84 program,
configuration bits, and EEPROM data from a standard
PROM interface file into the target system by reading
the file and calling the function in Example 1 using the
appropriate command name in the definition table, and
the data to be programmed. The command names are
repeated here for reference.
LOAD_CONFIG
LOAD_DATA
READ_DATA
INC_ADDR
Increments
pointer.
EXAMPLE 1:
PIC16C84
BEGIN_PROG
PARALLEL_MODE
LOAD_DATA_DM
READ_DATA_DM
data
.. program code..
ser_pic16c84(PROGRAM_MODE,0);
.. program code..
EXAMPLE 2:
.. program code..
data = ser_pic16c84(READ_DATA,0); // read data
// transfers data from target part to variable data
.. more program code..
EXAMPLE 3:
.. program code..
ser_pic16c84(LOAD_DATA,data);// load data into target
ser_pic16c84(BEGIN_PROG,0);// program loaded data
ser_pic16c84(INC_ADDR,0);// increment to next address
// transfers data from program variable data to target part
.. more program code..
EXAMPLE 4:
.. program code..
ser_pic16c84(RUN,0);
.. program code..
DS00589A-page 3
AN589
//************************** FIGURE #2 ********************************
//**
**
//**
SERIAL PROGRAMMING ROUTINE FOR THE PIC16C84 MICROCONTROLLER
**
//**
**
//**
Analog Design Specialists
**
//**
**
//*********************************************************************
//FUNCTION PROTOTYPE: int ser_pic16c84(int cmd, int data)
// cmd: LOAD_CONFIG
-> part configuration bits
//
LOAD_DATA
-> program data, write
//
READ_DATA
-> program data, read
//
INC_ADDR
-> increment to the next address (routine does not auto increment)
//
BEGIN_PROG
-> program a previously loaded program code or data
//
LOAD_DATA_DM -> load EEPROM data regesters (BEGIN_PROG must follow)
//
READ_DATA_DM -> read EEPROM data
//
// data: 1) 14 bits of program data or
//
2) 8 bits of EEPROM data (least significant 8 bits of int)
// Additional programmer commands (not part of PIC16C84 programming codes)
//
// cmd: RESET
-> provides 1 ms reset pulse to target system
//
PROGRAM_MODE -> initializes PIC16C84 for programming
//
RUN
-> disconnects programmer from target system
//
// function returns:1) 14 or 8 bits read back data for read commands
//
2) zero
for write data commands
//
3) PIC_PROG_EROR = -1 for programming function errors
//
4) PROGMR_ERROR = -2 for programmer function errors
#include <bios.h>
#define
#define
#define
#define
#define
#define
#define
#define
#define
LOAD_CONFIG
0
LOAD_DATA
2
READ_DATA
4
INC_ADDR
6
BEGIN_PROG
8
PARALLEL_MODE 10
LOAD_DATA_DM
3
READ_DATA_DM
5
MAX_PIC_CMD
63
#define RESET
#define PROGRAM_MODE
#define RUN
64
65
66
// not used
#define PIC_PROG_EROR -1
#define PROGMR_ERROR -2
#define PTR
// use device #0
DS00589A-page 4
AN589
if(cmd <=MAX_PIC_CMD)
{
biosprint(0,8,PTR);
s_cmd = cmd;
for (i=0;i<6;i++)
{
biosprint(0,(s_cmd&0x1) +2+8,PTR);
biosprint(0,(s_cmd&0x1)
+8,PTR);
s_cmd >>=1;
}
8,PTR);
clock hi
clock low
******************
// set bits 001000, clock low
return 0;
}
else if((cmd ==READ_DATA)||(cmd ==READ_DATA_DM)) //read 14 bits from part, lsb first
{
biosprint(0, 4+8,PTR);
// set bits 001100, clock low, tri state data buffer
for (i=200;i;i) ;
// delay between command & data
biosprint(0,2+4+8,PTR);
// set bits 001110, clock hi, leading bit
biosprint(0, 4+8,PTR);
// set bits 001100, clock low
data =0;
for (i=0;i<14;i++)
// programmer error
// reset device
DS00589A-page 5
AN589
{
biosprint(0,32+16+4,PTR);
(reset
delay(1);
biosprint(0,32
+4,PTR);
return 0;
}
else if(cmd ==PROGRAM_MODE)
{
biosprint(0,32+16+4,PTR);
delay(10);
biosprint(0,8,PTR);
delay(10);
//
//
//
//
return 0;
}
else if(cmd ==RUN)
{
biosprint(0,32+4,PTR);
return 0;
}
else return PROGMR_ERROR;
}
DS00589A-page 6
// command error
Note the following details of the code protection feature on PICmicro MCUs.
The PICmicro family meets the specifications contained in the Microchip Data Sheet.
Microchip believes that its family of PICmicro microcontrollers is one of the most secure products of its kind on the market today,
when used in the intended manner and under normal conditions.
There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our knowledge, require using the PICmicro microcontroller in a manner outside the operating specifications contained in the data sheet.
The person doing so may be engaged in theft of intellectual property.
Microchip is willing to work with the customer who is concerned about the integrity of their code.
Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not
mean that we are guaranteeing the product as unbreakable.
Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of
our product.
If you have any further questions about this matter, please contact the local sales office nearest to you.
Trademarks
The Microchip name and logo, the Microchip logo, FilterLab,
KEELOQ, microID, MPLAB, PIC, PICmicro, PICMASTER,
PICSTART, PRO MATE, SEEVAL and The Embedded Control
Solutions Company are registered trademarks of Microchip Technology Incorporated in the U.S.A. and other countries.
dsPIC, ECONOMONITOR, FanSense, FlexROM, fuzzyLAB,
In-Circuit Serial Programming, ICSP, ICEPIC, microPort,
Migratable Memory, MPASM, MPLIB, MPLINK, MPSIM,
MXDEV, PICC, PICDEM, PICDEM.net, rfPIC, Select Mode
and Total Endurance are trademarks of Microchip Technology
Incorporated in the U.S.A.
Serialized Quick Turn Programming (SQTP) is a service mark
of Microchip Technology Incorporated in the U.S.A.
All other trademarks mentioned herein are property of their
respective companies.
2002, Microchip Technology Incorporated, Printed in the
U.S.A., All Rights Reserved.
Printed on recycled paper.
M
WORLDWIDE SALES AND SERVICE
AMERICAS
ASIA/PACIFIC
Japan
Corporate Office
Australia
Rocky Mountain
China - Beijing
Atlanta
500 Sugar Mill Road, Suite 200B
Atlanta, GA 30350
Tel: 770-640-0034 Fax: 770-640-0307
Boston
2 Lan Drive, Suite 120
Westford, MA 01886
Tel: 978-692-3848 Fax: 978-692-3821
Chicago
333 Pierce Road, Suite 180
Itasca, IL 60143
Tel: 630-285-0071 Fax: 630-285-0075
Dallas
4570 Westgrove Drive, Suite 160
Addison, TX 75001
Tel: 972-818-7423 Fax: 972-818-2924
Detroit
Tri-Atria Office Building
32255 Northwestern Highway, Suite 190
Farmington Hills, MI 48334
Tel: 248-538-2250 Fax: 248-538-2260
Kokomo
2767 S. Albright Road
Kokomo, Indiana 46902
Tel: 765-864-8360 Fax: 765-864-8387
Los Angeles
18201 Von Karman, Suite 1090
Irvine, CA 92612
Tel: 949-263-1888 Fax: 949-263-1338
China - Chengdu
Microchip Technology Consulting (Shanghai)
Co., Ltd., Chengdu Liaison Office
Rm. 2401, 24th Floor,
Ming Xing Financial Tower
No. 88 TIDU Street
Chengdu 610016, China
Tel: 86-28-6766200 Fax: 86-28-6766599
China - Fuzhou
Microchip Technology Consulting (Shanghai)
Co., Ltd., Fuzhou Liaison Office
Unit 28F, World Trade Plaza
No. 71 Wusi Road
Fuzhou 350001, China
Tel: 86-591-7503506 Fax: 86-591-7503521
China - Shanghai
Microchip Technology Consulting (Shanghai)
Co., Ltd.
Room 701, Bldg. B
Far East International Plaza
No. 317 Xian Xia Road
Shanghai, 200051
Tel: 86-21-6275-5700 Fax: 86-21-6275-5060
China - Shenzhen
San Jose
Hong Kong
New York
Toronto
6285 Northam Drive, Suite 108
Mississauga, Ontario L4V 1X5, Canada
Tel: 905-673-0699 Fax: 905-673-6509
India
Microchip Technology Inc.
India Liaison Office
Divyasree Chambers
1 Floor, Wing A (A3/A4)
No. 11, OShaugnessey Road
Bangalore, 560 025, India
Tel: 91-80-2290061 Fax: 91-80-2290062
Korea
Microchip Technology Korea
168-1, Youngbo Bldg. 3 Floor
Samsung-Dong, Kangnam-Ku
Seoul, Korea 135-882
Tel: 82-2-554-7200 Fax: 82-2-558-5934
Singapore
Microchip Technology Singapore Pte Ltd.
200 Middle Road
#07-02 Prime Centre
Singapore, 188980
Tel: 65-334-8870 Fax: 65-334-8850
Taiwan
Microchip Technology Taiwan
11F-3, No. 207
Tung Hua North Road
Taipei, 105, Taiwan
Tel: 886-2-2717-7175 Fax: 886-2-2545-0139
EUROPE
Denmark
Microchip Technology Nordic ApS
Regus Business Centre
Lautrup hoj 1-3
Ballerup DK-2750 Denmark
Tel: 45 4420 9895 Fax: 45 4420 9910
France
Microchip Technology SARL
Parc dActivite du Moulin de Massy
43 Rue du Saule Trapu
Batiment A - ler Etage
91300 Massy, France
Tel: 33-1-69-53-63-20 Fax: 33-1-69-30-90-79
Germany
Microchip Technology GmbH
Gustav-Heinemann Ring 125
D-81739 Munich, Germany
Tel: 49-89-627-144 0 Fax: 49-89-627-144-44
Italy
Microchip Technology SRL
Centro Direzionale Colleoni
Palazzo Taurus 1 V. Le Colleoni 1
20041 Agrate Brianza
Milan, Italy
Tel: 39-039-65791-1 Fax: 39-039-6899883
United Kingdom
Arizona Microchip Technology Ltd.
505 Eskdale Road
Winnersh Triangle
Wokingham
Berkshire, England RG41 5TU
Tel: 44 118 921 5869 Fax: 44-118 921-5820
01/18/02