ST ST7 Series User manual

ST7
8-BIT MCU FAMILY
USER GUIDE
JANUARY 1999
1

USE IN LIFE SUPPORT DEVICES OR SYSTEMS MUST BE EXPRESSLY AUTHORIZED.
STMicroelectronicsPRODUCTS ARE NOT AUTHORIZED FOR USE AS CRITICAL COMPONENTS IN
LIFE SUPPORT DEVICES OR SYSTEMS WITHOUT THE EXPRESS WRITTEN APPROVAL OF
STMicroelectronics. As used herein:
1. Life support devices or systems are those
which (a) are intended for surgical implant into
the body, or (b) support or sustain life, and
whosefailure toperform, when properly used in
accordance with instructions for use provided
with the product, can be reasonably expected
to result in significant injury to the user.
2. A critical component is any component of a life
support device or system whose failure to
perform can reasonably be expected to cause
the failure of the life support device or system,
or to affect its safety or effectiveness.
1

3/317
Table of Contents
1INTRODUCTION........................................................12
1.1 WHOISTHISBOOKWRITTENFOR? .................................12
1.2 ABOUTTHEAUTHORS.............................................12
1.3 HOWISTHISBOOKORGANIZED? ...................................12
1.4 WHYAMICROCONTROLLER?.......................................13
1.4.1 Electroniccircuitry......................................................15
1.4.2 Choiceofmicrocontrollermodel ...........................................17
1.4.3 Choiceofdevelopmenttools .............................................17
2HOWDOESATYPICALMICROCONTROLLERWORK? .......................19
2.1 THE CENTRAL PROCESSING UNIT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
2.2 HOW THE CPU AND ITS PERIPHERALS MAKE UP A SYSTEM . . . . . . . . . . . . 21
2.2.1 CPU ................................................................21
2.2.2 Memory..............................................................21
2.2.3 Input-Outputs . . . ......................................................23
2.2.4 InterruptController .....................................................24
2.2.5 Bus .................................................................25
2.2.6 ClockGenerator .......................................................25
2.2.7 ResetGenerator .......................................................25
2.3 CORE ...........................................................25
2.3.1 ArithmeticandLogicUnit(ALU) ...........................................25
2.3.2 Program Counter ......................................................26
2.3.3 InstructionDecoder.....................................................26
2.3.4 StackPointer .........................................................26
2.4 PERIPHERALS ....................................................27
2.4.1 Parallel Input-Outputs ...................................................27
2.4.2 AnalogtoDigitalConverter...............................................28
2.4.3 ProgrammableTimer ...................................................28
2.4.4 SerialPeripheralInterface ...............................................28
2.4.5 Watchdog Timer . ......................................................28
2.5 THEINTERRUPTMECHANISMANDHOWTOUSEIT ....................29
2.5.1 Interrupthandling ......................................................29
2.5.1.1 Hardware mechanism . .............................................31
2.5.1.2 Hardwaresourcesofinterrupt ........................................31
2.5.1.3 Global interrupt enable bit ...........................................32
1

