- epe... · news is that the pic16f877 and its close relatives the ’876, ’874, and ’873 have...

12
Copyright © 2008, Wimborne Publishing Ltd (Sequoia House, 398a Ringwood Road, Ferndown, Dorset BH22 9AU, UK) and TechBites Interactive Inc., (PO Box 857, Madison, Alabama 35758, USA) All rights reserved. The materials and works contained within EPE Online — which are made available by Wimborne Publishing Ltd and TechBites Interactive Inc — are copyrighted. TechBites Interactive Inc and Wimborne Publishing Ltd have used their best efforts in preparing these materials and works. However, TechBites Interactive Inc and Wimborne Publishing Ltd make no warranties of any kind, expressed or implied, with regard to the documentation or data contained herein, and specifically disclaim, without limitation, any implied warranties of merchantability and fitness for a particular purpose. Because of possible variances in the quality and condition of materials and workmanship used by readers, EPE Online, its publishers and agents disclaim any responsibility for the safe and proper functioning of readerconstructed projects based on or from information published in these materials and works. In no event shall TechBites Interactive Inc or Wimborne Publishing Ltd be responsible or liable for any loss of profit or any other commercial damages, including but not limited to special, incidental, consequential, or any other damages in connection with or arising out of furnishing, performance, or use of these materials and works. READERS’ TECHNICAL ENQUIRIES We are unable to offer any advice on the use, purchase, repair or modification of commercial equipment or the incorporation or modification of designs published in the magazine. We regret that we cannot provide data or answer queries on articles or projects that are more than five years’ old. We are not able to answer technical queries on the phone. PROJECTS AND CIRCUITS All reasonable precautions are taken to ensure that the advice and data given to readers is reliable. We cannot, however, guarantee it and we cannot accept legal responsibility for it. A number of projects and circuits published in EPE employ voltages that can be lethal. You should not build, test, modify or renovate any item of mainspowered equipment unless you fully understand the safety aspects involved and you use an RCD adaptor. COMPONENT SUPPLIES We do not supply electronic components or kits for building the projects featured; these can be supplied by advertisers in our publication Practical Everyday Electronics. Our web site is located at www.epemag.com We advise readers to check that all parts are still available before commencing any project. To order you copy for only $18.95 for 12 issues go to www.epemag.com www.epemag.com

Upload: others

Post on 04-Apr-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Copyright © 2008, Wimborne Publishing Ltd (Sequoia House, 398a Ringwood Road, Ferndown, Dorset BH22 9AU, UK)

and TechBites Interactive Inc., (PO Box 857, Madison, Alabama 35758, USA)

All rights reserved.

The materials and works contained within EPE Online — which are made available by 

Wimborne Publishing Ltd and TechBites Interactive Inc — are copyrighted.  TechBites Interactive Inc and Wimborne Publishing Ltd have used their best efforts in preparing these materials and works. However, TechBites Interactive Inc and Wimborne Publishing Ltd make no warranties of any kind, expressed or implied, with regard to the documentation or data contained herein, and specifically disclaim, without limitation, any implied warranties of merchantability and fitness for a particular purpose.  Because of possible variances in the quality and condition of materials and workmanship used by readers, EPE Online, its publishers and agents disclaim any responsibility for the safe and proper functioning of reader‐constructed projects based on or from information published in these materials and works.  In no event shall TechBites Interactive Inc or Wimborne Publishing Ltd be responsible or liable for any loss of profit or any other commercial damages, including but not limited to special, incidental, consequential, or any other damages in connection with or arising out of furnishing, performance, or use of these materials and works.  READERS’ TECHNICAL ENQUIRIES 

We are unable to offer any advice on the use, purchase, repair or modification of commercial equipment or the incorporation or modification of designs published in the magazine. We regret that we cannot provide data or answer queries on articles or projects that are more than five years’ old. We are not able to answer technical queries on the phone. 

PROJECTS AND CIRCUITS 

All reasonable precautions are taken to ensure that the advice and data given to readers is reliable. We cannot, however, guarantee it and we cannot accept legal responsibility for it. A number of projects and circuits published in EPE employ voltages that can be lethal. You should not build, test, modify or renovate any item of mains‐powered equipment unless you fully understand the safety aspects involved and you use an RCD adaptor. 

COMPONENT SUPPLIES 

We do not supply electronic components or kits for building the projects featured; these can be supplied by advertisers in our publication Practical Everyday Electronics. Our web site is located at www.epemag.com 

We advise readers to check that all parts are still available before commencing any project. 

 

To order you copy for only $18.95 for 12 issues go to www.epemag.com 

www.epem

ag.co

m

Copyright © 2000 Wimborne Publishing Ltd andMaxfield & Montrose Interactive Inc

EPE Online, March 2000 - www.epemag.com - 183

This project combines Mi-crochip’s MPLAB developmentsoftware with the advanced self-debugging features of the latestPIC chips. The result is a user-friendly advanced developmentsystem for a very low cost.

DEVELOPMENTSYSTEMS

