COP8SAx Designer's Guide

download COP8SAx Designer's Guide

of 254

Transcript of COP8SAx Designer's Guide

  • 8/14/2019 COP8SAx Designer's Guide

    1/254

    COP 8 MICROCONTROLLE R

    C OP 8SAx Designers G uide

    Lit era t ure Num ber 620894-001January 1997

  • 8/14/2019 COP8SAx Designer's Guide

    2/254

    ii

    REVISION RECORD

    REVISIONRELEASE

    DATESUMMARY OF CHANGES

    -001 1/97 First Relea se

  • 8/14/2019 COP8SAx Designer's Guide

    3/254

    ii i

    PREFACE

    This manual is written with the intention to serve as a Designers Guide for those whoare considering to use a microcontroller from Nationals COP8SAx family of devices.

    Chapter 1, MICROCONTROLLER BASICS, reviews microcontroller basics, including

    defi nitions, building blocks, operat ion, a pplica tions, an d progra mming. Those who a re a l-rea dy fa miliar w ith m icrocont rollers ca n skip this cha pter.

    Ch a pter 2, COP 8SAx FAMILY, provides a det a iled overview of the COP 8SAx fam ily ofdevices. It describes the feat ures, architecture, instruction set, a nd electr ica l cha ra cter-istics. For more deta iled informa tion, refer to th e COP 8 Feat ure Family U sers Man ua l.

    Ch a pter 3, DEVELOP MENT TOOLS, describes the ra nge of development t ools tha t a rea va ilable for developing and t esting a pplica tion softw a re tha t is run on th e COP 8SAx mi-crocontroller.

    Ch a pter 4, COP 8SAx AP P LIC ATION I DE AS, provides a n overview of some design exam -

    ples using t he COP 8SAx microcont roller. Within th ese exam ples, the users ca n fi nd a p-plica tion hint s th a t ma y be useful in implementing a design.

    The informa tion cont a ined in th is ma nua l is for reference only a nd is subject to chan gew ithout n otice.

    No part of this document may be reproduced in any form or by any means without theprior w ritt en consent of Na tional S emiconductor Corpora tion.

    COP8, MICROWIRE/PLUS and WATCHDOG are trademarks of National Semiconductor Corporation.

  • 8/14/2019 COP8SAx Designer's Guide

    4/254

    iv

  • 8/14/2019 COP8SAx Designer's Guide

    5/254

    CONTE NTS v

    CONTENTS

    Chapter 1 MICROCONTROLLER BASICS

    1.1 WH AT I S A M I C RO C ON TR OL L E R? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-11.1.1 CP U . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-11.1.2 P r ogr am Memor y . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-11.1.3 D at a Memor y . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-1

    1.1.4 Timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-11.1.5 Inputs/Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-11.2 WH AT D OE S A MI C ROC ON TR OL LE R RE P L AC E ? . . . . . . . . . . . . . . . 1-21.3 WH AT AR E MI C ROC ON TR OL LE R AP P L I CATI ON S ? . . . . . . . . . . . . . 1-31.4 WH AT I S TH E D IF FE RE NC E B E TWE E N A MI C ROC ONTR OL LE R

    AND A MICROP ROCE SS OR? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-61.5 WH AT I S TH E AR C H ITE C TU R E OF A MI C ROC ON TR OL LE R . . . . . . 1-6

    1.5.1 Von N eumann Ar ch itectur e . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-61.5.2 Ha r var d Ar ch itectur e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-7

    1.6 H OW D OE S A MI C ROC ON TR OL LE R OP E R ATE ? . . . . . . . . . . . . . . . . 1-71.7 D ES C RI P TI ON OF MI CR OC ONTR OL LE R B U I LD ING B L OC KS . . . . 1-9

    1.7.1 P r ogr am Memor y . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-91.7.2 D at a Memor y . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-101.7.3 Micr ocont r ol ler CP U . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-121.7.4 Timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-151.7.5 Oscil la t or C i rcu it s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-161.7.6 Ins t r uct ion Se t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-191.7.7 P r ogr amming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-20

    Chapter 2 COP8SAx7 MICROCONTROLLER

    2.1 I N TR OD U C TI ON . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-12.2 K E Y F E ATU R E S . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-1

    2.2.1 C P U F ea t u r es . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-22.2.2 P er ipher a l Fea t ur es . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-32.2.3 I/O Fea tur es . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-32.2.4 F u lly S t a t i c C M OS D es ig n . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-32.2.5 Temper a tur e Ranges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-32.2.6 D evelopment Suppor t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-3

    2.3 B L O C K D IAG R AM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-42.4 AR C H I TE C TU R E . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-42.5 P AC K AG I N G /P I N E F F I C I E NC Y . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-42.6 C ON NE C TI ON D I AG R AM S . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-5

    2.6.1 OR D E R I NG I N F OR MATI ON . . . . . . . . . . . . . . . . . . . . . . . . . . 2-7

    2.7 P I N D E S C R I P TI ON S . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-82.8 F U N C TI ON AL D E S C R I P TI ON . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-11

    2.8.1 CP U Regis ter s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-112.8.2 P r ogr am Memor y . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-122.8.3 D at a Memor y . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-122.8.4 E C O N (E P R OM C on fig ur a t ion ) R eg is t er . . . . . . . . . . . . . . . . 2-132.8.5 U s er S t or a g e S pa c e I n E P R O M . . . . . . . . . . . . . . . . . . . . . . . 2-132.8.6 OTP Secur ity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-14

  • 8/14/2019 COP8SAx Designer's Guide

    6/254

    vi C ONTE NTS

    2.8.7 Reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-152.8.8 Oscil la t or C i rcu it s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-192.8.9 Contr ol Reg is ter s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-21

    2.9 TIMERS. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-232.9.1 Timer T0 (IDLE Timer) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-232.9.2 Timer T1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-23

    2.10 TIMER CON TROL FLAGS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-272.11 P OWER SAVIN G FEATURES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-28

    2.11.1 HALT Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-28

    2.11.2 IDLE Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-292.12 MULTI-IN PU T WAK EU P . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-312.13 INTERRU P TS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-33

    2.13.1 Introduct ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-332.13.2 Maskable Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-342.13.3 VIS I ns truct ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-362.13.4 Non-ma skable Interrupt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-412.13.5 P or t L Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-422.13.6 In ter r upt Summar y . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-42

    2.14 WATCHD OG/CLOCK MONITOR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-432.14.1 Clock Monitor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-44

    2.14.2 WATCH DOG/Clock Moni tor Operat ion . . . . . . . . . . . . . . . . . 2-442.14.3 WATCHD OG a nd C lock Monitor Summar y . . . . . . . . . . . . . 2-452.14.4 Detect ion of I llegal Condi t ions . . . . . . . . . . . . . . . . . . . . . . . . 2-46

    2.15 MICROWIRE/P LUS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-472.15.1 MICROWIRE/P LUS Opera t ion . . . . . . . . . . . . . . . . . . . . . . . 2-48

    2.16 MEMORY MAP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-522.17 IN STRUCTION SET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-54

    2.17.1 Introduct ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-542.17.2 Instruct ion Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-542.17.3 Address ing Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-542.17.4 Instruct ion Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-60

    2.18 D E TAI L E D FU N C TI ON AL D E S C RI P TI ON S OF I NS TR U C TI ON S . . 2-622.18.1 ADC Add wi th Ca rry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-642.18.2 ADD Add . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-652.18.3 AND And . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-662.18.4 ANDSZ And, Skip if Zero . . . . . . . . . . . . . . . . . . . . . . . . . . 2-672.18.5 CLR Clear Accumulator . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-682.18.6 DCOR Decimal Correct . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-692.18.7 D EC D ecr ement Accumula t or . . . . . . . . . . . . . . . . . . . . . . 2-702.18.8 D R S Z R E G # D ecr em en t R eg is t er a n d S kip

    if Result is Zero . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-712.18.9 IFB IT Test B i t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-72

    2.18.10 IFB NE # I f B P ointer Not Eq ual . . . . . . . . . . . . . . . . . . . . 2-732.18.11 IFC Test i f Ca rry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-742.18.12 IFE Q Test i f Eq ua l . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-752.18.13 IFG T Test i f G reat er Tha n . . . . . . . . . . . . . . . . . . . . . . . . . 2-762.18.14 IFNC Test I f No Ca rry . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-772.18.15 IFNE Test I f Not E qua l . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-782.18.16 INC Increment Accumulat or . . . . . . . . . . . . . . . . . . . . . . . 2-792.18.17 INTR Int errupt (Softwa re Tra p) . . . . . . . . . . . . . . . . . . . . 2-80

  • 8/14/2019 COP8SAx Designer's Guide

    7/254

    C ONTE NTS vii

    2.18.18 J ID J ump Indirect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-812.18.19 J MP J ump Absolute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-822.18.20 J MPL J ump Absolute Long . . . . . . . . . . . . . . . . . . . . . . . . 2-832.18.21 J P J ump Rela t ive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-842.18.22 J SR J ump Subrout ine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-852.18.23 J SRL J ump Subrout ine Long . . . . . . . . . . . . . . . . . . . . . . . 2-862.18.24 LAID Load Accumula tor Indirect . . . . . . . . . . . . . . . . . . . 2-872.18.25 LD Loa d Accumulat or . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-882.18.26 LD Load B P ointer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-90

    2.18.27 LD Loa d Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-912.18.28 LD Loa d Register . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-922.18.29 NOP No Opera tion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-932.18.30 OR Or . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-942.18.31 P OP Pop Sta ck . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-952.18.32 P US H Push Sta ck . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-962.18.33 RB IT Reset Memory B it . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-972.18.34 RC Reset C arry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-982.18.35 RET Return from Subroutine . . . . . . . . . . . . . . . . . . . . . . . 2-992.18.36 RETI Return f rom Int errupt . . . . . . . . . . . . . . . . . . . . . . 2-1002.18.37 RETSK Return a nd Skip . . . . . . . . . . . . . . . . . . . . . . . . . 2-101

    2.18.38 RLC Rota te Accumulator Left Through Ca rry . . . . . . . . 2-1022.18.39 RP ND Reset P ending . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-1032.18.40 RRC Rota te Accumula tor Right Through Carry . . . . . . . 2-1042.18.41 SB IT Set Memory B it . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-1052.18.42 SC Set Ca rry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-1062.18.43 SUB C Subtr act w i th Ca r r y . . . . . . . . . . . . . . . . . . . . . . . 2-1072.18.44 SWAP Sw a p Nibbles of Accumulat or . . . . . . . . . . . . . . . . 2-1082.18.45 VIS Vector Interrupt Select . . . . . . . . . . . . . . . . . . . . . . . 2-1092.18.46 X Exchange Memory wi th Accumulator . . . . . . . . . . . . . 2-1102.18.47 XOR Exclusive Or . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-1122.18.48 Register an d Symbol Definit ion . . . . . . . . . . . . . . . . . . . . . . 2-113

    2.18.49 Instruct ion Set S umma ry . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-1142.18.50 Instruction Execution Time . . . . . . . . . . . . . . . . . . . . . . . . . 2-1152.18.51 Opcode Ta ble . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-117

    2.19 P R O G R AM MI N G E XAM P L E S . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-1182.19.1 Clear RAM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-1182.19.2 Bina ry/B CD Ari thmetic Operat ions . . . . . . . . . . . . . . . . . . . 2-1182.19.3 Bina ry Mult iplica t ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-1212.19.4 Bina ry Division . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-122

    2.20 ELECTRICAL CHARACTERISTICS . . . . . . . . . . . . . . . . . . . . . . . . . . 2-1252.20.1 D C E lect r ica l C ha r a c t er is t ics (0C TA + 70C unless

    oth erwise specified) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-125

    2.20.2 AC E l ect r ica l C h a r a ct er is t ics (0C TA + 70C unlessoth erwise specified) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-1272.20.3 D C E lect r i ca l Char a cteri st i cs (40 C TA + 85C unless

    oth erwise specified) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-1282.20.4 AC E lect r i ca l Char a cteri st i cs (40C TA + 85C unless

    oth erwise specified) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-130

  • 8/14/2019 COP8SAx Designer's Guide

    8/254

    viii C ONTE NTS

    2.20.5 D C E lect r ica l C ha r a c t er is t ics (40C TA + 125C unlessotherw ise specified) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-131

    2.20.6 AC E lect r i ca l Char a cteri st i cs (40C TA + 125C unlessotherw ise specified) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-133

    2.21 ESD /EMI CONSID ERATIONS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-1342.22 IN PU T P ROTECTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-1342.23 E LE C TR OMAG N E TI C I NTE R FE R ENC E (E MI )

    CONS ID E RATIONS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-1362.23.1 Introduct ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-136

    2.23.2 Emiss ion P redict ions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-1362.23.3 Board La yout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-1372.23.4 Decoupling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-1382.23.5 Output Ser ies Resista nce . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-1392.23.6 Osci lla tor Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-1392.23.7 Mechanical Shield ing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-139

    2.24 E M I RE D U C TI ON ON TH E C O P 8 S Ax7 . . . . . . . . . . . . . . . . . . . . . . . 2-1402.24.1 Si li con D esign Changes to Achieve Low E MI . . . . . . . . . . . 2-1412.24.2 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-141

    Chapter 3 DEVELOPMENT SUPPORT

    3.1 SUMMARY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-13.2 iceMASTER (IM) IN -CIRCUIT EMULATION . . . . . . . . . . . . . . . . . . . . . 3-13.3 I ceM AS TE R D E B U G M OD U L E (D M) . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-33.4 I ceM AS TE R E VAL U ATI ON P R OG R AM MI NG U N IT (E P U ) . . . . . . . . . 3-5

    3.4.1 G e tt in g S t a r t ed Wit h t h e E P U . . . . . . . . . . . . . . . . . . . . . . . . . 3-73.5 C OP 8 AS S EMB L ER /L INK ER S OF TWAR E DE VE LOP M ENT

    TOOL K IT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-83.6 C OP 8 C C OM P I L E R . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-93.7 I ND U S TR Y WI D E OTP /E P R OM P R OG R AMMI NG S U P P OR T. . . . . . 3-93.8 AVAI L AB L E L I TE R ATU R E . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-113.9 D I AL -A-H E L P E R S E R VI C E . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-11

    3.10 D IAL-A-HELP ER BB S VIA A STAN D ARD MOD EM . . . . . . . . . . . . . . 3-123.11 N ATI ON AL S E M IC O ND U C TO R ON TH E WO RL D WI D E WE B . . . . . 3-123.12 C U S TO ME R R E S P O NS E C E N TE R . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-12

    Chapter 4 COP8SAx7 APPLICATION IDEAS

    4.1 TE S TI NG A R EMOTE NOR MALL Y OP E N SWI TC H FORCONN E CTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2

    4.2 M IC R OWI R E /P L U S I N TE R F AC E . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-44.2.1 MICROWIRE/P LUS Mas ter /Slave P r otocol . . . . . . . . . . . . . . . 4-44.2.2 N M93C06-COP8SAx 7 In ter face . . . . . . . . . . . . . . . . . . . . . . . . 4-5

    4.3 TI ME R AP P L I C ATI ON S . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-104.4 TI ME R P WM AP P L I C ATI ON S . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-10

    4.4.1 Rudimentar y D -A Conver ter . . . . . . . . . . . . . . . . . . . . . . . . . . 4-104.4.2 P WM Motor Cont r ol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-104.4.3 AC Motor TRIAC Contr ol . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-124.4.4 Timer Captur e Ex ample . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-134.4.5 E xt er n a l E v en t C ou n t er E xa m p le . . . . . . . . . . . . . . . . . . . . . 4-15

    4.5 TRIAC CONTROL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-17

  • 8/14/2019 COP8SAx Designer's Guide

    9/254

    CONTE NTS ix

    4.6 E XTE R NAL P O WE R WAK E U P C I RC U I T. . . . . . . . . . . . . . . . . . . . . . . 4-204.7 B ATTE R Y-P O WE R E D WE I G H T M E AS U R E M E N T. . . . . . . . . . . . . . . 4-224.8 ZE R O C R OS S D E TE C TI ON . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-234.9 I N D U S TR I AL TI ME R . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-244.10 C OP 8 S AA7 E L E C TR ON I C K E Y AP P L I C ATI ON S . . . . . . . . . . . . . . . . 4-26

    4.10.1 Typical Appl icat ions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-274.10.2 Flexibil ity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-274.10.3 Low C ost . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-274.10.4 Sma l l Transmit ter Size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-27

    4.10.5 Low-Cost Vers ion for Rol ling Code . . . . . . . . . . . . . . . . . . . . . 4-274.10.6 Receiver Circui t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-274.11 C OP 8 S Ax7 D I R E C T L E D D I S P L AY D R I VE AP P L I C ATI ON . . . . . . . . 4-29

    4.11.1 Improved Br ightness . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-294.12 C OR D L E S S P H O N E AP P L I C ATI ON . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-32

    4.12.1 Typical Appl icat ion Requirements . . . . . . . . . . . . . . . . . . . . . 4-334.13 C OP 8 S AC 7 B AS E D AU TO MATE D S E C U R I TY/M ON I TO RI N G

    AP P LI CATIONS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-354.13.1 Typical Appl icat ion Requirements . . . . . . . . . . . . . . . . . . . . . 4-36

    4.14 COP8SAC7 K eyboar d Appl ica t ions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-384.14.1 Typical Appl icat ion Requirements . . . . . . . . . . . . . . . . . . . . . 4-39

    4.14.2 Typical Appl icat ions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-404.15 C OP 8S AA7 C L OS E D L OOP TE M P E R ATU R E CON TR OLAP P LI CATIONS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-414.15.1 P r imar y Sys tem cons ider a t ions : . . . . . . . . . . . . . . . . . . . . . . . 4-414.15.2 Typica l Requir ements for Motor Cont r ol Systems . . . . . . . . 4-42

    4.16 AUTOMATIC WASHIN G MACHIN E . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-434.16.1 Rel iab i li t y and Sa fety Fea tur es . . . . . . . . . . . . . . . . . . . . . . . 4-434.16.2 LED or LCD D isplay Uni t s . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-434.16.3 Zero Cross Detect ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-434.16.4 Other I/O Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-434.16.5 Ex ter na l EEP ROM In ter face . . . . . . . . . . . . . . . . . . . . . . . . . 4-44

    4.16.6 Sof twar e Cons ider a t ions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-454.17 AIR COND ITIONER CONTROLLER . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-47

    4.17.1 Temperature Detect ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-474.17.2 Keypad S ca nning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-484.17.3 Over-Vol tage and U nder-Vol tage Detect ion . . . . . . . . . . . . . . 4-484.17.4 D r ive C i rcu it s for Fan , Compr essor and B uzzer . . . . . . . . . . 4-48

    Appendix A PHYSICAL DIMENSIONS

    Index

  • 8/14/2019 COP8SAx Designer's Guide

    10/254

    x C ONTE NTS

    FiguresFigure 1-1 Microcontrol ler General B lock Diagra m . . . . . . . . . . . . . . . . . . . . . . . . . 1-2Figure 1-2 Microcontroller Opera tion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-8Figure 1-3 P rogram Memory Sect ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-9Figur e 1-4 Separ a te D a ta and Code Space . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-11Figure 1-5 Adding Two Numbers Using Accumulator Ba sed Machine. . . . . . . . . 1-13Figure 1-6 Adding Two Numbers Using Register Ba sed Machine . . . . . . . . . . . . 1-14Figure 1-7 Clock Generat ion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-16Figure 1-8 External Osci lla tor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-16

    Figure 1-9 R/C Oscil la tor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-16Figure 1-10 P ha se Shif t Oscillat or . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-17Figure 2-1 COP 8SAx7 Block Dia gram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4Figure 2-2 Connect ion Diagra ms. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-6Figure 2-3 P ar t Number ing Scheme . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-6Figure 2-4 I/O Por t Conf igurat ions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-9Figure 2-5 I/O Por t Conf igurat ionsOutput Mode . . . . . . . . . . . . . . . . . . . . . . . . . 2-10Figure 2-6 I/O Por t Conf igurat ionsInput Mode . . . . . . . . . . . . . . . . . . . . . . . . . . 2-11Figure 2-7 Reset Logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-15Figure 2-8 Reset Circui t Using External Reset . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-16Figure 2-9 Dddesired Reset Response Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-17

    Figure 2-10 Reset Timing (P ower-On Reset enabled) With VCC Tied t o RE S E T. . 2-18Figure 2-11 Reset C ircuit U sing Power-On Reset . . . . . . . . . . . . . . . . . . . . . . . . . . 2-18Figure 2-12 Cryst a l Oscil la tor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-19Figure 2-13 Externa l Oscillat or . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-20Figure 2-14 R/C Oscillat or . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-21Figure 2-15 Timer in P WM Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-24Figure 2-16 Timer in E xternal Event C ounter Mode . . . . . . . . . . . . . . . . . . . . . . . . 2-25Figure 2-17 Timer in Input Ca pture Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-26Figure 2-18 Wa keup From H ALT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-29Figure 2-19 Wa keup From ID LE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-30Figure 2-20 Multi-Input Wa ke Up Logic. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-31

    Figure 2-21 Keyboa rd Scan ning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-32Figure 2-22 Int errupt B lock Diagra m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-34Figure 2-23 VIS Opera tion. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-38Figure 2-24 VIS Flow Cha rt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-39Figure 2-25 MICROWIRE /P LU S Applica tion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-47Figur e 2-26 MICROWIRE/P LUS SP I Mode In ter face Timing ,

    Norma l SK Mode, SK I dle Ph a se being Low . . . . . . . . . . . . . . . . . . . . 2-50Figur e 2-27 MICROWIRE/P LUS SP I Mode In ter face Timing ,

    Alterna te S K Mode, SK Idle P ha se being Low . . . . . . . . . . . . . . . . . . . 2-50Figur e 2-28 MICROWIRE/P LUS SP I Mode In ter face Timing ,

    Alterna te S K Mode, SK I dle P ha se being H igh . . . . . . . . . . . . . . . . . . 2-51

    Figur e 2-29 MICROWIRE/P LUS SP I Mode In ter face Timing ,Norma l SK Mode, SK I dle Ph a se being H igh . . . . . . . . . . . . . . . . . . . . 2-51

    Figure 2-30 MICROWIRE /P LU S Timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-133Figure 2-31 P ort s L/C/G /F I nput P rotection (Except G 6). . . . . . . . . . . . . . . . . . . . 2-134Figure 2-32 Diode Equivalent of Input P rotection . . . . . . . . . . . . . . . . . . . . . . . . . 2-134Figure 2-33 On-Chip ES D D etection/P rotection C ircuit . . . . . . . . . . . . . . . . . . . . 2-135Figure 2-34 EMI I mprovements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-140Figure 2-35 B lock diagra m of EMI C ircuitry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-142

    http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-
  • 8/14/2019 COP8SAx Designer's Guide

    11/254

    CONTE NTS xi

    Figure 3-1 COP 8 iceMASTER E nvironment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2Figure 3-2 COP 8-DM Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-3Figure 3-3 EP U-COP 8 Tool Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-5Figure 4-1 Test Circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2Figure 4-2 Flow C har t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2Figure 4-3 MICROWIRE/P LUS Sa mple Pro tocol Timing . . . . . . . . . . . . . . . . . . . . 4-4Figure 4-4 NM93C06-COP 8SAx7 Int erfa ce . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-5Figure 4-5 Timer PWM Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-10Figure 4-6 P WM Motor Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-12

    Figure 4-7 Timer Capture Applica tion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-14Figure 4-8 P ower Wakeup Using An NPN Transis tor . . . . . . . . . . . . . . . . . . . . . . 4-20Figure 4-9 P ower Wakeup Using Diodes And Resistors . . . . . . . . . . . . . . . . . . . . 4-21Figure 4-10 B a tt ery-powered Weight Measurement . . . . . . . . . . . . . . . . . . . . . . . . 4-22Figure 4-11 Industr ia l Timer Application. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-24Figure 4-12 Tra nsmitt er in Single Cell Operat ion . . . . . . . . . . . . . . . . . . . . . . . . . . 4-26Figure 4-13 Rol ling Code IR Transmit ter Using External EE P ROM . . . . . . . . . . . 4-28Figure 4-14 Rolling Code IR/RF Tra nsmitter U sing One-Chip EEP ROM . . . . . . . 4-28Figure 4-15 LED Direct Dr ive U sing COP8SAx7. . . . . . . . . . . . . . . . . . . . . . . . . . . 4-29Figure 4-16 LED Drive. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-30Figure 4-17 Four-Wa y Multiplexed Direct LE D D rive. . . . . . . . . . . . . . . . . . . . . . . 4-31

    Figure 4-18 Ha ndset B lock Diagra m. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-32Figure 4-19 B a se Block Diagra m. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-33Figure 4-20 Exa mple of a S ecurity/Monitor ing Syst em . . . . . . . . . . . . . . . . . . . . . . 4-35Figure 4-21 La ptop/Notebook Keyboa rd Schemat ics . . . . . . . . . . . . . . . . . . . . . . . . 4-38Figure 4-22 Automotive Closed Loop Air Control . . . . . . . . . . . . . . . . . . . . . . . . . . 4-42Figure 4-23 Automat ic Wa shing Machine Control Model U sing COP8SAC7. . . . . 4-44Figure 4-24 Main P rogra m Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-45Figure 4-25 Int errupt Routine Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-46Figure 4-26 B lock Diagra m of Air Conditioning Control Module . . . . . . . . . . . . . . 4-47Figure 4-27 Tempera ture Detection Circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-48Figure 4-28 Keypad Sca nning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-49

    Figure 4-29 Over-Volta ge and U nder-Volta ge Detection Circuit . . . . . . . . . . . . . . 4-49Figure 4-30 Drives Circuits for Fa n, Compressor a nd B uzzer . . . . . . . . . . . . . . . . . 4-50

    TablesTable 1-1 Microcontrol ler Fea tures/Appl ica t ions Matr ix . . . . . . . . . . . . . . . . . . . . 1-4Table 2-1 P rogram/Da ta Memory Sizes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-12Table 2-2 Osci lla tor Option . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-19Ta ble 2-3 C ry st a l Oscilla t or C on fig ur a t ion , TA= 25C, VCC = 5V . . . . . . . . . . . . 2-19Ta b le 2-4 R /C O s cilla t or C on fig ur a t i on , -40 C t o + 85 C , VCC = 4.5V t o 5.5V,

    O S C F r eq Va r ia t i on of 35%. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-20

    Table 2-5 Interrupt Vector Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-37Table 2-6 WATCHD OG S ervice Regis ter (WDSVR). . . . . . . . . . . . . . . . . . . . . . . 2-43Table 2-7 WATCHD OG S ervice Window S elect . . . . . . . . . . . . . . . . . . . . . . . . . . 2-44Table 2-8 WATCHD OG S ervice Act ions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-45Table 2-9 MICROWIRE/P LUS Mas ter Mode C lock Select . . . . . . . . . . . . . . . . . 2-48Table 2-10 MICROWIRE/P LUS Mode Set t ings . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-49Table 2-11 MICROWIRE/P LUS S hi ft Clock Polar i ty and Sample/Shi f t Pha se . . 2-50Ta ble 2-12 Electr ic Field Ca lculat ion Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-137

    http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-http://-/?-
  • 8/14/2019 COP8SAx Designer's Guide

    12/254

    xii C ONTE NTS

  • 8/14/2019 COP8SAx Designer's Guide

    13/254

    MI CROC ONTROLLE R B AS IC S 1-1

    Chapter 1

    MICROCONTROLLER BASICS

    1.1 WHAT IS A MICROCONTROLLER?

    Microcontroller is an highly integrated single-chip microcomputer. Some of the keyelement s of a m icrocont roller include a CP U to process informa tion, progra m m emory t ostore instructions, dat a memory to store informa tion, system t iming, an d input/out putsections to commu nicat e wit h t he out side world.

    1.1.1 CPU

    Central Processing Unit (CPU) is the heart of a microcontroller where all of thearithmetic and logical operations are performed. This is the calculator part of themicrocont roller. The C P U gets progra m instr uctions from t he program memory.

    1.1.2 Program Memory

    P rogram Memory conta ins a set of CPU instructions organized into a part icular sequenceto do a par ticular t a sk. P rogram Memory is referred to a s Read On ly Memory (ROM) orOTP /E P ROM. OTP or One-Time P rogra mm a ble ca n be progra mm ed only once a nd t heprogram is stored permanently, even when the microcontroller power is turned off.P rogram memory enables the microcont roller to immedia tely begin run ning its programa s soon a s it is turn ed on.

    1.1.3 Data MemoryA form of memory t ha t ca n be both read a nd w rit ten is required for t he progra m st a ck,data storage, and program variables. This type of memory is commonly referred to asRa ndom Access Memory (RAM). Ea ch memory locat ion ha s a unique a ddress w hich t heCP U uses to fi nd the informa tion i t needs.

    A ty pica l microcont roller cont a ins both R OM a nd R AM ty pe memory.

    1.1.4 Timing

    Microcontrollers use a timing signal, called a clock, to provide a timing reference forprogram execution, and to determine when data should be written to or read frommem ory. It a lso provides timing for on-boar d periphera ls.

    1.1.5 Inputs/Outputs

    Microcontrollers require int erface sections t o comm unicat e w ith externa l circuitry. Inputports allow data and status conditions to be read into the microcontroller while the

  • 8/14/2019 COP8SAx Designer's Guide

    14/254

    1-2 MI CROC ONTROL LE R B AS IC S

    output ports allow the microcontroller to affect external logic systems. The interfacesbetween the microcontroller and the outside world vary with the application, and mayinclude display units, keypa ds, swit ches, sensors, relays, motors, a nd so on.

    1.2 WHAT DOES A MICROCONTROLLER REPLACE?

    A microcontr oller can do the w ork of ma ny different ty pes of logic circuits. D iscrete logiccircuits a re perma nently w ired to perform t he function t hey w ere designed to do. If th edesign requirements a re cha nged slightly, an ent ire print ed circuit board or ma ny boardsmay have to be redesigned to accommodate the change. With a microcontroller

    performing t he logic functions, most chan ges ca n be ma de simply by reprogra mming th emicrocontroller. That is, the software (program) is changed rather than the hardware(logic circuits). This makes the microcontroller a very attractive building block in anydigital system. With a microcontroller-based design, the designer can simply add afeat ure set to th e product w ith minima l softw a re/ha rdw a re cha nges.

    Microcontrollers can also be used to replace analog circuitry. Special interface circuitscan be used to ena ble a microcont roller to input a nd output a na log signa ls.

    There are also situations where the designer considers using an ASIC (Application-Specific Integrated Circuit) as logic replacement for control applications.

    Microcont rollers ca n effi cient ly be used as sing le-chip repla cements in su ch applicat ionswith signifi ca ntly lower development cost a nd fa st t ime to market.

    One of th e great benefit s of the electronic revolution is tha t it brought intelligence, a ndw ith it a da pta bility, to tra ditional electro-mecha nical devices. B y cont inuously ga th eringinformation on the performance of the device, its operating environment, and otherfa ctors, microcont roller int elligence ca n determine a new a nd proper stra tegy a nd t hencommand the surrounding device to react. The most important of these are the new

    Figure 1-1 Microcontroller G eneral B lock Diagr a m

    ProgramMemory

    CPU

    DataMemory

    Timing

    I/O

  • 8/14/2019 COP8SAx Designer's Guide

    15/254

    MI CROC ONTROLLE R B AS IC S 1-3

    intelligent applications which are adapted in real time to changing conditions, such asthe iron th a t senses when the cloth benea th i t ha s reached the proper temperat ure andmoisture, or t he vacuum cleaner t ha t a djusts i ts speed a nd brush height a utomat ica l lyto cha nges in ca rpet na p.

    1.3 WHAT ARE MICROCONTROLLER APPLICATIONS?

    Microcontrollers a pplica tions a re more or less limited only by th e user ima gina tion. So

    pervasive has been this technological revolution that we barely notice it anymore.Microcontrollers now reside in our televisions, keyboards, modems, printers,w ristw a tches, telephones, ca rs, household a pplian ces, an d every oth er part of home andwork life. The market for microcontrollers continues to expand rapidly, encompassing aw ide ran ge of consum er, indust ria l, au tomotive, a nd t elecommu nicat ions a pplica tions. Infa ct, a t ypical home toda y cont a ins over 35 microcontr oller-ba sed products a fi gure tha tsome sources estima t e could grow t o a lmost 250 by t he yea r 2000.

    The emergence of new low cost microcontrollers offers a wealth of benefits for today'sconsumer a pplica tions an d represent a n entirely new profit source for ma nufa cturers. Inthe past, the high cost of electronics limited the use of microcontrollers to "high tech"

    applications such as televideo recorders, stereo systems, and high-end durable goodssuch a s wa shing m a chines. Toda y, th e applica tion base ha s broadened t o include systemssuch as coffee machines, irons, shavers, and cleaners, where the introduction ofelectronics helps to provide product differentiation and allows the inclusion safetyfeatures.

  • 8/14/2019 COP8SAx Designer's Guide

    16/254

    1-4 MI CROC ONTROL LE R B AS IC S

    Table 1-1 Microcont roller Fea tu res/Applica tions Ma t rix (Sheet 1 of 3)

    Market Segment ApplicationsApplications

    Features/FunctionsMicrocontroller

    Features Required

    C on su mer C hild ren

    Toys and

    Ga m es

    B asketba ll/B aseba ll

    Ga m es

    Children Electronic

    Toys

    D a r t s

    Throws

    J uke Box

    P inba l l

    Laser Gun

    Ba t tery Dr iven

    Replacing Discrete wit h

    Low Cost

    Driving

    P iezo/Spe a ker/LE D s

    Directly

    Very Cost S ensitive

    Very Low P rice

    Low Power C onsumption

    Wide Voltage Range

    High-Current Outputs

    Small Packages

    Electronic

    Audio It ems

    Audio Greet ing Ca rds

    Electronic Musical

    Equipment

    Ba t tery Dr iven

    Tone Gener at ion

    Low Power

    Wide Voltage Range

    Low Power C onsumption

    Effi cient Table Lookup

    Flexible Timer

    Electronic

    Appliances

    a nd Tools

    Sm all Appliances:

    Irons

    Coffee Makers

    Digita l Scales

    Microwa ve Ovens

    CookersFood P rocessors

    Blenders

    Low Cost Power S upply

    Temp Measu remen t

    Sa fety Features

    Noise Immunity

    Driving

    LE Ds/Rela ys/Hea tin gElements

    Brown Out D etect ion

    On-Board Comparator

    High-Current Outputs

    Wa tchdog/Soft wa re

    Interrupt

    Schmitt Trigger Inputs16-B it P WM Timer

    Household Appliances:

    Oven Control

    Dishwasher

    Was hing Ma chine/Dr yer

    Vacuum C leaner

    Electronic Heater

    Electronic Home

    Control (Doorbell,

    Light Dimmer,

    Climate)

    Sewing Ma chine

    Rely on H ar d-Wire Relay

    Circuits, Timers,

    Counters, Mecha nical

    Sequence Contr ollers

    Temp Cont rol

    Noise Immunity

    Sa fety Features

    Timing Control

    Main D riven

    Brown Out D etect ion

    On-Board Comparator

    On -B oa rd A/D

    Wa tchdog/Soft In terr upt

    Schmitt Trigger Inputs

    Flexible Timers

    P WM Outputs

    High-Current Outputs

    Sa fety Features

    Portable,

    Handheld,

    B a t t e r y

    Powered

    Scales

    Multimeters (porta ble)

    Electronic Key

    La ptop/Not ebook

    Keyboard

    Mouse

    G ara ge Door Opener

    TV/E lectr onic Rem ote

    Control

    Portable or Reta il

    Point-Of-Sale Device

    J ogging Monitor

    Sm a r t C a r ds

    Ba t tery Dr iven

    Minimal Power

    Consumption

    Low Voltage

    Sensing

    Measurement

    Sta ndby Mode

    Flexible Package

    Offerings

    Sma ll Physical Size

    Low Volta ge Operat ion

    Low Power C onsumption

    Wide Voltage Range

    Power S aving Modes

    Multi-Input Wakeup

    On-Board Comparator

    Small Packages

  • 8/14/2019 COP8SAx Designer's Guide

    17/254

    MI CROC ONTROLLE R B AS IC S 1-5

    P ers on a l C om m u nica t ion s C or d less P h o ne

    (base/ha ndset )

    P hone Dialer

    Answering Machine

    Feature Phone

    P B X C a r d

    CB Rad ios/Digita l

    TunersCable Converter

    Low Power

    Timing

    Seria l In terfaces

    Low Voltage

    Tone Dia ling

    Ba t tery Saving Funct ions

    Sma ll Physical Size

    Low Current Drain

    Low Volta ge Operat ion

    Sta ndby Mode

    UART

    Serial Synchronous

    Interface

    16-Bit Timers

    Schmitt Trigger InputsLED Direct Dr ive

    Suffi cient I/O in S ma ll

    Packages

    Medica l Monit ors Thermomet er

    Pressure Monitors

    Var ious Portable

    Monitors

    Ba t tery Dr iven

    Sen sing/Mea surem ent

    Da ta Transmission

    Low Power

    Low Voltage

    On-B oard C ompara tor (low

    cost A/D )

    16-Bit Timer

    Low Power C onsumption

    Low Volta ge Operat ion

    Medical

    Equipment

    B ed-side Pu mp/Timer s

    U ltrasonic Ima ging

    System

    Ana lyzers (chemical,da t a )

    Elect ronic Microscopes

    Monitoring D at a

    Da ta Transmission

    Timing

    Seria l Interface

    A/D

    16-Bit Timers

    I ndust ria l Mot ion

    Control

    Motor Control

    Power Tools

    Motor S peed Control

    Noisy Environment

    Timing Control

    Flexible P WM Timers

    Schmitt Trigger Inputs

    High-Current Outputs

    Security/

    Monitoring

    System

    Security S ystems

    Burglar Alarms

    Remote Dat a

    Monitoring Systems

    Emergency Control

    Systems

    Security Sw itches

    Da ta Transmission

    Monitoring (scan input s

    from sensors)

    Keypad Scan

    Timing

    Diagnost ic

    Da ta Monitoring

    Drive Alarm Sounders

    Interface to Phone

    System

    Sta ndby Mode

    UART

    Flexible 16-B it P WM

    Timers

    Fl exib le I /O

    Sin gle St op A/D Ca pab ility

    Power S aving Modes

    (HALT, Mult i-In put

    wakeup)

    Serial Synchronous

    Interface

    Misc. S w it ch C ont rols

    (elevat or, tr affi c,

    power sw itches)

    Sensing Control

    Sy stem s/Displa ys

    P ressure C ontrol

    (scales)

    Metering (utility,

    monetary, industrial)

    La wn S prinkler/La wnMowers

    Ta xi Met er

    Coin Controls

    Industrial Timers

    Temperat ure Meters

    G a s P u m p

    G a s/Sm oke Det ectors

    Timi ng /Cou nt ing

    Sensing

    Measurement

    Generic Microcontroller

    Table 1-1 Microcont roller Fea tu res/Applica tions Ma t rix (Sheet 2 of 3)

    Market Segment ApplicationsApplications

    Features/FunctionsMicrocontroller

    Features Required

  • 8/14/2019 COP8SAx Designer's Guide

    18/254

    1-6 MI CROC ONTROL LE R B AS IC S

    1.4 WHAT IS THE DIFFERENCE BETWEEN A MICROCONTROLLER AND AMICROPROCESSOR?

    The broad category of microcomputers is divide into two areas: microcontrollers andmicroprocessors. This distinction is made because these are really two different types ofdevices. Microcontrollers genera lly have a dua l-bus a rchitectu re ra th er tha n t he memorymapped von Neumann architecture common in most microprocessors. For controla pplica tions, microcont rollers a re genera lly more memory efficient th a n microprocessors.The m icrocont roller instru ction set is quit e different in n a tu re t ha n t he microprocessorinstruction set. Microcontrollers are invariably single-chip devices and microprocessorsare, generally, multi-chip devices. Microcontrollers dominate the microcomputerma rketpla ce in t erms of volume. To be sure, th e division betw een microcontr oller a ndmicroprocessor is sometimes blurred but the distinction is real nonetheless.

    1.5 WHAT IS THE ARCHITECTURE OF A MICROCONTROLLER

    Microcontrollers ha ve tw o types of a rchitectu re: Von Neuma nn or H a rva rd.

    1.5.1 Von Neumann Architecture

    The Von Neuma nn a rchitectur e wa s na med a fter J ohn Von Neuma nn, a n ear ly pioneerin the computer field at Pr inceton. In this architecture, a CPU and memory areinterconnected by a common a ddress bus an d da ta bus. Positive a spects of this approachinclude convenient a ccess to ta bles stored in progra m m emory (ROM or OTP /E P ROM)a nd a more ort hogona l instruction set. The a ddress bus is used to identify w hich memorylocat ion is being accessed, while the da ta bus is used to tra nsfer informa tion eith er fromthe CPU to the selected memory location or vice versa. Von Neumann was the first torealize that his architecture model could have the memory serve as either programmemory or da ta memory. I n earlier computers (both electronic a nd electromecha nical),th e program store (often a progra m pa tchboa rd) ha d been completely separ a te from theda ta store (often a ba nk of vacuum t ubes or relays).

    Aut omot ive Ra dio/Ta pe D eck

    Controls

    Window, Sea t, Mir ror,

    an d Door Contr ols

    Climate Controls

    H ead light /Antenna

    Power St eering

    Anti TheftSlave Controllers

    Timing

    Motion Control

    Display Control

    Soft Runa wa y/Tra p

    Recovery (safety

    considerations)

    EMI /Noise Immu nit y

    Seria l In terfacesSta ndby Modes

    Wide Temp R a nge

    Flexible P WM Timers

    Power S aving Modes

    Multi-Input Wakeup

    WATCH DOG Softwa re

    Trap

    UART

    CAN Interface

    Special Featur es forDashboard

    Control (counters, ca pture

    modules, MU L/DI V)

    Reduced EMI

    Wide Temp R a nge

    Table 1-1 Microcont roller Fea tu res/Applica tions Ma t rix (Sheet 3 of 3)

    Market Segment ApplicationsApplications

    Features/FunctionsMicrocontroller

    Features Required

  • 8/14/2019 COP8SAx Designer's Guide

    19/254

    MI CROC ONTROLLE R B AS IC S 1-7

    The single a ddress bus of the Von Neuma nn a rchitectu re is used sequent ially t o accessinstr uctions from program m emory a nd t hen execute the instructions by retrieving da tafrom a nd/or storing da ta to the da ta memory. This mea ns th a t a n instr uction fetch ca nnotoverlap a da ta a ccess from m emory.

    The obvious advantage of a Von Neumann architecture is the single address bus andsingle data bus l inking memory with the CPU. A drawback is that code can beinadvertently executed from data memory, opening up the possibility for undesiredoperat ion due t o corrupt ion of t he program count er or other registers.

    1.5.2 Harvard Architecture

    The Harvard architecture was named af ter the Harvard Mark 1 and the ear lyelectromecha nical comput ers developed at H a rva rd by H owa rd Aiken, a nother computerpioneer . This architecture has separate program memory and data memory with asepa ra te a ddress bus a nd da ta bus for each memory. One of the benefi ts of the Ha rvarda rchitectur e is th a t th e operat ion of th e microcont roller can be cont rolled more ea sily inthe event of corrupted program counter. A modified (enhanced) Harvard architecturea llow s a ccessing da ta ta bles from program memory. This is very importa nt w ith m odernda y microcomputer s, since t he progra m mem ory is usua lly ROM or OTP /E P ROM) w hile

    the data memory is RAM. Consequently, data tables usually need to be in programmemory so tha t t hey a re not lost w hen t he microcont roller is pow ered dow n.

    The adva nta ge of a modified H a rvard a rchitecture is tha t instruction fetch a nd memorydata transfers can be overlapped with a two stage pipeline, which means the nextinstr uction ca n be fetched from progra m m emory w hile the current inst ruction is beingexecuted using data memory. A drawback is that special instructions are required toa ccess RAM a nd R OM (or OTP /EP ROM) da ta va lues, ma king program ming m oredifficult .

    1.6 HOW DOES A MICROCONTROLLER OPERATE?

    The CP U can r equest informa tion from memory (or rea d a n input port) by ca lling it byits memory a ddress. The a ddress with a l l its bi ts is s tored in the C P U a s binary numberin a temporary da ta lat ch type memory called a register. The output s of the register a resent over mu ltiple wires (or single wire) to th e microcont roller memory a nd periphera ls.The group of w ires (par a llel) or t he single w ire (serial) tha t carries t he a ddress is calledth e addr ess bus. The word bus refers t o one or more wires tha t sh a re a common pa thto/from mu ltiple places. The a ddress regist er holds a ddr ess bits. The nu mber of a ddressbits d epends on the microcontr oller ty pe.

    Da ta is sent t o the CP U over a da ta bus. The dat a bus is dif ferent from t he address busin that the CPU uses i t to read information from memory or peripherals and to writeinformation to memory or peripherals. Signals on the address bus originate only at theCP U a nd a re sent t o the other blocks at ta ched to the bus. Signa ls on th e data bus ca neither be inputs to the CP U or output s from t he CP U. The informa tion on th e dat a bus issent or received at the CPU by the data register . In other words, the data bus is bi-directiona l an d th e addr ess bus is uni-directiona l. The widt h of th e add ress an d th e dat abus ma y a lso be different, depending on t he microcont roller type a nd m emory size.

  • 8/14/2019 COP8SAx Designer's Guide

    20/254

    1-8 MI CROC ONTROL LE R B AS IC S

    Figure 1-2 Microcont roller Opera t ion

    Address Bus

    Data Bus

    ProgramMemory

    Address Register

    DataMemory

    CPU

    I/O

    Data Register

  • 8/14/2019 COP8SAx Designer's Guide

    21/254

  • 8/14/2019 COP8SAx Designer's Guide

    22/254

  • 8/14/2019 COP8SAx Designer's Guide

    23/254

    M IC R OC O NTR OL LE R B AS I C S 1-11

    data memory. The data pointer (PTR) is loaded with the address of a byte of data in

    memory. To access the byt e of da ta , th e pointer ca n be used inst ead of using t he a ddressitself (LD A, [P TR]). This is pa rt icular ly useful w hen consecut ive locat ions a re a ccessed.The data pointer can be incremented automatically after each access instead ofspecifying the a ddress each t ime.

    Stack

    The sta ck is a section of memory used to store da ta a nd a ddress va lues. St a cks operat ein a LIFO (last in first out) manner. A stack pointer is used to address the stack. Thestack pointer is a register used to keep the address of the last piece of data put on thesta ck. Usua lly the sta ck pointer is initialized to a n a ddress in memory. As da ta is put on

    the stack, the stack pointer moves up or down in memory. The microcontroller uses thestack to store return addresses during subroutine calls and interrupts. Somemicrocontrollers also store status information on the stack before responding tointerrupts. The application program can use the stack to store data temporarily,especia lly dat a to be pa ssed between subroutines. Not a ll sta cks a re user a ccessible.

    Examples:

    1. St a ck opera tion a s a result of executing J ump-to-Subroutine (J SR), or P U SHinstructions.

    Figure 1-4 Separa te Dat a a nd Code Space

    Internal Data Bus

    MemoryAddressRegister

    DataMemory

    CPURegisters

    MemoryData

    Register

    A

    MUX

    MUX

    ALU

    Stack Pointer Empty

    Empty

    Empty Stack Pointer

    Return Address Low

    Return Address High

    Empty

    Before After

    Stack Stack

  • 8/14/2019 COP8SAx Designer's Guide

    24/254

    1-12 MI C ROC ON TR OL LE R B AS I CS

    2. St a ck operat ion a s, a result of executing Retur n-from-Su brout ine (RE T) orP OP instructions.

    1.7.3 Microcontroller CPU

    The key fu nct ion of a C P U is t o perform ins t ru ction fet ch/decode/execute.

    Fet ch Th e pr og ra m cou nt er (P C ) a d dr es ses a l oca t i on in pr og ra m m em or y con -ta ining a n inst ruction. This instru ction is lat ched into a specia l instruc-tion register (IR). The P C is incremented t o point to th e next a va ilableinstruction.

    D ecode The ins t r uct ion in the IR is decoded . The b it s of the ins t r uct ion r el a te tospecifi c actions. Ea ch bit or group of bits is used t o determine t he a ppro-

    priat e control signa ls to a ctivat e in order t o ca use th e execut ion of theinstruction.

    Execute The control signals go out to a l l par t s of the microcontrol ler, causing thedesired action to ta ke pla ce.

    Arithmetic Logic Unit (ALU)

    The arithmetic logic unit is a binary adder. It performs all the arithmetic and logicfunctions in the microcontroller. The destination for all such operations is theAccumulator (A). The two inputs to an operation are the accumulator and either an

    immediate data as specified by an instruction or, more commonly, the contents of datamemory loca tions. The one-bit ca rry register (C register) sometimes is a th ird input toth e ALU.

    Status/Control Registers

    The st a tu s a nd control registers a re special-purpose registers used t o store the st a te ofth e microcont roller. The cont rol bits a re ma nipulat ed by t he user progra m t o place th emicrocontroller and its peripherals in particular states. The status bits are read by thea pplica tion progra m to inform m icrocont roller/user of t he curr ent st a te. Exa mplesinclude:

    1. A ca rry bit , which indica tes whether the last opera tion performed by the ALUgenera ted a carry.

    2. Int errupt ena ble bit , which tel ls the microcontroller whether an interrupt isenabled.

    3. Interrupt pending bi t , which te l ls the program whether a par t icular in ter ruptoccurred.

    Stack Pointer

    Stack PointerReturn Address Low

    Return Address High

    Empty

    Before After

    Stack Stack

    Empty

    Empty

    Empty

  • 8/14/2019 COP8SAx Designer's Guide

    25/254

    M IC R OC O NTR OL LE R B AS I C S 1-13

    4. H ALT bit, wh ich tells microcont roller to stop all activities.

    5. Timer run, which t ells microcontroller to star t t he t imer.

    Accumulator vs Register

    An accumulator-based microcontroller operates in a manner different from a register-ba sed m icrocont roller. The difference is due t o the d ifferent ALU a rchitectu res. The m ostcommon a re:

    1. S ta ck based: a no addr ess machine

    2. Accumulat or ba sed: a one-address machine

    3. Register ba sed: a t wo- or three-a ddress ma chine

    Another difference is due to the difference between the microcontroller architectures interm s of w here numbers m ust be locat ed in order for t hem t o be operat ed on by t he ALUof th e m icrocont rollers.

    Exa mple: Adding tw o numbers

    Adding tw o num bers in a n a ccumula tor-ba sed ma chine requires tha t one of the numbers

    be located in the accumulator and the other one in data memory. The result of thea ddition is pla ced ba ck in th e accumulat or.

    A register-ba sed ma chine does not req uire tha t a ny of the a ddends be in the a ccumula tor.Inst ead , the t w o num bers ma y be in registers in memory. The result ma y be specifi ed tobe placed in one of the registers being used in the addition, a third register, or theaccumulator.

    Wha t's the difference? Is one method better t ha n a nother?

    Accumulator based machines require one of the operands to be located in theAccum ula t or. Therefore, only one opera nd loca tion mu st be specifi ed in inst ruct ions.

    Register based machines do not require the operands to be in a particular location.Therefore, th e locat ion of both opera nds m ust be specifi ed in inst ruct ions.

    The decoding of register-based instructions and the fetching of operands generallyrequires more time tha n w ould be required to execut e an a ccumula tor-ba sed instruction.

    Figure 1-5 Adding Tw o Numbers Using Accumulat or Ba sed Ma chine

    DataMemory

    Memory DataRegister

    ALU

    Accumulator

    Addend #2

    Addend #1

  • 8/14/2019 COP8SAx Designer's Guide

    26/254

    1-14 MI C ROC ON TR OL LE R B AS I CS

    However, the accumulator-based machine requires operands to be moved into thea ccumula tor before instr uctions a re executed. Which ta kes longer in t he end? It dependson how much faster an accumulator-based machine can execute an instruction than aregister-ba sed ma chine.

    Trade-off memory efficiencyAn accumulator-based machine will generally haveshorter opcodes th a n a register-ba sed ma chine.

    Interrupts

    Interrupt is an event which causes the microcontroller to stop executing code in itsnorma l sequence an d inst ea d respond to the occurrence of th e event . The microcontr oller

    performs t he follow ing st eps when a n int errupt occurs:

    1. Stops execut ion o f the "next " instruct ion.

    2. D isab les a dd it iona l in ter r upts .

    3. Sa ves current sta tus of the microcontroller.

    4. J umps to a specia l in ter rupt ha ndling rout ine.

    5. Returns from t he specia l in ter rupt ha ndling rout ine.

    6. Restores sta te of the microcontroller

    7. E n a b les in t er ru pt s

    8. Executes the "next " ins truct ion.

    Figure 1-6 Adding Tw o Numbers U sing Register B a sed Machine

    Register 1

    Addent #2

    Addent #1

    Register 2

    Register 3

    A

    ALU

  • 8/14/2019 COP8SAx Designer's Guide

    27/254

    M IC R OC O NTR OL LE R B AS I C S 1-15

    Int errupt Types

    1.7.4 Timing

    The microcontr oller uses th e instr uction cycle time a s a n int erna l timin g reference. Theinstruction cycle time is the amount of time it takes for an instruction to be fetched,decoded, a nd executed. The inst ruct ion cycle time differs for va rious microcontr ollers. Ita lso differs for va rious inst ructions. Microcont roller ma nufa cturers specify a minimuminstruction cycle time. For example, for the COP8SAC7, the instruction cycle time t c =

    1 S. This means that the fastest instructions are executed in 1 S w i th themicrocontroller operating at the maximum frequency. Slower instructions usually takesome mult iple of t he ins t ruction cycle clock.

    The instruction cycle time is usually a division of the input clock frequency to themicrocontroller. For exa mple, divide by 10 is one possible factor. This m ea ns a 10 MH zinput clock must be provided to genera te a 1 S ins tr uction cycle time (1 MH z inst ruct ioncycle clock). The m inimu m in st ruct ion cycle tim e ma y be severa l inst ruct ion cycle clocksor only one inst ruct ion cycle clock, dependin g on t he m icrocont roller. Lim itin g fa ctors oninstr uction cycle time a re:

    1. Memory access t ime (memory speed)

    2. Number of bytes per ins truct ion

    3. Wid t h of d a t a b u s

    4. Level of decoding required of instructions

    5. E x ecu t ion t i me

    E xt erna l In t errupt Int errupt s w hich a re genera ted by device/event soutside of the m icrocont roller. An extern a l int er-rupt ca n be lat ched or edge triggered.

    Int erna l In t errupt s Int errupt s w hich a re genera ted by ha rdw a rew ithin th e microcont roller in response t o certa inevent s, such a s timer overflow or underfl ow.

    S oft w a re Tra ps Int errupt s ca used by execut ing a pa rt icula rinstruction. S uch a n instruction m ay be a specialinstr uction designed t o ca use a tra p (INTR) or ma ybe the result of a n error in executing a norma linstruction.

    Ma skable vs. Non-Ma ska bleInterrupts

    Non-Ma skable interrupts a re those interrupt swh ich cannot be disa bled by th e softwa re andth erefore ca nnot be ignored, such a s th e Reset a ndSoftw a re Tra p int errupts. Maska ble interrupt s, onthe other han d, ma y be disa bled by th e softwa re,such a s t imer overfl ow /underfl ow interrupt s..

    En a bling and disa bling is generally accomplishedby sett ing/resetting a n ena ble bit.

  • 8/14/2019 COP8SAx Designer's Guide

    28/254

    1-16 MI C ROC ON TR OL LE R B AS I CS

    1.7.5 Oscillator Circuits

    Typically there are three types of clock oscillator options available: external oscillator,R/C oscilla t or, or cryst a l oscilla t or.

    External Oscillator

    An external square wave clock source is generated outside and presented to themicrocontroller clock input pin. The clock source mu st meet t he specified dut y cycle, rise

    a nd fa ll times, and input level.

    R/C Oscillator

    The R /C (resis t or/ca pa citor) oscilla t or req uir es t he u se of exter na l R/C componen t s or R /Cintegrated on-chip. The oscillator frequency is a function of the resistance andcapacitance values.

    Crystal Oscillator

    The phase shift oscillator referred to as the Pierce Oscillator has many desirablecha ra cter ist ics . I t provides a large output signa l an d drives the crysta l at a low powerlevel. The low power level lea ds t o low pow er dissipat ion, especia lly a t h igher frequen cies.

    Figure 1-7 Clock G enerat ion

    Figure 1-8 External Oscillator

    Figure 1-9 R/C Oscilla t or

    Clock Generator Divider

    External Clock Circuitry

    Instruction Cycle Frequency

    Clock Input

    Clock InputVCC

    R

    C

    or Clock input pin open for internal R/C

  • 8/14/2019 COP8SAx Designer's Guide

    29/254

    M IC R OC O NTR OL LE R B AS I C S 1-17

    The circuit has good short-term stability, good waveforms at the crystal, a frequencyw hich is independent of pow er supply a nd t empera tur e cha nges, low cost a nd usa ble a ta ny frequency. As compa red w ith oth er oscilla tor circuits, t his circuit is not disturbedvery much by connecting a scope probe a t a ny point in th e circuit, because it is a sta blecircuit and has low impedance. This makes it easier to monitor the circuit without anyma jor distur ba nce. The P ierce oscillat or ha s one disadva nt a ge. The a mplifier used in t hecircuit must have high gain to compensate for gain losses in the circuitry surroundingthe crysta l .

    Figure 1-10shows t he cla ssic pha se shift oscilla tor found not only on the C OP 8SAx7 but

    on most oth er microcontr oller circuits. I t is t he simplest oscilla tor in t erms of componentcomplexity.

    The P ierce is a s eries resona nt circuit . For oscillat ion t o occur, tw o criteria mu st be met :

    1. The loop gain must be grea ter tha n one.

    2. The pha se shif t around the loop must be 360

    The a mplifier (intergra ted on-chip) provides the d esired ga in a nd th e 180 pha se shift.The external C 1 and C 2 capacitors provide the additional 180 phase shift. The R 1resistor is used at lower frequencies (typically lower than 2.5 MHz) to introduce lossesaround the loop and prevent the oscillator going into harmonic oscillation. The R 2resistor is used t o bias th e am plifi er for bett er a nd q uicker oscillat or st a rt-up.

    Inputs/Outputs

    Input s a nd Out puts a llow th e microcont roller to commu nicat e with externa l devices.

    Input s An out side device forces a microcont roller pin high orlow. The logic level is read by the microcontroller as asingle bit of incoming information.

    Figure 1-10 P ha se Shif t Oscillat or

    AMPL.

    CRYSTAL

    GAIN A

    LOSS

    PHASE SHIFT(180 )

    OUT

    C1C2

    R1

    -+

    R2

  • 8/14/2019 COP8SAx Designer's Guide

    30/254

    1-18 MI C ROC ON TR OL LE R B AS I CS

    Out put s Microcont roller forces one of it s pins high or low. Theoutput volta ge on t he pin corresponds t o a single bit ofinformation.

    La t ches Oft en used t o st ore out going/incoming bit s.

    P ort s A port is a group of pins used for sending or receiving in-forma tion. A port ma y ha ve all output s, all inputs, or acombin a tion input /output pins. Some ports a re bidirec-tional. P ort pins ma y be used togeth er for pa ra llel com-

    munication or individually as control signals or serialcommunication.

    Memory Mapped I/O or Ports Ea ch port (group of pins) is assigned an a ddress a s i f i twere a register (byte of da ta ) in memory. Writing to a naddress assigned to a port causes the pins associatedwit h t he a ddressed port to be forced high or low a ccord-ing to the value writ ten. I f ports are not memoryma pped, special I /O inst ruct ions h a ve to be used to ac-cess t hem.

    U s er-C on fi gu ra ble I /O U s er-con fi gu ra ble por ts or I/O m a y be set by t he u ser to

    be inputs or outputs (some ports are fixed in hardwareto be inputs or outputs). A configuration or control reg-ister is generally associated with a user-configurableport. S ett ing or resetting t he bits in this special registerconfi gures th e associat ed port pins the be inputs or out -put s. Some user-confi gur a ble I/O port s only a llow th euser to select pins of a par ticular port to be all inputs ora ll out puts. Oth er devices a llow th e user to specify t heconfiguration of each individual pin of a port. Somepins/port s h a ve user selecta ble specia l funct ions.

    D edica t ed I/O D edica ted I/O pins ca n only be used for one pa rt icula rfunction. For example, the RESET pin can rarely beused for a nyt hing other tha n resetting t he device. Othersuch pins m ight be th e clock pin.

  • 8/14/2019 COP8SAx Designer's Guide

    31/254

    M IC R OC O NTR OL LE R B AS I C S 1-19

    1.7.6 Instruction Set

    Each microcontroller has a set of instructions. The user can organize particularinstructions in a logical order to create a program. The microcontroller follows thisprogra m t o perform a given ta sk. The cont ents of a microcont roller instru ction set va rywith various microcontrollers.

    Opcod es N um er ic cod es in t h e in st r uct ion s t h a t r epr es en t t h e a ct u a l oper a t ion t obe performed by the CPU are called operation codes (or opcodes forshort ). An opcode is a ctua lly a group of bits w hich tell t he microcontr ol-

    ler to perform a par ticular operat ion (a code w ord for a given operat ion).For exam ple; 64 might m ean clear t he a ccumula tor.

    Mnemonics N ames ass igned to par t icu la r oper a t ions a r e ca l led mnemonics . Ea chmnemonic is a ssocia ted w ith a par ticular opcode. A user ma y specify amnemonic such a s ADD ra th er th a n t he opcode 84. The mn emonic is lat -er t ra nsla ted into opcodes w hich th e microcont roller can decode. U singmnemonics m a kes writ ing code easier. For exa mple, t he mn emonics LD,ADD, J P, CLRA represent t he operat ion loa d, a dd, jump, a nd clea r a ccu-mu la tor, r espectively.

    Categories of Instructions

    1. Arit hm et ic/logic/sh ift (ADD /AND /RR C )

    2. Transfer of control (J P , J MP)

    3. Memory reference (LD)

    4. B i t manipula t ion (SB IT)

    5. S t a c k con t r ol (P U S H )

    6. Conditiona l/Test (IFEQ)

    Opcode fields/Multiple Byte Opcodes

    An opcode field is a group of bits w ith in a n opcode used to represent one specifi c pa rt ofan instruction. Typically the bits in an opcode are broken into groups or fields. Mostinstr uctions usua lly consist of a t least tw o fi elds: opcode fi eld a nd a ddress fi eld.

    Addressing Modes

    Implied The loca t ion/va lue of t he opera nd(s) is specifi edimplicitly in t he defi nition of th e instruction.

    Exa mple: CLR A, SC

    Immedia t e D a t a t o be used a s a n opera nd is specifi ed direct lyin the instr uction.

    Example: LD A, #023 or AND A, #0FF

  • 8/14/2019 COP8SAx Designer's Guide

    32/254

    1-20 MI C ROC ON TR OL LE R B AS I CS

    Memory D irect The memory a ddress of t he opera nd(s) is speci-fi ed in the instr uction.

    Exa mple: LD A, 00

    Regist er Indirect A regist er w hich cont a ins t he a ddress of t he oper-a nd in memory is specifi ed in the instr uction.

    Exa mple: LD A, [B ]

    Post-Increment or Post-Decrement Simila r to register indirect , a regis ter conta ining

    th e a ddress of th e operand in memory is specifi edin the instruction. However, the contents of theregister (the memory address) is automaticallyincrement ed or decrement ed a fter t he operand isfetched from the specified location.

    E xa mple: LD A, [B + ] or LD A, [B -]

    Indexed Addressing S imila r t o regist er indirect except a n index num-ber is also specifi ed in th e instr uction. This indexnum ber/displa cement is a dded t o th e content s of

    a base register to form t he a ctua l address of theoperan d. The ba se register ma y be either impliedin the instruction or given as a n a ddit iona l argu-ment . This a ddressing m ode is used t o access en-tries in a table. The base address represents thesta rt ing loca tion of the t a ble in memory. The dis-placement represents the distance between thesta r t of the ta ble a nd t he desired element in thetable.

    E xa mple: L D A, 12[B ] or AD D A, 14[R0]

    1.7.7 Programming

    Routines/Subroutines

    A routine is a segment of code which performs a specific function. A subroutine is asegment of code w hich performs a specifi c part of function. A subroutine is usua lly calledby several different routines or called severa l times from a single rout ine.

    Stack Manipulation

    On some microcont rollers, the sta ck is assigned a par ticular segment of memory an d th emicrocontroller initializes the stack pointer to a specific address upon reset. This isreferred to as st a ck initia lizing by ha rdw a re. There are a lso cases wh ere th e sta ck pointeris initialized the user program (softw a re) a t t he beginning of the progra m t o point t o asegment of a va ilable memory. The sta ck ma y be addressed by instructions such a s P U SHa nd P OP. The P U SH instruction places a piece of da ta on t he sta ck a nd increments or

  • 8/14/2019 COP8SAx Designer's Guide

    33/254

    M IC R OC O NTR OL LE R B AS I C S 1-21

    decrement s th e sta ck point er. The P OP inst ruct ion does the opposite; it removes a pieceof da ta from t he sta ck a nd decrement s or increments th e sta ck pointer.

    Interrupt Routines

    There ar e tw o meth ods to get th e int errupt routines:

    1. Without a Vector Ta ble

    P ollingAll interrupts ca use a n imm ediat e jump t o a single locat ion in m em-

    ory. The user program must poll all int errupt pending bits t o determine th ecause of th e interrupt. Once the ca use is determined, t he user progra m ma yjump to an appropriate interrupt handling routine.

    P reset Loca tionEa ch interrupt causes t he microcont roller to jump t o a dif-ferent place in memory. The location is specified by the microcontroller de-signer. The user program must store the interrupt handling routine at thespecified location.

    2. With a Vector Table

    A vector ta ble is a list of sta rt a ddresses for ea ch of the program 's interrupt

    routin es. This t a ble is used by t he microcontr oller to determ ine w here t o jumpwh en a part icular interrupt occurs.

    Direct J umpThe microcont roller may a ut oma tically rea d t he vector ta blew hen a n interru pt occurs and jump directly t o th e specifi ed addr ess.

    VIS InstructionThe microcontroller may jump to a single location in mem-ory for a ll interrupts. The user program ma y ca ll a specia l instru ction (VIS )to cause t he microcont roller to jump to th e specifi ed a ddress.

  • 8/14/2019 COP8SAx Designer's Guide

    34/254

    1-22 MI C ROC ON TR OL LE R B AS I CS

    Context Switching

    Saving and restoring of the microcontroller state during interrupts or when switchingbetween different tasks.

    Exa mple of an int errupt routine:

    INTERRUPT;

    PUSH A ; Save accumulator

    PUSH CNTRL ; Save control register

    PUSH PSW ; Save process status word

    IFBIT 0, IPND ; If timer interrupt pending

    JP TIMERINT ; then jump to timer interrupt

    IFBIT 1, IPND ; If external interrupt pending

    JP EXTERNALINT ; then jump to external interrupt

    IFBIT 2, IPND ; If serial interrupt pending

    JP SERIALINT ; then jump to serial interrupt

    EXIT ; Exit from interrupt

    LD IPND, #00 ; Clear pending bits

    POP PSW ; Restore process status word

    POP CNTRL ; restore control register

    POP A ; Restore accumulator

    RETI ; Return from interrupt

  • 8/14/2019 COP8SAx Designer's Guide

    35/254

    M IC R OC O NTR OL LE R B AS I C S 1-23

    Assembler

    1. As sem bler

    The assembler is a softw a re progra m th a t converts a source progra m into anobject fi le. In oth er words, it converts ASC II representa tion of instru ctions t obinary representa tion.

    2. Assembler Inputs/Outputs

    Source File - ASC II fi le cont a ining a softw a re program w ritt en in inst ruction

    mnemonics (symbolic language).

    Object File - "E xecut a ble" fi le conta ining inst ruction opcodes (ma chine la n-guage).

    Listing File - An ASCI I fi le which lists each locat ion in m emory a nd t he in-struction opcode associated with it . It usually contains assembly error mes-sages. This listing is useful for finding errors, determining size of code,fi ndin g locat ion of segment s of code, an d checking for proper a ssembling of in-structions.

    Sy mbol Ta ble - Ta ble of const a nt s a nd symbols wit h t heir a ssocia ted va lues.

    It is useful for det ermining t he locat ions of subroutines in t he code.

    3. Assembler Direct ives

    An a ssembler directive is a n inst ruction for the a ssembler in t he source fi le.Different a ssemblers ha ve different sets of directives. Exa mples:

    .CHIP Specifies t he pa rt icula r device for w hich th e code is wr itt en

    .END S pecifies the end of the code

    .=NUM S ets t he locat ion count er to NU M. The locat ion count er is usedby t he a ssembler t o store th e add ress of th e memory loca tionw here th e current inst ruction is being st ored. This directivea llow s th e user to specify a par ticular locat ion for a givensegmen t o