4/317
Table of Contents
317
2.5.1.4 Softwareinterruptinstruction.........................................32
2.5.1.5 Savingthestateoftheinterruptedprogram .............................32
2.5.1.6 Interruptvectorization ..............................................32
2.5.1.7 Interruptserviceroutine.............................................34
2.5.1.8 InterruptReturninstruction ..........................................34
2.5.2 Softwareprecautionsrelatedtointerruptserviceroutines .......................34
2.5.2.1 SavingtheYregister ...............................................34
2.5.2.2 Managing the stack . . . .............................................35
2.5.2.3 Resetting the hardware interrupt request flags ...........................35
2.5.2.4 Makinganinterruptserviceroutineinterruptible ..........................35
2.5.2.5 Datadesynchronizationandatomicity..................................36
2.5.3 Conclusion: the benefits of interrupts . . . ....................................38
2.6 AN APPLICATION USING INTERRUPTS: A MULTITASKING KERNEL . . . . . . . 39
2.6.1 Pre-emptivemultitasking ................................................39
2.6.2 Cooperative multitasking . . . .............................................41
2.6.3 Multitaskingkernels ....................................................42
2.6.3.1 Advantagesofprogrammingwithamultitaskingkernel ....................42
2.6.3.2 Thetaskdeclarationandallocation....................................42
2.6.3.3 Tasksleepingandwaking-up ........................................42
2.6.3.4 Multitasking kernel overhead .........................................43
3PROGRAMMINGAMICROCONTROLLER...................................45
3.1 ASSEMBLY LANGUAGE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
3.1.1 When to use assembly language ..........................................45
3.1.2 Development process in assembly language .................................46
3.1.2.1 Assembly language . . . .............................................47
3.1.2.2 Assembler .......................................................48
3.1.2.3 Linker...........................................................49
3.1.2.4 Theprojectbuilder/makeutility .......................................51
3.1.2.5 EPROMburners ..................................................52
3.1.2.6 Simulators .......................................................53
3.1.2.7 In-circuitemulators ................................................54
3.2 CLANGUAGE.....................................................55
3.2.1 WhyuseC? ..........................................................55
3.2.2 Tools used with C language . .............................................57
3.2.3 Debugging in C . . ......................................................58
3.3 DEVELOPMENT CHAIN SUMMARY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
3.4 APPLICATIONBUILDERS...........................................61
3.5 FUZZY-LOGICCOMPILERS .........................................61
1

5/317
Table of Contents
4ARCHITECTUREOFTHEST7CORE.......................................62
4.1 POSITIONOFTHEST7WITHINTHESTMCUFAMILY....................62
4.2 ST7CORE........................................................63
4.2.1 Addressingspace......................................................65
4.2.2 Internalregisters.......................................................65
4.2.2.1 Accumulator(A)...................................................65
4.2.2.2 Condition Code register (CC) ........................................65
4.2.2.3 Index registers (X and Y) ............................................67
4.2.2.4 Program Counter (PC) . .............................................68
4.2.2.5 StackPointer(SP).................................................68
4.3 INSTRUCTION SET AND ADDRESSING MODES . . . . . . . . . . . . . . . . . . . . . . . . 70
4.3.1 A word about mnemonic language .........................................70
4.3.2 Addressingmodes .....................................................72
4.3.3 Instructionset .........................................................73
4.3.4 Coding of the instructions and the address ..................................74
4.3.4.1 Prefixbyte .......................................................74
4.3.4.2 Opcodebyte .....................................................75
4.3.4.3 The addressing modes in detail . . . ....................................77
4.4 ADVANTAGES OF THE ST7 INSTRUCTION SET AND ADDRESSING MODES 82
5PERIPHERALS.........................................................84
5.1 CLOCKGENERATOR ..............................................84
5.1.1 ST72251 Miscellaneous Register ..........................................84
5.1.2 ST72311 Miscellaneous Register ..........................................85
5.2 INTERRUPT PROCESSING . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
5.2.1 Interruptsourcesandinterruptvectors......................................86
5.2.1.1 InterruptssourcesfortheST72251....................................87
5.2.1.2 InterruptsourcesfortheST72311.....................................88
5.2.2 Interruptvectorization ...................................................89
5.2.3 Globalinterruptenablebit................................................90
5.2.4 TRAPinstruction.......................................................91
5.2.5 Interrupt mechanism ....................................................91
5.2.5.1 Savingtheinterruptedprogramstate ..................................91
5.2.5.2 Interruptserviceroutine.............................................91
5.2.5.3 Restoringtheinterruptedprogramstate:TheIRETinstruction ...............92
5.2.6 Nestingtheinterruptservices.............................................92
5.3 PARALLELINPUT-OUTPUTPORTS ..................................94
1

