Microcomputer System
Microcomputer System
Microcomputer System
MicrocomputerSystems
1.1 Introduction
The term microcomputer is used to describe a system that includes a minimum of
a microprocessor, program memory, data memory, and input/output (I/O). Some
microcomputer systems include additional components such as timers, counters,
analogue-to-digital converters and so on. Thus, a microcomputer system can be
anything from a large computer having hard disks, floppy disks and printers, to a
single chip computer system.
In this book we are going to consider only the type of microcomputers that consist of
a single silicon chip. Such microcomputer systems are also called microcontrollers.
memory. Program memory stores all the program code and this memory is usually
non-volatile, i.e. data is not lost after the removal of power. Data memory is where
the temporary user data is stored during the various arithmetic and logical
operations. There are basically five types of memories as summarized below.
1.2.1 RAM
RAM means Random Access Memory. It is a general purpose memory which
usually stores user data. RAM is volatile, i.e. data is lost after the removal of power.
Most microcontrollers have some amount of internal RAM. 256 bytes is a common
amount, although some microcontrollers have more, some less.
1.2.2 ROM
ROM is Read Only Memory. This type of memory usually holds program or fixed
user data. ROM memories are programmed at the factory and their contents cannot
be changed by the user. ROM memories are only useful if you have developed a
program and wish to order several thousand copies of it.
1.2.3 EPROM
EPROM is Erasable Programmable Read Only Memory. This is similar to ROM but
the EPROM can be programmed using a suitable programming device. EPROM
memories have a small clear window on the chip where the data can be erased under a
UV light. Many development versions of microcontrollers are manufactured with
EPROM memories where the user program is usually stored. These memories are
erased and reprogrammed until the user is satisfied with the program. Some versions
of EPROMs, known as OTP (One Time Programmable), can be programmed using a
suitable programmer device but these memories cannot be erased. OTP memories
cost much less than the EPROMs. OTP is useful after a project has been developed
completely and it is required to make hundreds of copies of the program memory.
1.2.4 EEPROM
EEPROM is Electrically Erasable Programmable Read Only Memory. These
memories can be erased and also be programmed under program control. EEPROMs
are used to save configuration information, maximum and minimum values,
identification data etc. Some microcontrollers have built-in EEPROM memories (e.g.
PIC16F84 contains a 64-byte EEPROM memory where each byte can be programmed
and erased directly by software). EEPROM memories are usually very slow.
1.3.3 Timers
Timers are an important part of any microcontroller. A timer is basically a counter
which is driven from an accurate clock (or a division of this clock). Timers can be
4 PIC BASIC: Programming and Projects
8 bits or 16 bits long. Data can be loaded into the timers and they can be started and
stopped under software control. Most timers can be configured to generate an
interrupt when they reach a certain count (usually when they overflow). Some
microcontrollers offer capture and compare facilities where a timer value can be
read when an external event occurs, or the timer value can be compared to a preset
value and interrupts can be generated when this value is reached. It is typical to have
at least one timer on every microcontroller. Some microcontrollers may have three
or more while others may have two timers.
1.3.4 Watchdog
Many microcontrollers have at least one watchdog facility. The watchdog is usually
refreshed by the user program and a reset occurs if the program fails to refresh the
watchdog. Watchdog facilities are commonly used in real-time systems where it is
required to check the proper termination of one or more activities.
1.3.6 Interrupts
Interrupts are a very important concept in microcontrollers. An interrupt causes a
microcontroller to respond to external and internal (e.g. timer) events very quickly.
When an interrupt occurs the microcontroller leaves its normal flow of execution
and jumps directly to the interrupt service routine. Interrupts can in general be
nested such that a new interrupt can suspend the execution of another interrupt.
Most microcontrollers have at least one, some have several interrupt sources.