Chapter 1 Introduction to Microcontrollers 1.1 INTRODUCTION Microcontrollers have only been with us for a few decades but their impact (direct or indirect) on our lives is profound. Usually these are supposed to be just data processors performing exhaustive numeric operations. But their presence is unnoticed at most of the places like • At supermarkets in Cash Registers, Weighing Scales, etc. • At home in Ovens, Washing Machines, Alarm Clocks, etc. • At play in Toys, VCRs, Stereo Equipment, etc. • At office in Typewriters, Photocopiers, Elevators, etc. • In industry in Industrial Automation, safety systems, etc. • On roads in Cars, Traffic Signals, etc. What inside them makes these machines ]smart^? The answer is microcontroller. Creating applications for the microcontrollers is different than any other development job in electronics and computing. Before selecting a particular device for an application, it is important to understand what the different options and features are and what they can mean with regard to developing the application. The purpose of this chapter is to introduce the concept of a microcontrollers, how it differ from microprocessors, different type of commercial microcontrollers available as well as their applications. The reminder of the book will go through and present different types of microcontrollers and also programming and interfacing techniques of microcontroller, mainly 8051, in detail. 1.2 EMBEDDED CONTROLLER Simply an embedded controller is a controller that is embedded in a greater system. One can define an embedded controller as a controller (or computer) that is embedded into some device for some purpose other than to provide general purpose computing. Is an embedded controller is the same as a microcontroller? The answer is definitely no. One can state devices such as 68000, 32032, x86, Z80, and so on that are used as embedded controllers but they aren’t microcontrollers.
Microcontroller and Embedded System 2 We might be correct by stating that an embedded controller controls something (for example controlling a device such as a microwave oven, car braking system or a cruise missile). An embedded controller may also embed the on-chip resources like a microcontroller. Microcontrollers and microprocessors are widely used in embedded systems. Though microcontrollers are preferred over microprocessors for embedded systems due to low power consumption. 1.3 MICROCONTROLLERS AND MICROPROCESSORS A controller is used to control some process. At one time, controllers were built exclusively from logic components, and were usually large, heavy boxes. Later on, microprocessors were used and the entire controller could fit on a small circuit board. This is still common– one can find many controllers powered by one of the many common microprocessors (including Zilog Z80, Intel 8088, Motorola 6809, and others). As the process of miniaturization continued, all of the components needed for a controller were built right onto one chip. A one chip computer, or microcontroller was born. A CPU built into a single VLSI chip is called microprocessor. The simplified block diagram of the CPU is shown in the Fig. 1.1. It contains arithmetic and logic unit (ALU), Instruction decode and control unit, Instruction register, Program counter (PC), clock circuit (internal or external), reset circuit (internal or external) and registers. For example, Intel 8085 is 8-bit microprocessor and Intel 8086/8088 is 16-bit microprocessor. Microprocessor is general-purpose digital computer central processing unit (CPU). The microprocessor is general-purpose device and additional external circuitry are added to make it microcomputer. H o ld s the b in ary co de fo r e ach in struction a s it is e xecuted In struction R e gister (IR ) P ro gram C o un te r (P C ) H o ld s the m e m o ry a dd ress of th e ne xt in stru ction to b e e xe cu te d. R e gisters D e term ine s th e o pe ratio n to p e rform a nd sets in m otio n the n ecessary a ctio ns to p erfo rm it. In struction D e co de & C o ntrol U nit P e rfo rm s arithm e tic a nd lo gic op eration s A rith m e tic & L og ic U n it (A L U ) Tem p ora ry stora g e o f in fo rm atio n. Figure 1.1 General block diagram of CPU (Microprocessor)
! Introduction to Microcontroller A digital computer having microprocessor as the CPU along with I/O devices and memory is known as microcomputer. The block diagram in the Fig. 1.2 shows a microcomputer. A d dre ss Bus D a ta B us C P U C o ntrol B us ROM In te rfa ce C ircu itry RAM P e rip he ra l D e vice s Figure 1.2 Microcomputer block diagram A microcontroller is a highly integrated chip, which includes on single chip, all or most of the parts needed for a controller. The microcontroller typically includes: CPU (Central Processing Unit), RAM (Random Access Memory), EPROM/PROM/ROM (Erasable Programmable Read Only Memory), I/O (input/output) – serial and parallel, timers, interrupt controller. For example, Intel 8051 is 8-bit microcontroller and Intel 8096 is 16-bit microcontroller. I/O P o rts Tim er/C ounter SP ACC In te rrup t circuits R e gister(S ) In te rna l Rom C lo ck C ircu it In te rna l RAM ALU P ro gram C o un te r Figure 1.3 A block diagram of a microcontroller
Microcontroller and Embedded System 4 By only including the features specific to the task (control), cost is relatively low. A typical microcontroller has bit manipulation instructions, easy and direct access to I/O (input/output), and quick and efficient interrupt processing. Figure 1.3 shows the block diagram of a typical microcontroller. COMPARING MICROPROCESSORS AND MICROCONTROLLERS • • • • Microprocessor is a single chip CPU, microcontroller contains, a CPU and much of the remaining circuitry of a complete microcomputer system in a single chip. Microcontroller includes RAM, ROM, serial and parallel interface, timer, interrupt schedule circuitry (in addition to CPU) in a single chip. –RAM is smaller than that of even an ordinary microcomputer, but enough for its applications. –Interrupt system is an important feature, as microcontrollers have to respond to control oriented devices in real time. E.g., opening of microwave oven’s door cause an interrupt to stop the operation. (Most microprocessors can also implement powerful interrupt schemes, but external components are usually needed). Microprocessors are most commonly used as the CPU in microcomputer systems. Microcontrollers are used in small, minimum component designs performing control-oriented activities. Microprocessor instruction sets are ]processing intensive^, implying powerful addressing modes with instructions catering to large volumes of data. Their instructions operate on nibbles, bytes, etc. Microcontrollers have instruction sets catering to the control of inputs and outputs. Their instructions operate also on a single bit. E.g., a motor may be turned ON and OFF by a 1-bit output port. Before going in to details of microcontrollers it will be beneficial to go through common and frequently used terminology encountered in the description of microcontrollers. CENTRAL PROCESSING UNIT (CPU) CPU is the brain of the computer system, administers all activity in the system and performs all operations on data. It continuously performs two operations: fetching and executing instructions. It understand and execute instructions based on a set of binary codes called the instruction set. Machine Cycle To execute an instruction–the processor must: 1. Fetch the instruction from memory 2. Decode the instruction