6/317
Table of Contents
317
5.3.1 ST72251 I/O Ports .....................................................94
5.3.2 ST72311 I/O Ports .....................................................96
5.4 WATCHDOG TIMER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
5.4.1 Aim of the watchdog ....................................................99
5.4.2 Watchdog Description ..................................................100
5.4.3 Using the Watchdog to protect an application ...............................103
5.5 16-BITTIMER ....................................................103
5.5.1 Timerclock ..........................................................104
5.5.2 Free running counter ..................................................105
5.5.2.1 Reading the free running counter . ...................................105
5.5.2.2 Resetting the free running counter ...................................106
5.5.2.3 TheTOFflag ....................................................107
5.5.3 Input capture operation .................................................108
5.5.4 Output compare operation . . ............................................110
5.5.5 One-pulsemode......................................................113
5.5.6 Pulse-Width Modulation mode ...........................................115
5.6 ANALOGTODIGITALCONVERTER .................................117
5.6.1 Description ..........................................................117
5.6.2 UsingtheAnalogtoDigitalConverter......................................118
5.6.3 Theproblemoftheconverter'saccuracy ...................................119
5.6.4 Using the ADC to convert positive and negative voltages; increasing its resolution . .120
5.6.4.1 Measuring negative and positive voltages ..............................120
5.6.4.2 Increasingtheresolution ...........................................121
5.6.4.3 ApplicationExamples .............................................124
5.7 SERIALPERIPHERALINTERFACE ..................................125
5.8 SERIALCOMMUNICATIONINTERFACE ..............................128
5.8.1 Bit rate generator .....................................................128
5.8.2 Send and receive mechanism ...........................................129
5.8.3 Statusregister........................................................132
5.8.4 ControlRegister2.....................................................132
5.8.5 Using the Wake-Up feature in a multiprocessor system ........................133
5.8.6 Handling the interrupts .................................................133
6STMICROELECTRONICSPROGRAMMINGTOOLS ..........................135
6.1 ASSEMBLER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .135
6.1.1 Anoverviewoftheassemblerfunction.....................................135
6.1.2 Instructioncoding .....................................................137
1

7/317
Table of Contents
6.1.3 Declaringvariables....................................................138
6.1.4 Declaringconstants ...................................................140
6.1.4.1 Constantdata ...................................................140
6.1.4.2 Symboldefinition .................................................141
6.1.5 Relocation commands .................................................142
6.1.5.1 Whatisrelocation? ...............................................142
6.1.5.2 Segmentdefinition................................................143
6.1.5.3 UsingtheSegmentdirectiveinthesourcefile...........................145
6.1.5.4 Segmentallocation ...............................................146
6.1.5.5 Initializationofvariablesatpower-on..................................148
6.1.5.6 Referencing symbols and labels between modules .......................151
6.1.6 Conditional assembly ..................................................154
6.1.7 Macros .............................................................156
6.1.7.1 Replaceableparameters ...........................................157
6.1.7.2 Localsymbols ...................................................158
6.1.7.3 Conditional statements in macros . ...................................160
6.1.8 Some miscellaneous features ............................................162
6.1.8.1 EQUandCEQUpseudo-ops........................................162
6.1.8.2 #DEFINE pseudo-op . . ............................................162
6.1.8.3 Numberingsyntaxdirectives ........................................163
6.1.9 Objectandlistingfiles..................................................163
6.1.9.1 Objectfiles......................................................164
6.1.9.2 Listingfiles......................................................164
6.2 LINKERANDASCII-HEXCONVERTER ...............................165
6.2.1 Thelinkingprocess....................................................165
6.2.2 Hexfiletranslator .....................................................167
6.2.3 The back-annotation pass of the assembler .................................168
6.3 INSTALLINGWINEDITANDTHESOFTWARETOOLS...................168
6.3.1 WinEdittexteditor.....................................................168
6.3.1.1 InstallingWinEdit .................................................168
6.3.1.2 ConfiguringWinEdit...............................................169
6.3.2 InstallingtheSTMicroelectronicsSoftwareTools.............................169
6.4 BUILDINGADEMONSTRATIONPROGRAM ...........................170
6.4.1 Purposeofthedemonstrationprogram ....................................170
6.4.2 Inventoryoftheprogramfiles............................................170
6.4.3 Descriptionoftheprogramfiles ..........................................171
6.4.3.1 The PROJECT.WPJ file ..........................................171
6.4.3.2 The main source file, MAIN.ASM and the timer source file, TIMER500.ASM . . .
173 6.4.3.3 The REG72251.ASM file and the REGISTER.INC file .................176
6.4.3.4 The MAP72251.ASM file .........................................178
1