Developing projects with mi-crocontrollers is extremely inter-esting, especially the ability toalter the way hardware respondsjust by making simple changes toprogram code.

The problem is that eachchange of code has to be written,compiled (converted into suitableform for loading) and pro-grammed into a chip before it canbe tested. Several low cost sys-tems – such as the EPE PICtutorare available (see our web pageat www.epemag.com for moredetails) and are adequate for thedevelopment of simple programs,but for larger changes and pro-grams it can be tedious, and er-rors are almost as easy to intro-duce as to eliminate.

Better methods of testing pro-grams rely on more advancedsoftware that can “run” in a virtualchip on a PC screen and ad-vanced hardware which commu-nicates with the program in thePC, reads input pins, andswitches output pins to match thelevels of the virtual chip. Such a

ging (ICD). This requires a chipwith special built in hardware(known as a “Background De-bugger”) and software whichcan communicate its status viaa serial link.

The chip is fitted to its work-ing printed circuit board (PCB)and all external hardware isconnected and active. Code isthen programmed, run, and de-bugged under PC control, until itis running correctly. For Mi-crochip PIC users, the goodnews is that the PIC16F877 andits close relatives the ’876, ’874,and ’873 have built in ICD facili-ties and can be used to develop

A real-time PIC In-Circuit Emulator (ICE), programmer,debugger, and development system

EPE ICEBREAKER by MARK STUART

system is called an In-CircuitEmulator or “ICE” and profes-sional systems are available forpractically every type of micro-controller.

The problem with this iscost. A professional ICE for thePIC series of chips costs a rea-sonable 2000 UK Pounds or so– not a lot if you are a profes-sional programmer being paidtwice that each month – butmore certainly enough to makeyour eyes water if you are anamateur!

Just lately a new type of de-velopment system has ap-peared called In-Circuit Debug-

LK1RE2

RC0

RC1

RC2

RC3

RC4

RC5

RC6

RC7

15

16

17

18

23

24

25

26

RD1

RD2

RD3

RD4

RD5

RD6

RD7

RD019

20

21

22

27

28

29

30

C210p

OSC 2

VSS(GND)

VSS(GND)

RA0

RA1

RA2

RA3

RA4

RA5

VDD(+V)

VDD(+V)

OSC 113

C110p

2

3

4

5

6

7

X120MHz

14

RB1

IC1PIC16F877

RE0

RE19

10

RB2

RB3

RB4

RB5

RB6

RB7

35

36

37

38

39

40

1

8

RB034

33

R1410k

0V (GND)

LK2

D75V1

D65V1

D85V1

R111k

R13470!

R1210k

PL1

+5V

a

k

a

k

a

k

MCLR11

32

12

31

16

59

Fig.1. Minimum circuit for using the PIC16F877 as a“background” debugger.

www.epem

ag.co

m

Copyright © 2000 Wimborne Publishing Ltd andMaxfield & Montrose Interactive Inc

EPE Online, March 2000 - www.epemag.com - 184

code which can be run in theseand smaller chips in the range –such as the most popularPIC16F84.PIC IN-CIRCUITDEBUGGING

This article is intended as aneasy introduction to ICD with verysimple demonstration programs,users can then progress to usingthe more complicated features ofthe chips. It is not intended as aprogramming tutorial, but the op-eration of some programs is de-scribed in the course of demon-strating the ICD hardware.

Simple programs can beloaded, run and debugged withoutknowing much about the entireICD system which is extremelycomplicated and occupies manypages of the PIC data sheets.The Microchip web site(www.microchip.com) providesan enormous amount of informa-tion for those wishing to knowmore.

MINIMUM ICD SET UPThe minimum hardware re-

quired for ICD, using thePIC16F877, is shown in Fig.1.Communication to a computerserial port is achieved via thePort RB6 and RB7 pins of thechip, which cannot be used forother functions. As there areplenty of other port pins availablethis is not a significant limitation.

Port RB6 receives data fromthe computer, and RB7 transmitsdata to the computer. Both ofthese pins operate at simple 0Vto 5V logic levels. Some com-puter serial port output pins swing10V positive and negative, and solimiting resistors and 5����1V Zenerdiodes are used for protection.

The serial data sent back tothe computer should also be ca-pable of swinging 10V, but it hasbeen found that practically all

computers read serial data cor-rectly when 0V to 5V swings areused. A third connection linksthe serial port RTS output to theVPP or MCLR pin of the chip.This allows control of the pro-gramming voltage(programming at 5V, as op-posed to the 12V normally re-quired) and resetting of the chipby the computer.

After a Reset, the chipchecks if pins RB6 and RB7 areshorted to 0V. If they are, it ig-nores the ICD functions and justruns the code directly startingfrom location 0. Links fitted inthe positions marked LK enforcethis option.

As well as the hardwareconnections, the computerneeds to run a program to com-municate with the chip, and thechip must have a program tocommunicate with the com-puter. The program in the chipis loaded and copy-protectedinto the upper half of the chip’s8K program memory.

