Chapter 1
Introduction to Microcontrollers and Display Systems
The basic building blocks of any digital computer are the central processing unit (CPU), the memory and the input-output (I/O). The CPU is like the human brain, as it controls all internal operations of the computer. Instructions are fetched from the memory under the control of the CPU, which it then decodes and controls various internal parts of the computer so that the required operations are performed. The CPU also includes an arithmetic and logic unit (ALU), which is used to perform mathematical and logical operations. The result of an operation is stored either in the memory, in a temporary register, or is sent to an I/O port. Two types of memories are used in a computer, as far as memory functionality is concerned. The program memory stores the user instructions and this memory is normally non-volatile, that is the data is not lost after removal of the power. The second type of memory is the data memory, which stores the temporary user data, such as the result of an operation. The I/O ports allow the computer to communicate with the external world. For example, a keyboard is an input device, enabling the user to enter data to the computer. Similarly, a printer is an output device, enabling the user to print out a hard copy of data in paper form. Depending on the actual application and the requirements, a computer may include additional components, such as timers, counters, interrupt logic, clock logic, and so on.
A computer program consists of a collection of instructions for performing a specific task. In the early days of computers, programs were written in Assembly language, which was a short way of specifying instructions using words called mnemonics. Although Assembly language was fast, it had several disadvantages. Writing a long and complex program using Assembly language was difficult. More importantly, it was difficult to maintain a program written in Assembly language. Also, different processors had different instruction sets and different Assembly language instructions, resulting in no portability. Consequently, it was a tedious task to convert a program written for one processor to function on another processor. Over the last decade, nearly all programs have been written using a high level language such as C, BASIC or Pascal. High level languages have several advantages. First, learning to program in a high level language is easy. Second, the developed code is highly portable. For example, a C program written for a processor can easily be modified to work on another type of processor. This is true, even if the two processors are manufactured by different vendors. Third, high level programs are much easier to develop and maintain.
1.1 Microcontrollers and Microprocessors
A microcontroller is basically a single chip computer, generally requiring no external components. A microprocessor differs from a microcontroller in many ways. Perhaps the main difference is that a microcontroller can function as a computer without the need of any external hardware. A microprocessor, on the other hand, is just the CPU of a computer, and requires several other external components before it becomes a useful computer. Because a microcontroller consists of a single chip, its power consumption is low. The development of a microcontroller based system is also easy, as the processing hardware consists of a single chip. Perhaps the only advantage of a microprocessor over a microcontroller is that a microprocessor can easily be expanded to have more memory or I/O. The expansion of microcontrollers is more difficult and a different model is usually chosen when higher performance, more memory or more I/O are required.
Figure 1.1 shows the structure of a computer, built using a microprocessor. Here the hardware consists of several components, all attached to the microprocessor chip. The structure of a microcontroller based computer is shown in Figure 1.2. The advantages of using a microcontroller instead of a microprocessor are clear when Figures 1.1 and 1.2 are compared.
The differences between a microprocessor and a microcontroller are summarised below:
- A microprocessor is a single chip CPU microcontroller containing a CPU, memory, I/O, timers, counters and much of the remaining circuitry of a complete computer system on a single chip.
- The power consumption of a microprocessor based computer is very large, in the order of amperes. On the other hand, the power consumption of a microcontroller based computer is in the range of several hundred milliamperes. In addition, microcontrollers can be operated in sleep modes, which consume currents as low as tens of nanoamperes.
- A microprocessor based computer costs much more than a microcontroller based system.
- Because a microcontroller based system consists of a single chip, it has higher reliability.
- Microprocessor based systems can easily be expanded, for example by adding more memory or I/O chips. It is usually not possible to expand a microcontroller system. If an application requires more memory, more I/O or higher processing power, then a different model microcontroller is usually chosen.
Although microcontrollers have only been with us for a few decades, they have been used in many consumer, commercial, industrial and educational devices. Some examples are found in:
- Offices: in typewriters, computers, calculators, photocopiers, scanners, plotters, elevators, and so on;
- Homes: in microwave ovens, washing machines, alarm clocks, dish washers, hi-fi equipment, DVD players, digital televisions, and so on;
- Industry: in automatic control systems, safety systems, robotics, motor control, and so on;
- Transportation systems: in vehicles, traffic signals, road signs, speed cameras, GPS systems, and so on;
- Supermarkets: in weighing scales, cash registers, electronic signs, card readers, and so on;
- Play: in electronic toys, MP3 players, video games, mobile phones, and so on;
- Education: in electronic white-boards, photocopiers, projectors, calculators, and so on.
1.2 Evolution of the Microcontroller
The first microprocessor, named the 4004, was introduced by the Intel Corporation in 1971. This was a simple 4-bit device, supported by three other chips to make a computer; the 4001 and 4002 memory chips, and the 4003 shift register. 4004 was initially used in calculators and in simple control applications.
Shortly after the 4004 appeared in the commercial marketplace, many electronic companies realised the power and future prospects of microprocessors and so have heavily invested in this field. Three other general-purpose microprocessors were soon introduced: Rockwell International 4-bit PPS-4, Intel 8-bit 8008 and the National Semiconductor 16-bit IMP-16. These microprocessors were based on PMOS technology and can be classified as the first-generation devices.
In the early 1970s, we see the second-generation microprocessors in the marketplace, designed using the NMOS technology. The shift to NMOS technology resulted in higher execution speeds, as well as higher chip densities. During this time, we see 8-bit microprocessors such as the Motorola 6800, Intel 8080 and 8085, the highly popular Zilog Z80, and Motorola 6800 and 6809.
The third generation of microprocessors were based on HMOS technology, which resulted in higher speeds and, more importantly, higher chip densities. During 1978, we see the 16-bit microprocessors such as the Intel 8086, Motorola 68 000 and Zilog Z8000. The 8086 microprocessor was so successful that it was used in early PC designs (called PC XT).
The fourth generation of microprocessors appeared around the 1980s and the technology was based on HCMOS. During this generation we see the introduction of 32-bit devices into the marketplace. Intel introduced the highly popular 32-bit microprocessors 80 386, 80 486, and the Pentium family; and Motorola introduced the 68 020 family. The Intel processors have been used heavily in early PC designs. In parallel to the development of 32-bit microprocessors, we see the introduction of early single chip computers (later named microcontrollers) into the marketplace. The Intel 8048 was the first microcontroller, followed by the highly popular 8051 series. The 8051 device has been so popular that it is still in use today. This device was a true single chip computer, containing a CPU, data memory and erasable program memories, I/O module, timer/counter, interrupt logic, clock logic, and serial communications module, such as the Universal Synchronous Asynchronous Receiver Transmitter (USART). After the success of the 8051, we see many other companies offering microcontrollers. Today, some of the most popular general-purpose low-cost 8-bit microcontrollers are Microchip PIC series, Atmel AVR series, Motorola HC11 series, and 8051 and its derivatives.
The fifth and the current generation of microcontrollers are now based on 16-bit and 32-bit architectures (e.g. PIC32 series). It is interesting to note that currently the 8-bit microcontrollers are still popular and much more in demand. This is because of their simple architectures, low cost, low power requirements, and the availability of the vast number of hardware and software development tools. The power offered by the high-end 8-bit microcontrollers (e.g. the PIC18F series) are enough for most medium to high-speed applications, except perhaps in special cases of digital signal processing where much higher throughput is generally required.
1.3 Parts of a Microcontroller
Before explaining microcontroller architectures and programming, it is worthwhile to look at the parts of a microcontroller in more detail and understand some basic terms.
1.3.1 Address
Address is a binary pattern that is used to represent memory locations. An address bus is a collection of address lines in a processor. For example, most 8-bit microcontrollers have a 16-bit address bus, capable of addressing up to 65 536 different memory locations (0 to 65 535).
1.3.2 ALU
An arithmetic and logic unit (ALU) is part of a computer where the actual mathematical and logical operations are performed. 8-bit microcontrollers have 8-bit ALU modules. Typical operations carried out by an ALU are addition, subtraction, division, logical ...