8/317
Table of Contents
317
6.4.3.5 The CATERPIL.BAT file ..........................................179
6.4.4 Using WinEdit to change and compile the files ...............................180
7DEBUGGERANDPROMPROGRAMMERTUTORIALFORST72251 ............183
7.1 STMICROELECTRONICS HARDWARE TOOLS . . . . . . . . . . . . . . . . . . . . . . . . .183
7.1.1 EPROMProgrammingBoards ...........................................183
7.1.2 StarterKits ..........................................................184
7.1.3 DevelopmentKits .....................................................184
7.1.4 Emulators ...........................................................184
7.2 EPROMPROGRAMMERBOARDS ...................................184
7.2.1 EPROMprogrammerInstallation .........................................185
7.2.2 UsingtheEPROMERsoftware...........................................185
7.3 EMULATORANDDEBUGGER ......................................189
7.3.1 Introducing the emulator and the debugger .................................189
7.3.2 Installing the emulator and the debugger ...................................189
7.3.3 Using the debugger ...................................................193
7.3.3.1 Loading the application ............................................193
7.3.3.2 Running the application ............................................195
7.3.3.3 Watchingtheregistersandvariables..................................195
7.3.3.4 UsingInspectandWatch...........................................197
7.3.3.5 Usingbreakpoints ................................................199
7.3.3.6 Watchingthecontentsofthestack ...................................200
7.3.3.7 Watchingtheexecutiontrace .......................................201
7.3.3.8 Morefeaturestocomelater.........................................202
7.4 PURPOSEOFTHETUTORIAL ......................................202
7.5 SCHEMATICDRAWINGOFTHEPRINTEDCIRCUITBOARD .............204
7.6 DEVELOPING THE PROGRAM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .204
7.6.1 Peripherals used to implement the solution .................................204
7.6.2 Thealgorithmofeachtask ..............................................205
7.6.3 AsimplemultitaskingkernelfortheST7 ...................................206
7.6.3.1 StartTasks routine ...............................................206
7.6.3.2 The Yield routine.................................................208
7.6.4 Thesourcecodeoftheapplication........................................211
7.6.4.1 Main file (Multitsk.asm) ...........................................212
7.6.4.2 ADC source file(Acana.asm) .......................................216
7.6.4.3 Kernel source file (Littlk.asm)..................................217
7.7 RUNNING THE APPLICATION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .219
1

9/317
Table of Contents
7.8 SUMMARY REMARKS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .219
8CLANGUAGEANDTHECCOMPILER ....................................221
8.1 CLANGUAGEEXTENSIONSFORMICROCONTROLLERS ...............221
8.2 DESCRIPTION AND INSTALLATION OF THE HICROSS TOOL CHAIN . . . . . .222
8.3 USINGTHECCOMPILER ..........................................226
8.3.1 Memoryallocation.....................................................226
8.3.1.1 Read-only constants . . ............................................227
8.3.1.2 EEPROMnon-volatilestorage.......................................228
8.3.1.3 PageZerovariables...............................................229
8.3.1.4 Far and near pointers . ............................................229
8.3.2 Initializationofvariablesandconstantvariables..............................230
8.3.3 Inputs and outputs ....................................................230
8.3.3.1 First method: using macros .........................................231
8.3.3.2 Second method: defining variables ...................................231
8.3.4 Interrupthandling .....................................................232
8.3.5 Limitations put on the full implementation of C language .......................232
8.4 USING THE ASSEMBLER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .233
8.4.1 UsingIn-lineassemblerstatementswithinaCsourcetext .....................233
8.4.1.1 Single-statementassemblerblock....................................233
8.4.1.2 Multiple-statementassemblerblock ..................................234
8.4.2 UsingtheHiwareassembler.............................................235
8.5 USINGTHELINKER...............................................235
8.6 USING THE EPROM BURNER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .237
8.7 PROJECTDIRECTORYSTRUCTURE ................................239
8.7.1 Configdirectory.......................................................239
8.7.2 Objectdirectory.......................................................241
8.7.3 Sourcesdirectory .....................................................241
8.8 HINTSONCWRITINGSTYLEFORTHEST7 ..........................242
8.8.1 Accessingindividualbitsinregisters ......................................242
8.8.2 Settingconfigurationregisters ...........................................245
8.8.3 Usingmacrostodefineexternaldevices ...................................245
8.8.4 Optimizingresourceusage..............................................246
8.8.4.1 Define a function when a group of statements is repeated several times ......247
8.8.4.2 Useshiftsinsteadofmultiplicationanddivision..........................247
8.8.4.3 Limitthesizeofvariablestotheveryminimum..........................248