It may seem wasteful to usehalf of the chip’s memory forprotected code, but in practice,the 4K remaining is a vastamount of space for the PICprogram and it is very doubtfulthat it will ever be filled. Once

working code has been devel-oped and debugged it can beloaded and will run alone in anychip in the 16x range – the pro-tected communication code is re-quired only in the chip used fordebugging.

Connections for suitable se-rial leads are shown in Table 1.These are standard connections,but can be made up with 4-waycable (flat telephone cable isideal) if required. Take care whenmaking leads to get the pin num-bering correct – it is very confus-ing, the only safe way is to readthe molded numbers on the con-nectors.

The port connections for thePIC 16F877/874 and the alterna-tive connections for the 28-pinPIC16F876/873 versions of thechip are shown in Fig.2.

HARDWAREWhilst the minimum system

could be used, it is unlikely thatany PIC application would oper-ate without external hardware.Most systems have power sup-plies, input switches, output de-vices and so on. It is irritating andtime consuming to have to set upthese simple hardware require-ments when the object is to get a

Constructional Project

www.epem

ag.co

m

Copyright © 2000 Wimborne Publishing Ltd andMaxfield & Montrose Interactive Inc

EPE Online, March 2000 - www.epemag.com - 185

program written and tested.EPE ICEbreaker was designedto include a number of input andoutput devices along with a sol-derless connection system sothat many applications could betested from a notebook PC with-out the use of a soldering iron.

The full ICEbreaker circuitdiagram is shown in Fig.3,whilst Fig.4 gives the PCB de-tails.

Resistors R11 to R13, andR14, Zener diodes D6 to D8 andlinks LK1/2 are the same as theminimum system. PL2 allowsthe power and computer con-nections to be extended so that

the PIC could be fitted into an-other board with other hardwareand still debugged via the samecomputer lead.

Voltage regulator IC2 allowsa range of power adapters to beused connected to 2����1mm powersocket SK5. Links 3 and 4 allowpositive inner or outer connec-tions to be set. If accidentalpower reversal is possible, thepositive link connection can bemade using a 1A diode (e.g.1N4001) instead of a piece ofwire. Power is indicated by light-emitting diode (LED) D5 via resis-tor R8.

Switch S1 provides an alter-native hardware reset which canbe useful for stopping programsquickly and for restarting fromlocation 0.

For ICD operation the PICneeds accurate timing. A 20MHzcrystal X1 together with capaci-tors C1 and C2 provide the stan-dard oscillator components. Alter-native positions (X2) and (C3, C4)are to be used with 28-pin chips.

Resistors R15 and R16 allowRC oscillator options to be used ifrequired for testing or runningfully debugged code, but as RCoscillator stability is poor, this op-

tion is not recommended forICD use. Other crystal frequen-cies can be used and the com-puter serial port speed alteredaccordingly. 20MHz gives thefastest communication (38,400BAUD) and is best if there areno other special frequency re-quirements.

Stepping motor driving is avery popular PIC application.Transistors TR1 to TR4 and as-sociated resistors R2 to R5 andprotection diodes D1 to D4 pro-vide four open collector driversfor four-phase unipolar motors.Connectors PL3 and PL4 allowfor 2����54mm and 2mm pitch mo-tor connectors. Input to thedrivers is via SK4. The transis-tors can also be used individu-ally as simple open-collectornpn switches for driving relays,lamps and similar loads up to24V and 400mA.

Two other output transistorsare fitted. TR5 is a simple opencollector npn device and TR6drives a double-polechangeover relay RLA. Thesetwo devices are useful for bidi-rectional control of a DC motor.RLA can be wired as a revers-ing switch and the motor can be

Constructional Project

ICE9-way to 9-way

Computer1235

73 TxD2 RxD5 GND

ICE9-way to 25-way

Computer1235

42 TxD3 RxD

7

Table 1: Serial LeadConnections.

7

8

9

6

10

11

12

13

1

2

3

4

5

15

14

16

17

18

19

20

40

39

38

37

36

35

34

33

32

31

30

29

28

27

26

25

24

23

22

21

7

8

9

6

10

11

12

13

1

2

3

4

5

1514

16

17

18

RA2/AN2/VREF

RA2/AN2/VREF

RA3/AN3/VREF

RA3/AN3/VREF

MCLR/VPP/THV

MCLR/VPP/THV

GND/(VSS)

GND/(VSS) RB1

RB1

RB2

RB2

RB3/PGM

RB3/PGM

RA1/AN1

RA1/AN1

RA0/AN0

RA0/AN0

OSC1/CLK IN

OSC1/CLK IN OSC2/CLK OUT

OSC2/CLK OUT

GND(VSS)

GND(VSS)

RD7/PSP7

+VE(VDD)

+VE(VDD)

+VE(VDD)

RB7/PGD

RB7/PGD

RB6/PGC

RB6/PGC

RB5

RB5

RB4

RB4

19

20

21

22

23

24

25

26

27

28

RA5/AN4/SS

RA5/AN4/SS

RE0/RD/AN5

RE1/WR/AN6

