29/317
2 - How does a typical microcontroller work?
quences in applications where the microcontroller must keep in control, like in automotive ap-
plications or in security systems.
Various solutions have been imagined to prevent such situations. The most popular is the
watchdog timer. This is a timer that is set for a certain duration at power up. The program must
reset it to its start value periodically; failing to do so, the timer will overflow and this event gen-
erates a hardware reset. This restores the system to the state it was at power up.
To use the watchdog timer properly, the program must reset it at the appropriate time, in a pe-
riodic manner. To do this efficiently requires some care. A word of advice is given on this sub-
ject in a later chapter.
2.5 THE INTERRUPT MECHANISM AND HOW TO USE IT
A microcontroller is a programmed computer that executes a single string of statements
known as «the program». Therefore, it apparently cannot perform more than one task at a
time.
However, most if not all applications require a single microcontroller to handle many things at
once. Usually, for cost-effectiveness and simplicity, the designer of a microcontroller-based
system tries to pack as many functions as possible in a single chip.
The answers to this problem are based both on hardware and on software. The hardware ap-
proach is called «interrupt handling» and the software approach is called «multitasking».
2.5.1 Interrupt handling
An interrupt, in computer terminology, is a mechanism that allows the currently executing pro-
gram to be interrupted, as the name implies, when an external event occurs. The computer
then starts to execute a specially-written piece of code that is intended to process the in-
coming event. Once this processing is finished, the main program resumes exactly where it
was interrupted. Nothing else happens to this program except that its execution is delayed by
the time it took to process the interrupt-triggered code.
Содержание ST7 Series
Страница 1: ...ST7 8 BIT MCU FAMILY USER GUIDE JANUARY 1999 1 ...
Страница 238: ...238 317 8 C Language and the C Compiler 08 Burn bmp Then use the EPROMer programmer software as described in Chapter 7 ...
Страница 289: ...289 317 10 Second Application a Sailing Computer 10 befor Bs Rw Vw VMG AlphaR AlphaV Before the wind ...