10/317
Table of Contents
317
8.9 CONCLUSION....................................................248
9 A CARRIER-CURRENT SYSTEM FOR DOMESTIC REMOTE CONTROL . . . . . . . . . 249
9.1 CARRIER CURRENT CONTROL AND THE X-10 STANDARD . . . . . . . . . . . . . 250
9.2 TRANSMITTER...................................................255
9.2.1 Instructionsforuse ....................................................255
9.2.2 Descriptionoftheelectroniccircuit........................................255
9.2.3 Descriptionofthesoftware..............................................259
9.2.3.1 Themainprogram ................................................259
9.2.3.2 TimerACaptureinterruptserviceroutine ..............................262
9.2.3.3 TheTimerBoverflowinterruptserviceroutine ..........................269
9.3 RECEIVER ......................................................272
9.3.1 Instructionsforuse ....................................................272
9.3.2 Electroniccircuitry.....................................................272
9.3.3 Software ............................................................276
9.3.3.1 Interruptfunctions ................................................276
9.3.3.2 Mainprogram....................................................279
9.4 CONCLUSION....................................................285
10SECONDAPPLICATION:ASAILINGCOMPUTER ..........................286
10.1THEORYOFTHECOMPUTATION ...................................288
10.2INTERFACINGTHEMEASUREMENTDEVICES ........................291
10.2.1 Frequency-type devices: speedometer and wind gauge .......................291
10.2.1.1 Interfacing the speedometer ........................................291
10.2.1.2 Interfacing the wind gauge ..........................................291
10.2.1.3 Using a common timer for both speed measurement devices ...............292
10.2.2Interfacingtheweathervane ............................................293
10.3INTERFACINGTHEDISPLAY .......................................294
10.3.1Displaycircuit ........................................................295
10.3.2Push-buttoncircuit ....................................................298
10.3.3LEDcircuit ..........................................................299
10.4INTERFACINGTHEOPTIONALPERSONALCOMPUTER ................299
10.5PROGRAMARCHITECTURE........................................300
10.5.1 Reading and conversion of the speeds . ...................................300
10.5.2Refreshingofthedisplay ...............................................302

11/317
Table of Contents
10.5.3Pollingthepush-buttons................................................304
10.5.4 Reading and filtering the wind direction . ...................................305
10.5.5Theperiodicinterruptserviceroutine ......................................306
10.5.6Computationoftheresults ..............................................307
10.5.7 Handling of the serial interface ...........................................309
10.5.8 Initialization of the peripherals and the parameters . ..........................310
10.6 MEMORY ALLOCATION AND COMPILE AND LINK OPTIONS . . . . . . . . . . . .312
10.7CONCLUSION....................................................314
11SOMELASTREMARKS ...............................................315

12/317
1 - Introduction
1 INTRODUCTION
1.1 WHO IS THIS BOOK WRITTEN FOR?
This book is a technical guide for ST7 users and may be approached in different ways:
For studentsand anyone unfamiliar with microprocessors, but with some experience of logic
circuits; they should start by reading Chapters 1 through 3.
For trained engineers wanting to get specific knowledge about the ST7 and microcontroller
programming in C language; they may skip Chapters 1 through 3 and go straight to Chapter
4.
For designers already familiar with the ST7, needing more details about C-language
programming and how to use the ST7 internal peripherals; the application descriptions in
Chapters 5 and 8 through 10 are of special interest for them.
1.2 ABOUT THE AUTHORS
Jean-Luc Gregoriades teaches automated systems and industrial computer science at the
Electrical Engineering department of the University of Cergy-Pontoise, France.
Jean-Marc Delaplace is an electronics and software engineer at Gilson S.A., a laboratory au-
tomation instrument maker.
As a team, they have already written books on the ST6 (published at Dunod Editions)and the
ST9 (published by STMicroelectronics).
1.3 HOW IS THIS BOOK ORGANIZED?
This book contains the following chapters:
Chapter 1: Introduction.
Chapter 2: How does a typical microcontroller work internally and how to use it.
Chapter 3: Programming a microcontroller.
Chapter 4: Architecture of the ST7 core.
Chapter 5: The peripherals.
Chapter 6: The STMicroelectronics programming tools.
Chapter 7: The Debugger and the PROM programmer through a pedagogic application using
a ST72251.
Chapter 8: The C language and the C compiler.
Chapter 9: Application of the ST72251: a carrier-current system for domestic remote control.
Chapter 10: Application of the ST72311: a sailing computer.