RE2/CS/AN7

RA4/TOCKI

RA4/TOCK1

RC0/T1OSO/T1CKI

RC0/T1OSO/T1CKI RC1/T1OSI/CCP2

RC1/T1OSI/CCP2 RC2/CCP1

RC2/CCP1 RC3/SCK/SCL

RC3/SCK/SCL

RD0/PSP0

RD1/PSP1

RC4/SDI/SDA

RC4/SDI/SDA

RC5/SDO

RC5/SDO

RC6/TX/CK

RC6/TX/CK

RC7/RX/DT

RC7/RX/DT

RD4/PSP4

RD6/PSP6

RD2/PSP2

RD3/PSP3

RD5/PSP5

RB0/INT

RB0/INT

PIC16F876 AND 873

PIC16F877 AND 874

Fig.2. Port connections for the PIC16F877/874 and the alternative 28-pin PIC16F876/873.

www.epem

ag.co

m

Copyright © 2000 Wimborne Publishing Ltd andMaxfield & Montrose Interactive Inc

EPE Online, March 2000 - www.epemag.com - 186

turned on and off by TR5.Many applications require

display of information, and anintelligent LCD module is anideal display device. X3 hasstandard 4- or 8-bit drive capa-bility, and requires a minimumof six output lines for driving. Allpins are available at connectorSK1. Preset VR1 allows thecontrast of the LCD to be al-tered to suit the lighting condi-tions and viewing angle.

Just two input devices arefitted. S2 and S3 are simplesingle-pole push-to-makeswitches with pull-up resistorsR6 and R7.

Whilst the circuit diagramseems simple, the PCB layoutshows that there are far moreconnection points, and that aprototyping area with a solder-less breadboard is provided.Each side of the main inte-grated circuit (IC) sockets thereare spaces for rows of turned-pin sockets. The inner two rowsconnect to the adjacent IC pins,whilst the outer two rows arepower and ground connections.

Turned-pin socket strips canbe fitted in all rows, but it ismore practical to have a singlerow of sockets each side of thechip and leave the other spacesblank so that pull up or pulldown resistors can be solderedin position if required. An addi-tional “patch” area is providedbelow IC1 and is ideal foradding “permanent” hardwaresuch as LEDs or presets.

ICEBREAKERSOFTWARE

ICEbreaker must be runfrom a PC with at least Win-dows 95. This helps keep thesoftware simple, and is not aserious restriction as PCs thatcan run Win95 are available at

Constructional Projectvery low prices. A standardPentium 133 without specialsound, graphics or multimediais more than adequate providedit has a spare serial port (COM1 – 4).

The software is designed tobe run in conjunction with Mi-crochip’s MPLAB software. Thisis available from many sources– the Microchip web site is theideal one as it allows the verylatest version to be loaded, al-ternatively the Microchip CD-ROM is widely available andgood for those without internetaccess.

MPLAB is used in “editoronly” mode to allow assemblylanguage source code to bewritten and then assembled toproduce the necessary .HEXcode for programming into thechip. MPLAB also produces a.COD file which is used by theICEbreaker software to keeptrack of the program executionwhen debugging, single step-ping and running the program.Like many other PC programs,MPLAB has a lot of featuresthat are not regularly used, how-ever the advanced featuresdon’t get in the way when usingit at the simple level required byICEbreaker.

The ICEbreaker software isa simple stand-alone applicationthat can be run directly from afloppy disk if necessary. Thisarticle assumes that the con-tents of the ICEbreaker disk arecopied into a new folder(directory) on the C-drive, whichhas been labeled “icebreak”.The only files required are ice-break.exe and icebreak.ini, butit is also convenient to storeprogram files in the same direc-tory.

ICEbreaker and MPLABshould be run together, and the“Alt” and “Tab” keys or thetaskbar buttons used to switch

from one to the other.

CONSTRUCTIONThe EPE ICEbreaker

printed circuit board componentlayout and (approximately) fullsize copper foil master areshown in Fig.4. This board isavailable from the EPE OnlineStore (code 7000257) fromwww.epemag.com

Assembly of the board isstraightforward. Begin by fittingseven 12mm pillars with shortM3 screws before adding anycomponents. Refer to the com-ponent layout drawing and thenfit plain uninsulated wire links inall of the positions shown. Fittwo-way pin headers in the posi-tion for LK1 and LK2 so that twoshorting links can be connectedif required.

Links LK3 and LK4 providethe facility to set the input powersocket for positive or negativeinner connection. For positiveinner fit the links in position B,for negative fit them in positionA. As mentioned previously it ispossible to add a diode in placeof one of the links to protectagainst polarity reversal. To dothis, fit the cathode of the diodeto the point marked with a +sign, and the anode of the diodeto the appropriate A or B posi-tion.

Fit the diodes and resistorsnext, taking care to identify thetype and polarity. Usually thecathodes are marked with ablack or dark blue band, whichshould be positioned to matchthe line on the component lay-out diagram. The transistorsTR1 to TR6 are all the sametype and are fitted with theircurved sides as shown in thediagram. They should be fittedclose to the board surface sothat they cannot get bent and