13/317
1 - Introduction
Chapter 11: Conclusion.
Chapters 1, 2 and 3 are a refresher on theconcept of a microcontroller. Chapter 1 introduces
the concept, Chapter 2 addresses the hardware and Chapter 3 addresses the software as-
pects.
Chapters 4 through 7 describe the ST7 and its programming tools, taking only assembly lan-
guage into account.
Chapter 8 discusses the C language and techniques for using the C Compiler for the ST7 mi-
crocontroller, its strengths and also its limitations.
Chapters 9 and 10 describe application projects using the ST72251 and the ST72311 mem-
bers of the ST7 family. They tell the story of the design of devices that, though they do work,
were not intended to be commercial products.
1.4 WHY A MICROCONTROLLER?
The microcontroller is just another choice when one has to design an application, and it com-
petes with other technologies, like wired logic, a microprocessor system, or a Programmable
Logic Device of which many types are available.
All these solutions tend to reduce the number of components, the area of printed circuit used,
the number of connections, while increasing the computing power and keeping the cost low.

14/317
1 - Introduction
The following table shows a comparison of these solutions. Each one is discussed below.
Wired logic uses commercially available logic functions and sometimes linear chips. Though it
is simple, it is neither practical nor economical to consider this technology for building applica-
tions as complex as those that are usually needed today. It can only be considered for very
special subfunctions where high speed is required.
Programmable Logic Devices(PLD) arethe modern form ofwired logic,and are often used for
combinatory and sequential logic. The biggest models allow intensive numeric processing, but
only on integer numbers. They use programming languages that do not belong to the family of
computer languages commonly used today.
The last two technologies are the microprocessor and the microcontroller. In principle, both
areverymuchalikeandtheyarebothwellsuitedtoprogrammeddataprocessing.Themain
difference between them is the size of the application.
The microprocessor is a component that includes mainly the computing core, and perhaps the
logic closely related to itlike the clock generator, the interruptcontroller, etc. Many more chips
must be added to it in order to make a functional application, memory chips in particular. Ac-
tually, this solution is only used in computers, either general-purpose computers like PCs, or
built-in to complex applications like industrial robots. It allows the designer to tailor his circuit
exactly to his needs.
The microcontroller is defined as a complete programmed system in one chip. This means
that one chip is sufficient to fulfil the need, or that only a few more chips are required to
Solution type Advantages Drawbacks
Wired logic Very high speed
Cheap Only for simple circuits
Programmable logic High speed
Able to handle complex digital signals
Limited number processing
Programming languages are specific
and non-portable
May be expensive
Microprocessor
Powerful
Wide choice of models
Configurable in wide limits
Allows almost all popular programming
languages
Many components even for simple sys-
tems
Relatively expensive
Microcontroller
Simple electronic circuits are possible
with few components
Allows the most popular programming
languages such as BASIC or C.
Standard configurations rarely exactly
fit the application’s needs implying the
use of over-sized models
Special configurations available, but
only for large quantities.

15/317
1 - Introduction
achieve the required computational power. These external chips may simply be interface com-
ponents, to adapt the electric signals to the input-output pins of the microcontroller, or addi-
tional memory or peripheral components if the buses are available externally on the pins of the
microcontroller.
In any case, these components require two different but equally important jobs for putting
them to work: electronic circuit design, and programming.
Both of these need be done as easily, quickly and economically as possible. A thorough study
of both aspects will be the basis for selecting the most appropriate model from the wide range
of products available today. Here are a few considerations related to these aspects.
1.4.1 Electronic circuitry
Thisiswhere thedesignerstrives toreducethe externalcomponentcount,and to carefully se-
lect each one to get the best value. In order to satisfy this requirement, the various chip man-
ufacturers offer for each family a choice of variants, to allow the designer to select the one that
best fits his needs in terms of input-outputs and auxiliary circuitry.
Roughly speaking, a microcontroller variant that is loaded withfeatures will allow a simpler ex-
ternal circuitry, at the expense of an increase in the microcontroller cost. The ideal choice
would be the variant that has the exact peripherals required by the application, and no more.
To illustrate this, we shall take a simple example. Let us consider an application that requires,
asaninput, anumerickeypad,and as an output,a galvanometertoprovide an analog display.
The ideal combination would call for an Analog to Digital Converter for the input, and a pro-
grammable timer with Pulse Width Modulation capability for the output. This would lead to the
following very simple schematic:

16/317
1 - Introduction
01-anal
Such peripheralsare typically available in many families. This example shows how two periph-
erals properly selected can drastically reduce the component count and thus the printed circuit
area. The solution shown may or may not fit the needs, but it is difficult to imagine a simpler
design.
+5v
Analog input
GND
Micro
controller
R
R
R
R
R
R
Array of
resistors
Current
generator
Analog keyboard
Analog display
Push pull
output with
PWM signal
Example of simplified circuitry thanks to a microcontroller

17/317
1 - Introduction
1.4.2 Choice of microcontroller model
The selected model of microcontroller must meet the requirements in terms of computational
power. It must be able to handle the input-outputs, process the data in the required amount of
time, and have enough memory to store both theprogram and the data.
An application is made of both hardware and software. So, there is a trade-off between the
processing done by hardware and that done by software. Using dumb peripherals requires
more computational power from the core; using sophisticated peripherals relieves the core
from time-consuming calculations and thus allows a less powerful core to be chosen.
Determining the computational power is a difficult matter since there is no internationally rec-
ognized measurement unit that expresses the speed of a microprocessor or similar device.
Some benchmarks that compare several products in the same application are available from
various sources, but they only give an idea of the relative capability of one product versus an-
other one.
Thus a certain margin must be considered, or there would be a risk that some time in the de-
velopment process that one comes to the conclusion that the selected microcontroller is un-
suitable for the application. This event would have serious consequences, as costly tools may
have been invested to develop the application, not to mention the delay in the product availa-
bility with its commercial consequences.
Also, even ifa microcontroller is suited to the product as itis first commercialized, this product
may undergo changes during its commercial life. As a general rule, changes are always addi-
tions, never removals. If the chosen microcontroller matches current needs too closely in
terms of capability, there is a risk that it could prevent the product from evolving to meet future
needs. This could make the product become obsolete sooner than expected.
To summarize, it is difficult to tell in advance whether a microcontroller will fit an application.
Asaresult, itiscurrentpractice to selecta modelwithexcesspowerin ordertoguaranteesuc-
cessful performance initially, and also to allow for product updates.
1.4.3 Choice of development tools
Once the needed power has been determined, one must investigate the development tools
availablefor the applicableproducts. The firststep isto comparetheirprices;but this isnot the
consideration that will determine the choice.
The real issue is how the tools will help writing the software, test it, and pinpoint its flaws. The
hourly cost of a software engineer, who spends more time on software development because
of the lack of efficiency of the tools, easily outweighs any savings that could have been made
when investing in them.
Development tools include all that is needed to write the program, either in assembly language
or in high level language, then translate it into machine language and load it into the program

18/317
1 - Introduction
memory of the application. The tools are able to test both the hardware and the software, and
analyze any malfunctioning in order to allow corrections to be made. This can be done using
only a Personal Computer, or external instruments connected to the computer, such as an
emulator, analyzer, PROM programmer, etc. depending on the development phase. The dia-
gram below shows where each phase takes place:
01-proc
The microcontroller itself, and the related development tools are described in Chapters 2 and
3.
Source text editor
Compiler
Assembly software tool
Linkage software tool
Simulation or emulation software tool
These software tools
are specific to a
microcontroller family
Typing of the programsource text
Simulation
Emulation tool
Probe
Application
PC
Debugging using an emulator
PC-based development environment