www.epem

ag.co

m

Copyright © 2000 Wimborne Publishing Ltd andMaxfield & Montrose Interactive Inc

EPE Online, March 2000 - www.epemag.com - 187

Constructional Project

bc e

bc e

bc e

bc e

bc e

bc e

RLA 2

OU

T

CO

M.

INIC

27805

C6

100

nC

5100

n

RLA

2

RLA

1

TR

6ZTX

451

NC

1

PO

LE 1

NO

1

NC

2

PO

LE 2

NO

2

SK

5

PO

WE

RIN

PU

T

LK3/4

SK

6

14(

10)

13(9

)

L.C

.D.

CO

NN

EC

TIO

NS

STEP

PIN

GM

OTO

RC

ON

NEC

TIO

NS

R3

R2

220

!22

0 !220

!220

!

D1

30V

TR

1ZTX

451

ak

R4

PL4

D2

30V

TR

2ZT

X45

1

k a

LK5

LK6

PL3D

7D

6

D3

30V

TR3

ZTX

451

k aR

5

C1 (

C3)

10p

C2 (

C4)

10p

16 x

2 L

.C.D

. D

ISP

LAY

1413

1211

109

87

65

4

X3

R6

4k7

S2

CO

NTR

AS

T

R1

4k7

SK

1

D5

D4

D3

D2

D1

D0R/W

RS

E

32

1

VR

110

k

X1

(X2)

20M

Hz

R15

(R16

)

R7

4k7

R8

1k

D5

L.E.D

.

S3

ka

D7

5V

1

P4

P1

P2

P3

MC

LR

RE

SET

STE

PP

ER M

OTO

RD

RIV

ER

IN

PU

TS

TR4

ZTX

451

30V

k a

ZTX

451

D4

30V

0V

12/3

1(8

/19)

SK

4S1

LIN

K F

OR

FR

EE

RU

NN

ING

1(1)

TR

AN

SIS

TO

RC

OLL

EC

TO

R

TR

5ZTX

451

SK

7/T

C

R9

470!

470 !

TR

AN

SIS

TO

RBA

SE

D8

5V1

ak a

D9

1N40

01

SK

7/R

D

R10

k a

RE

LAY

DR

IVE

R

RB

7

RB

6

OS

C1/

CLK

IN

OS

C2/

CLK

OU

T

+V

11/

32(2

0)

PIC

16F

876

/873

PIC

16F87

7/8

74

IC1

PU

SH

BU

TTO

NC

ON

NE

CTIO

NS

LK

1

39(2

7)

40(2

8)

PL2 LK

2

D6

5V1k a

k

R12

10k

R13

470

!

R11 1k

PL1

R14

10k

1 5

6 9+5V

SK

2

SK

3

1C

23

C4

*

* SE

E T

EXT

+5V

MC

LR0V

B7

B6

SK

7/TB

0V

Fig.3. Complete circuit diagram for the EPE ICEbreaker.

www.epem

ag.co

m

Copyright © 2000 Wimborne Publishing Ltd andMaxfield & Montrose Interactive Inc

EPE Online, March 2000 - www.epemag.com - 188

moved around when the boardis handled.

Use turned-pin socket stripsfor the 40 and 28-way IC posi-tions, and position a second rowof sockets alongside. Note thatthere is also the option of anarrow-bodied version of the28-pin device, and holes havebeen drilled to allow for this typeto be used. If required, socketstrips can be fitted for bothtypes without causing any diffi-culty. Also fit turned-pin socketstrips for SK1, SK2, SK3, SK4,SK6, and the three connectionsTB, TC, and RD. Also fit two 13-way strips to the upper andlower rows of the patch area –these are the positive and nega-tive “rails” and make very con-venient connection points fortaking power to the breadboard.

Fit pin headers for PL2, PL3and PL4 – the holes for theseare made tight to give extrasupport and so the pins mayneed pressing home against ahard surface. Fit push-switchesS1, S2 and S3, preset VR1, re-lay RLA and the voltage regula-tor IC2; an M3 screw and nutshould be used to secure thetab. A heatsink is not requiredfor most applications, but thereis space to fit a low profile type,or even a small piece of alu-minum if higher current loadsare to be used.

The 20MHz crystal and itsassociated capacitors C1 andC2 should be fitted if the (usual)40-pin device is being used forIC1. If a 28-pin version is usedthen fit these components to thealternative locations X2, C3 andC4. If both types of device maybe used, it is possible to fit twocrystals and two pairs of capaci-tors.

DISPLAY MODULEThe LCD module fits above

the board on 16mm long 6BA orM2.5 screws. Fit the four screwsfrom the track side of the boardand secure them with nuts. Fitfour more nuts and positionthem equally so that the LCDlies level and approximately10mm from the board. The con-nections to the LCD are madeto allow it to be unplugged foraccess to IC2 and for use inother applications.

Fit a 16-way pin-to-pin con-nector to the board, with theslightly thinner pins upwards. Fit(but do not solder) a 16-waywirewrap turned-pin socket stripto the LCD so that the socketsface downwards and plug ontothe pin-to-pin connector. Makesure the LCD is level, solder thewire wrap pins to the LCD andcut off the excess. The LCD cannow be secured by fitting an-other four nuts.

The serial port connectorPL2 and power connector SK5fit directly onto the board. Makesure that they are pressed fullyhome before soldering.

The solderless breadboardis secured to the board simplyby its self-adhesive backing.

Make sure that it is accuratelypositioned (and the right wayup) before pressing it firmly intoplace.

TESTINGOnce the hardware has

been assembled and before fit-ting IC1, check for dry joints,solder bridges and componentpolarities.

Once everything looks cor-rect, connect the power supply.Check that D5 lights and, if ameter is available, check the 5Vregulated supply. The LCD con-trast control VR1 should alterthe density of a single top rowof block characters as the LCDinitializes itself for one-linemode.

Switch off, insert IC1 andconnect a suitable lead betweenSK1 and the serial port of thePC, which has MPLAB and theICEbreaker software (see theShoptalk page) installed.

SOFTWAREINITIALISATION

Constructional Project

Display module removed from the PCB to reveal the regulatorIC mounted underneath.

www.epem

ag.co

m

Copyright © 2000 Wimborne Publishing Ltd andMaxfield & Montrose Interactive Inc

EPE Online, March 2000 - www.epemag.com - 189

Constructional Project

R14D6 R11

R12R13

PL1

D7 D8

PL2

LK1LK2

S1

RESET SK5B6 B7 0V

MCLR+5V

IC1

IC1

R7

R6

S3

S2

SK3 SK2

P1P2

P3P4

R2

R3

R4

R5TR4

TR3

TR2

TR1PL3

PL41C

23

C4e b c

e b c

e b c

e b c

X1R15

C1

C2

D5

C4

R8

R16

C3

X2

VR1

a

k

D1

D2D3

D4

akak

akak

akTR5

TR6R9

R10

D9

RLA2

SK6

SK1

NC2

NO2NC1

P1

P2

NO1RLA1

RLA2

e

eb

bc

c

COIL

D7

D6D5D4

D3D2

D1

D0E

R/WRS

RDTB

TC

a

a a

k kk

R1

IC2

INCOM.

OUT

LCD DISPLAYX3

C5

C6

LK3/4A

A

B

B

LK5

257

ICEBREAKER

9

5

6

1

SK4

(40-PIN)

(28-PIN)

SK7

14 1

POWER IN

Fig.4. Printed circuit board component layout and (approximately) full-size copper foilmaster pattern.

www.epem

ag.co

m

Copyright © 2000 Wimborne Publishing Ltd andMaxfield & Montrose Interactive Inc

EPE Online, March 2000 - www.epemag.com - 190

Run MPLAB, select the “project” tab and then“new project”. In the directory box select c:\ ice-break and set up a project named ib.prj and editthe project so that it contains the simple test pro-gram ib1.asm which is included on the ICEbreakerdisk. Close the “Project Edit” window then select“File” and ib1.asm. This will open the ib1.asm fileon the MPLAB screen.

Next select “Project” and “Make project”. Thiswill then run the MPASM program and produce

files called ib1.lst, ib1.hex, ib1.cod, and ib1.err inthe icebreak directory. The ib1.err file will contain afew warning messages, which can be ignored.

Leave MPLAB running, but minimize it by click-ing on the appropriate box. Open the icebreak fileand double click on icebreak.exe to start the pro-gram. The screen will display the main ICEbreakerwindow as shown in Fig.5, and possibly the Watchand Source windows (Figs. 7 and 8). In the main ICE-breaker window click on “Options” and then select“Programmer” this will produce the communicationsset up box shown in Fig 6. In this box set up the serialCOM port that you are using. If a 20MHz crystal isfitted the Baud box must be set to 38400. Other crys-tal frequencies can be used and the Baud rate ad-justed proportionally – e.g. a 5MHz crystal would op-erate at 38400/4 or 9600 Baud. Once set up close thebox by pressing OK.

Back in the mainbox select “File” and“Open”, which will re-veal a standard file se-lect dialog window list-ing the files in the ice-break directory. Selectand load ib1.asm andthen open the sourcecode window by select-ing ‘Window’ and then‘Source’. The windowshould contain theib1.asm source file withnumbered lines asshown in Fig.7.

Before the programcan be run it must besent to IC1 by selecting

Constructional Project

COMPONENTS

See also theSHOP TALK Page!

$60Approx. Cost Guidance Only

ResistorsR1, R6, R7 4k7 (3 off)R2 to R5 220 ohms (4 off)R8, R11 1k (2 off)R8, R10, R13 470 ohms (3 off)R12, R14 10k (2 off)R15, R16 See text

All 0.25W 5% carbon film

CapacitorsC1 to C4 10p ceramic, 2.5mm pitch (4 off), see textC5, C6 100n multilayer polyester (2 off)