19/317
2 - How does a typical microcontroller work?
2 HOW DOES A TYPICAL MICROCONTROLLER WORK?
There is a wide range of microcontrollers available on the market. They differ in their compu-
tational power, their internal organization, the number of their inputs and outputs, the type of
peripherals they provide. However, a microcontroller is always a complete system on a chip
that includes a core connected to some memory and surrounded by peripherals. A typical
block diagram of a microcontroller is the following:
02-basic
The peripherals shown here are only the most common that one can find in a microcontroller.
Other peripherals, designed for special tasks or communication protocols, may be found as
well. Let us mention just a few:
I2Cserialinterface
Radio Data System decoder
Liquid Crystal Display interface, etc.
We shall gain an overview of the main blocks in the remainder of this chapter.
general purpose and
dedicated registers,
accumulators
instructions decoder
program counter
stack
reset
generator
clock
generator
arithmetic
and logic unit
interrupt
controller
core
watchdog
timer
multifonction
timer(s)
EEPROM
internal
RAM
internal
ROM
(EPROM)
peripherals
serial
interface parallel input / output
ports
communication with the outer world of the microcontroller
analog to
digital
converter
xtal
internal buses
Typical block diagram of a microcontroller

20/317
2 - How does a typical microcontroller work?
2.1 THE CENTRAL PROCESSING UNIT
What is the Central Processing Unit (CPU)?
It is made up of the core, and auxiliary blocks like the clock generator, the reset circuitry, etc.
The CPU of a microcontroller is the actual programmed logic circuitry that is the heart of the
application based around the microcontroller. It is where all computation and decision-making
takes place. The CPU acts on data received from the outside world through the peripherals;
this data is processed ina predetermined way to produce more data that will acton the the out-
side world.
The CPU is the part of a microcontroller that corresponds to what is usually called a micro-
processor. A microprocessor contains only the computing logic; it must be surrounded with
devices like memory and input-output interfaces. A microcontroller bundles all these in a
single chip. For simple projects, this allows an application to be built with just one chip plus a
few components. This has been made possible by progress in the scale of integration that al-
lows powerful chips to be manufactured at a relatively low cost. This has opened up a new and
very wide application field: bringing the capabilities of a computer to even the cheapest appli-
ances. For example, nowadays home audio systems incorporate a radio receiver, a CD
player, two cassette decks and an amplifier and speakers; all controlled by a common control
panel with a large display that shows the FM frequency, or the CD track number and elapsed
time, etc. Here, a single microcontroller performs the overall control, displays the data, re-
spondstothe keys thatare pressedbythe user to selectthe required radio channel, CD track,
etc.
The word data, that is so commonly used, must be understood here in the widest sense.
Though we may first think of data as numbers, data are not only numbers; they may be a wide
range of objects like binary values (the state of an on/off switch), the voltage at a terminal (the
wiper of a potentiometer), a character string (a piece of text), and many other things. The fact
that data is thought of as numbers just comes from the fact that we are discussing machines
based on binary signals. Virtually all the data processors in the world only process binary
digits. Thesebinary digits (bits) are always grouped in packs of variable lengths that are proc-
essed in parallel, thus multiplying the processor throughput by the number of these bits proc-
essed at the same time.
The first microprocessors, historically, were four-bit machines. There are still four-bit micro-
controllers sold today for simple applications like telephones, washing machines, and others
requiring little processing power.
In the sense that is given to this word today, a microprocessor is at least a 8-bit wide machine.
The market is shared between machines of several types, with their power increasing along
with the number of bits they can process in parallel. The following table gives an overview of
the main classes of microprocessors today.
Other manuals for ST7 Series
1
Table of contents
Other ST I/O System manuals
Popular I/O System manuals by other brands

Solid State Logic
Solid State Logic Multichannel Digital Audio Interface... reference guide

WAGO
WAGO 750-464 manual

CityGrow Systems
CityGrow Systems CG102IO-MD user manual

National Instruments
National Instruments 9753 user manual

Advantech
Advantech WISE-4050 installation guide

QSC
QSC ATTEROTECH Axiom Series user manual