SemiconductorsD1 to D4 30V 400mW Zener diodes (4 off)D5 3mm low-current red LEDD6 to D8 5.1V 400mW Zener diodes (3 off)D9 1N4001 diodeTR1 to TR6 ZTX451 npn transistors (6 off)IC1 PIC16F877P20 microcontroller, pre-programmedIC2 7805 voltage regulatorX1 (X2) 20MHz low-profile crystal (see text)X3 16x2 alphanumeric LCD module

MiscellaneousSocket strips to make up the following: 11-way (SK1); 1-way (SK2, SK3 -- 2 off); 4-way (SK4); 6-way (SK6)SK5 2.1mm PCB power connectorS1 to S3 s.p.s.t. push-to-make switches (3 off)RLA d.p.c.o. 5V coil relay (BT47)

PCB available from the EPE Online Store code 7000257(www.epemag.com); breadboard; 9-way 90o male D-typeconnector (PL1); 6-way 0.1in. pin header (PL2, PL4 -- 2 off);6-way pin strip, 2mm pitch (PL3); 2-way 0.1in. pin headerwith DP link plug (2 off -- LK1, LK2); socket strips, 20-way(4 off), 14-way (2 off), 13-way (2 off); 16-way pin-to-pin stripfor LCD; 16-way long-pin socket strip for LCD.

Hardware: 12mm M3 HEX pillars (7 off); M3 screw x 6mm(7 off); screws CSK (4 off) and 12 nuts (6BA or M2.5) forLCD mounting.

PotentiometerVR1 10k carbon preset

Layout of components on the completed EPEICEbreaker PCB.

Fig.5. Main ICEbreakerwindow.

www.epem

ag.co

m

Copyright © 2000 Wimborne Publishing Ltd andMaxfield & Montrose Interactive Inc

EPE Online, March 2000 - www.epemag.com - 191

“Program” and then “Program”in the main ICEbreaker window.A progress bar appears andICEbreaker sends the programto the first 4K of the programmemory in IC1. Once this iscompleted, it should be possibleto step, run, and reset the codeone line at a time using the“Step” button in the main win-dow. In single step mode, ateach step, a highlight line pro-gresses through the sourcecode window, and the main ICE-breaker window shows the Pro-gram Counter, the contents ofthe W register and the Statusregister bits.

Sometimes the highlightdoes not track the source codeexactly, and is one line aboveor below the current line. This isdue to the communications be-tween the computer and IC1and depends upon the waysome of the source code is writ-ten; it is only a minor inconve-nience as the actual line of codeis easily worked out from theprogram counter in the ICE-breaker main window.

Other registers may be setup in the “Watch” window – se-lect “Windows”, “Watch” in themain window. Fig.8 shows themain Watch window and Fig.9the “Add” window. Registersmay also be “Watched” by set-ting the first location and enter-ing the number of registers in

the “Array” box.The selector box in the

“Watch Add” window allows achoice of locations, labels andregisters to be selected. It is im-portant to understand that someof these options are not whatthey seem, for example the Woption returns not the value ofthe W register, but the number0 which has been assigned tothe label W in the fifth line ofthe source code.

TESTING APROGRAM

Once some familiarity hasbeen achieved with the ICE-breaker windows, it is time toconnect some hardware andsee how it operates. As with allgood microcontroller hardwaresystems, the first thing to do isflash a LED! The ib1.asm pro-gram counts up throughPORTA, which is set to outputmode, and so all that is neces-sary is to connect a LED frompin 2 of IC1 via a current limit-ing resistor (anything from100� to 2k2) to 0V.

Using solid core 1/0·6 con-necting wire links it is an easymatter to put the LED and resis-

tor on the breadboard andmake the two connectionsto the turned-pin socketstrips. The row of 13 sock-ets at the bottom of thepatch area is a good placeto find 0V. Provided theprogram has been set upcorrectly and loaded intoIC1, the LED should flashwhen the program is set to“Run”.

In order to flash theLED slowly, the programhas three nested countingloops. To single step

through them would take years,and so it is impractical to goright through all of the states ofPORTA. The alternative to sin-gle stepping is to insert a break-point and run the program tothere.

Select “Options”,“Breakpoint” from the main ICE-breaker window and set thevalue to 24. Fig.10 shows the“Breakpoint” setting window. En-tering a breakpoint highlightsthe line in the “Source” window.“Reset” and then “Run” the pro-gram and it will now stop at thebreakpoint. Press run again andit will loop again to the samebreakpoint – each time incre-menting the value at PORTA sothat the LED on PORTA 0 turnson and off alternately. Try con-necting the LED to IC1 pin 3PORTA 1 and see that itswitches every other loop.

Now that a LED can beflashed, it is just a few moresteps to controlling all sorts ofperipheral devices, and whilstthe PIC16F877 cannot run theproverbial “Power Station” it iscapable of an amazing numberof very complicated feats. Thedevelopment of longer pro-grams controlling more hard-ware is so much easier when itis possible to test the programs

Constructional Project

Fig.6. Setup box.

Fig.7. Source file window.

www.epem

ag.co

m

Copyright © 2000 Wimborne Publishing Ltd andMaxfield & Montrose Interactive Inc

EPE Online, March 2000 - www.epemag.com - 192

quickly in this way. Single step-ping and watching the programand data registers allows evencomplicated routines to betested and debugged, and sim-ple changes can be made andchecked immediately.

To make a simple changeto the ib1 program, select“Program”, “Code” from the ice-breaker main menu and thenselect location 14. The contentscan be read and should be30FF, which means MOVLWFF. Modify the value to 3010which will load the value 10 in-stead of FF and press the“Write” button. Clear the break-point, “Run” the program, andsee the change in speed.

The program in IC1 hasbeen modified, but rememberthat the Source Code has not,and so will need changing to thenew value once the requiredspeed has been set. To modifythe source code run MPLAB,modify ib1.asm, recompile thecode by selecting “Project”,“Make project” (or by pressingthe appropriate shortcut button)and then switch back to ICE-breaker .

Select “File”, “Reopen” andthe modified source code willappear in the ICEbreaker“Source” window. To completethe operation select “Program”,“Program” and the new code willbe loaded into IC1. Although theprogram in IC1 had alreadybeen modified, it is always goodpractice to reprogram with thenewly compiled code to preventsimple errors creeping in – es-pecially when a number of mod-ifications might have beenmade.

As well as changes to theprogram memory, the sameprocedure can be used to mod-ify the EEPROM, and register

files. Changing register file con-tents is particularly useful whencombined with single stepping,as it allows routines to be testedwith a range of values, for ex-ample a timing loop can be setup with 00 in the loop countingregister and single stepped tosee what happens at the end ofthe loop.

Once experience is gained,the range of tools available willbe understood, and it will be-come easy to set up and checksimple routines and combinethem into full programs.

OTHER PROGRAMSProgram ib2.asm is a sim-

ple driver for the stepping mo-

tor. Connect PORTA 0 to 3 tothe four stepping motor drivesockets P1 to P4 and then fol-low the procedures used forib1.asm to compile, load andrun the program. Notes are in-cluded in the code suggestingmodifications that can be madeto the code for altering speed,direction, and duration of travel.

Program ib3.asm runs theLCD. It uses six connectionsfrom PORTC 2 to 8 to connectto RS, E, and D4, 5, 6, and 7 ofthe display in that order. Thecode initializes the display, andthen can be set up as a subrou-tine to write any character toany display location. The sourcecode has notes to explain theoperation and to suggest possi-ble changes for more advancedapplications.

COMPLETEDPROGRAMS

Once a program has beendebugged and is working cor-rectly, it can be programmedinto another PIC16F877 or anyother suitable PIC chip using anappropriate programmer (PICToolkit Mk2 from the May andJune issues of EPE Online isideal – www.epemag.com/0599p1.htm). The ICEbreakercode does not have to be in thechip and so any blank chip canbe used with this method. TheICEbreaker board can only pro-gram chips that already containthe special icebreak code – thisis necessary because the chiphas to communicate with thePC via the standard serial portinterface. Chips with icebreakcode are readily available – seethe Shoptalk page.

Once programmed, ICE-breaker chips will run normallyin other circuits if required to do

Constructional Project

Fig.8. ICEbreaker “Watch”window.

Fig.9. ICEbreaker “WatchAdd” window.

Fig.10. ICEbreaker“Breakpoint” window.

www.epem

ag.co

m

Copyright © 2000 Wimborne Publishing Ltd andMaxfield & Montrose Interactive Inc

EPE Online, March 2000 - www.epemag.com - 193

so but it is important to makesure that the two pins RB6 andRB7 are connected to 0V. Thisis because the ICEbreaker soft-ware automatically starts to run,and immediately checks forground connections on thesepins. If it finds that they aregrounded, the program jumps tolocation 0000 and starts runningthe program from there, as anormal chip would.

THE NEXT STEPSIt is tempting to continue

and describe the many featuresof the PIC16F877, but it really isan impossible task because thechip is so powerful (see also ourPIC16F87x Mini Tutorial in theOct ’99 issue of EPE Online).The beauty of the PIC range ofdevices is that it is possible torun the same code on many dif-ferent chips.

EPE ICEbreaker allows pro-grams that are intended to berun on much simpler chips to bechecked and debugged. All thatis necessary is to ensure thatthe ports and register addressesare compatible with the smallerchips. Applications for thePIC16F84 are particularly suit-able for development using ICE-breaker, and so the programspreviously published by EPEcan be used. Note though thatthe MPLAB environment usesMPASM code, and so the PICToolkit Mk2 software will benecessary to convert the origi-nal TASM source code toMPASM assembly language.

ICEbreaker provides an ad-vanced way to learn program-ming. Along with the PIC pro-gramming and data sheets andback issues of EPE, it will be-come an indispensable tool forlearning, development, and test-ing of PIC projects.

Constructional Project

www.epem

ag.co

m