Title Page




Chapter 1: Introduction to Microcontrollers and Display Systems

1.1 Microcontrollers and Microprocessors

1.2 Evolution of the Microcontroller

1.3 Parts of a Microcontroller

1.4 Display Devices

1.5 Summary


Chapter 2: PIC18F Microcontrollers

2.1 The PIC18F2410 Microcontroller

2.2 PIC18F2410 Architecture

2.3 Summary


Chapter 3: C Programming Language

3.1 C Languages for Microcontrollers

3.2 Your First mikroC Pro for PIC Program

3.3 Functions in mikroC Pro for PIC

3.4 mikroC Pro for PIC Built-in Functions

3.5 mikroC Pro for PIC Libraries

3.6 Using the mikroC Pro for PIC Compiler

3.7 Using the mikroC Pro for PIC Simulator

3.8 Other mikroC Pro for PIC Features

3.9 Summary


Chapter 4: PIC Microcontroller Development Tools – Including Display Development Tools

4.1 PIC Hardware Development Boards

4.2 PIC Microcontroller Display Development Tools

4.3 Using the In-Circuit Debugger with the EasyPIC7 Development Board

4.4 Summary


Chapter 5: Light Emitting Diodes (LEDs)

5.1 A Typical LED

5.2 LED Colours

5.3 LED Sizes

5.4 Bi-Colour LEDs

5.5 Tri-Colour LEDs

5.6 Flashing LEDs

5.7 Other LED Shapes

5.8 7-Segment LEDs

5.9 Alphanumeric LEDs

5.10 mikroC Pro for PIC 7-Segment LED Editor

5.11 Summary


Chapter 6: Liquid Crystal Displays (LCDs) and mikroC Pro for PIC LCD Functions

6.1 HD44780 Controller

6.2 Displaying User Defined Data

6.3 DDRAM Addresses

6.4 Display Timing and Control

6.5 LCD Initialisation

6.6 Example LCD Display Setup Program

6.7 mikroC Pro for PIC LCD Functions

6.8 Summary


Chapter 7: Graphics LCD Displays (GLCD)

7.1 The 128 × 64 Pixel GLCD

7.2 Operation of the GLCD Display

7.3 mikroC Pro for PIC GLCD Library Functions

7.4 Example GLCD Display

7.5 mikroC Pro for PIC Bitmap Editor

7.6 Adding Touch-screen to GLCDs

7.7 Summary


Chapter 8: Microcontroller Program Development

8.1 Using the Program Description Language and Flowcharts

8.2 Examples

8.3 Representing for Loops in Flowcharts

8.4 Summary


Chapter 9: LED Based Projects

9.1 PROJECT 9.1 – Flashing LED

9.2 PROJECT 9.2 – Binary Counting Up LEDs

9.3 PROJECT 9.3 – Rotating LEDs

9.4 PROJECT 9.4 – Wheel of Lucky Day

9.5 PROJECT 9.5 – Random Flashing LEDs

9.6 PROJECT 9.6 – LED Dice

9.7 PROJECT 9.7 – Connecting more than one LED to a Port Pin

9.8 PROJECT 9.8 – Changing the Brightness of LEDs

9.9 PROJECT 9.9 – LED Candle

9.10 Summary


Chapter 10: 7-Segment LED Display Based Projects

10.1 PROJECT 10.1 – Single Digit Up Counting 7-Segment LED Display

10.2 PROJECT 10.2 – Display a Number on 2-Digit 7-Segment LED Display

10.3 PROJECT 10.3 – Display Lottery Numbers on 2-Digit 7-Segment LED Display

10.4 PROJECT 10.4 – Event Counter Using 4-Digit 7-Segment LED Display

10.5 PROJECT 10.5 – External Interrupt Based Event Counter Using 4-Digit 7-Segment LED Display with Serial Driver

10.6 Summary


Chapter 11: Text Based LCD Projects

11.1 PROJECT 11.1 – Displaying Text on LCD

11.2 PROJECT 11.2 – Moving Text on LCD

11.3 PROJECT 11.3 – Counting with the LCD

11.4 PROJECT 11.4 – Creating Custom Fonts on the LCD

11.5 PROJECT 11.5 – LCD Dice

11.6 PROJECT 11.6 – Digital Voltmeter

11.7 PROJECT 11.7 – Temperature and Pressure Display

11.8 PROJECT 11.8 – The High/Low Game

11.9 Summary


Chapter 12: Graphics LCD Projects

12.1 PROJECT 12.1 – Creating and Displaying a Bitmap Image

12.2 PROJECT 12.2 – Moving Ball Animation

12.3 PROJECT 12.3 – GLCD Dice

12.4 PROJECT 12.4 – GLCD X-Y Plotting

12.5 PROJECT 12.5 – Plotting Temperature Variation on the GLCD

12.6 PROJECT 12.6 – Temperature and Relative Humidity Measurement

12.7 Operation of the SHT11

12.8 Acknowledgement

12.9 Summary


Chapter 13: Touch Screen Graphics LCD Projects

13.1 PROJECT 13.1 – Touch Screen LED ON-OFF

13.2 PROJECT 13.2 – LED Flashing with Variable Rate

13.3 Summary


Chapter 14: Using the Visual GLCD Software in GLCD Projects

14.1 PROJECT 14.1 – Toggle LED

14.2 PROJECT 14.2 – Toggle more than One LED

14.3 PROJECT 14.3 – Mini Electronic Organ

14.4 PROJECT 14.4 – Using the SmartGLCD

14.5 PROJECT 14.5 – Decimal to Hexadecimal Converter using the SmartGLCD

14.6 Summary


Chapter 15: Using the Visual TFT Software in Graphics Projects

15.1 PROJECT 15.1 – Countdown Timer

15.2 PROJECT 15.2 – Electronic Book

15.3 PROJECT 15.3 – Picture Show

15.4 Summary




Title Page


A microcontroller is a single chip microprocessor system, which contains data and program memory, serial and parallel I/O, timers, and external and internal interrupts, all integrated into a single chip that can be purchased for as little as £2.00. About 40% of microcontroller applications are in office automation, such as PCs, laser printers, fax machines, intelligent telephones, and so on. About one-third of microcontrollers are found in consumer electronic goods. Products such as CD players, hi-fi equipment, video games, washing machines, cookers and so on fall into this category. The communications market, automotive market and the military share the rest of the application areas.

Input and output are very important parts of any microcontroller system. Typical input devices are push-button switches, keypads and various analog and digital sensors. Typical output devices are Light Emitting Diodes (LEDs), Liquid Crystal Displays (LCDs), Graphics Liquid Crystal Displays (GLCDs), motors, actuators, buzzers, and so on. This book is about the theory and applications of display devices in microcontroller based systems. The book explains briefly the theory of the commonly used display devices, namely LEDs, 7-Segment LED displays, LCDs, monochrome GLCDs and TFT based colour LCDs. In addition, the use of each display device is explained with several working and tested projects. The description, block diagram, circuit diagram, operation and full program code of all the projects are given. PIC18F series of high-end microcontrollers are used in all the projects. The projects are developed using the highly popular mikroC Pro for PIC compiler. Knowledge of the C programming language will be useful. Also, familiarity with at least one member of the PIC16F series of microcontrollers will be an advantage. The knowledge of assembly language programming is not required because all the projects in the book are based on using the C language.

This book is written for students, for practising engineers and for hobbyists interested in developing display based projects using the PIC series of microcontrollers.

Chapter 1 presents the basic features of microcontrollers and the basic features of display devices used in such systems.

Chapter 2 provides a review of the PIC18 series of microcontrollers. Various features of these microcontrollers are described in detail. The PIC18F2410 is chosen as a typical microcontroller.

Chapter 3 provides a short tutorial on the C language and then examines the features of the mikroC Pro for PIC compiler used in PIC series of microcontrollers.

Chapter 4 is about the important topic of microcontroller development tools. Both the software and hardware development tools are described in detail. In addition, the use of microcontroller simulators and in-circuit debuggers are described with examples.

Chapter 5 provides the basic theory of LEDs. The use of simple LEDs and 7-Segment simple and multiplexed LEDs are explained with examples.

Chapter 6 provides some simple projects using the PIC18 series of microcontrollers and the mikroC Pro for PIC C language compiler. All the projects in this chapter are based on the PIC18F452 microcontroller and all the projects have been tested and are working. This chapter should be useful for those who are new to PIC microcontrollers, and for those who want to extend their knowledge of programming PIC18F series of microcontrollers using the mikroC Pro for PIC language.

Chapter 7 covers the theory of LCD displays. The basic working principles of LCDs and the mikroC Pro for PIC built-in LCD functions are explained with several examples.

Chapter 8 is about the Program Development Language (PDL) used to describe the operation of software in general. Various building blocks of the PDL are described in this chapter.

Chapter 9 provides simple LED based projects, ranging from LED flashing to more complex LED projects.

Chapter 10 is about 7-Segment LED based projects. Several single digit and multiplexed working and tested projects are given in this chapter with full source code.

Chapter 11 provides several text based LCD projects. The use of LCDs is described in this chapter through simple and complex projects, ranging from displaying simple text on an LCD to developing an LCD based voltmeter project.

Chapter 12 is about the use of GLCDs in microcontroller projects. The use of standard monochromatic 128 × 64 pixel GLCD is used in the projects in this chapter.

Touch screen displays are important application areas of microcontrollers. Chapter 13 gives several projects on using touch screens in graphics applications.

The Visual GLCD software package is used for the development of projects based on several different types of monochromatic GLCD displays. Chapter 14 explains the use of this software package and gives the steps required to develop GLCD based applications. Several projects are given in this chapter using the Visual GLCD software package with both 128 × 64 pixel and 240 × 128 pixel GLCD displays.

Finally, Chapter 15 is about the Visual TFT software package used for the development of TFT based colour graphics applications. The chapter describes the steps required to create microcontroller based TFT graphics applications using the MikroMMB graphics development board.

Dogan Ibrahim
London, 2012


The following material is reproduced in this book with the kind permission of the respective copyright holders and may not be reprinted, or reproduced in any way, without their prior consent.

Figures 2.1–2.6, 2.10, 2.11, 2.13, 2.17, 2.28, 2.30, 2.32–2.37 are taken from Microchip Technology Inc. Data Sheet PIC18F2X1X/4X1X (DS39636D). Figures 4.2–4.4 are taken from the web site of Microchip Technology Inc.

Figure 4.1 is taken from the web site of microEngineering Labs Inc.

Figure 4.5 and 4.6 are taken from the web site of Custom Computer Services Inc.

Figure 4.7 is taken from the web site of Futurlec Inc.

Figures 4.8 and 4.9 are taken from the web site of mikroElektronica.

PIC®, PICSTART® and MPLAB® are all trademarks of Microchip Technology Inc.

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.

Figure 1.1 Structure of a microprocessor based computer


Figure 1.2 Structure of a microcontroller based computer


The differences between a microprocessor and a microcontroller are summarised below:

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:

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 ANDing, ORing, Exclusive-OR and comparison. Some ALUs can also perform signed or unsigned multiplication.

1.3.3 Analogue Comparator

Some microcontrollers have built-in analogue comparator modules. An analogue comparator module is used to compare the voltage levels of two analogue signals. Although this feature is implemented in most mid-range PIC microcontrollers, it is not an important functionality.

1.3.4 Analogue-to-Digital Converter

Analogue-to-digital converter (A/D converter) is used to convert an analogue input signal into digital form, so that the signal can be processed within the microcontroller. Most mid-range PIC microcontrollers have built-in A/D converter modules. In general purpose and low-speed applications, the A/D converters are 8 to 10 bits, having 256 or 1024 quantisation levels. An A/D converter can either be unipolar or bipolar. Unipolar converters can only handle signals that are always positive. Bipolar converters, on the other hand, can handle both positive and negative signals. The A/D converters implemented in PIC series of microcontrollers are unipolar. The A/D conversion process is started by the user program and the conversion can take tens of processor cycles to complete. The user program has the option of either polling the conversion status and waiting until the conversion is complete, or alternatively, the A/D converter completion interrupt can be enabled to generate an interrupt as soon as the conversion is complete.

1.3.5 Brown-out Detector

Brown-out detectors in microcontrollers is a feature that can be configured to reset a microcontroller if the power supply voltage falls below a nominal value. The brown-out detector is a safety feature, as it protects the microcontroller data or the program from being corrupted while working below the recommended supply voltage.

1.3.6 Bus

A bus is a collection of wires grouped together in terms of their functions. An 8-bit conventional microprocessor usually has three buses: address bus, data bus and control bus. Memory and I/O addresses are sent over the uni-directional address bus. Data and instructions from the memory are sent over the bi-directional data bus. Processor control signals are sent over the uni-directional control bus. Some microprocessors have an additional I/O bus, where the I/O device addresses are sent.

1.3.7 CAN

CAN bus is used in the automotive industry. Some microcontrollers include CAN bus modules, which simplify the design of CAN bus based products. For example, the PIC18F4680 provides CAN interface.

1.3.8 CISC

CISC is also known as the Complex Instruction Computer. In CISC architecture, both data and instructions are of the same width (e.g. 8-bits wide) and the microcontroller usually has over 200 instructions. Data and instructions are on the same bus and cannot be fetched at the same time.

1.3.9 Clock

A clock is basically a square wave signal used to provide timing signals to a digital processor. A clock is generated either using external devices (e.g. crystal, resistor-capacitor etc.), or some microcontrollers have built-in clock generation circuits. The PIC18F microcontroller family can operate with clock frequencies of up to 40 MHz. The basic instruction cycle in a PIC microcontroller takes four clock cycles. Thus, the effective operating frequency, or the MIPS (Millions of Instructions per Second) value is equal to the clock frequency divided by four, that is 10 MIPS.

1.3.10 CPU

The central processing unit (CPU), is the brain of a computer system, administering all activity in the system and performing all operations on data. The CPU consists of the ALU, several registers, and the control and synchronisation logic. The CPU fetches instructions from memory, decodes these instructions, and finally executes them. Decoding an instruction is the process of deciding what control signals to send to other internal parts of the computer for the successful execution of the instruction.

1.3.11 EEPROM

The electrically erasable programmable read only memory (EEPROM) is a non-volatile memory that can be erased and reprogrammed using a suitable programming device. EEPROMs are used in microcontroller based systems to store semi-permanent data, such as configuration data, maximum and minimum values, identification data, setup data, and so on. Most PIC microcontrollers have built-in EEPROM memories. One disadvantage of these memories is their much slower write times than their read times.

1.3.12 EPROM

The erasable programmable read only memory (EPROM) can be programmed and erased. An EPROM memory chip has a small clear-glass window on top of the chip, where the data can be erased under strong ultraviolet light in a few minutes. An EPROM is programmed by inserting the chip into a socket of an EPROM programmer device, which is connected to a PC. After programming the chip, the window can be covered with dark tape to prevent accidental erasure of the data, for example under direct sunlight. An EPROM must be erased before it can be re-programmed. EPROM memories are commonly used during the program development time where the programs keep changing until finalised. Some versions of EPROMs are known as One Time Programmable (OTP), which can be programmed only once but cannot be erased.

1.3.13 Ethernet

The Ethernet interface enables a microcontroller to be connected to a local area network, and in addition provides Ethernet interface capabilities. A microcontroller with such an interface can be connected to the Internet and can send and receive TCP/IP based packets. Some microcontrollers, such as the PIC18F97J60, have built-in Ethernet capabilities.

1.3.14 Flash Memory

Flash memory is a non-volatile memory used mainly to store user programs. This type of memory can be programmed electrically while embedded on the board. Some microcontrollers have only 1 KB flash memory, while some others can have 32 KB or more. In addition to computers, flash memory is also used in mobile phones and digital cameras.

1.3.15 Harvard Architecture

This is a type of CPU where the program memory and data memory units and buses are separate. The result is that the processor can fetch instructions and data at the same time, thus increasing the performance. Several microcontrollers, including the PIC family, are designed using the Harvard architecture.

1.3.16 Idle Mode

This mode is similar to the sleep mode and is used to conserve power. In idle mode, the internal oscillator is off but the peripheral devices are on.

1.3.17 Interrupts

Interrupts cause a microcontroller to respond to external or internal events in the shortest possible time. An internal interrupt usually comes from the timer module, where an interrupt can be generated whenever a timer overflows. Thus, events can be scheduled to happen at regular intervals. External interrupts usually come from the microcontroller I/O ports. For example, the microcontroller can be configured to create an interrupt when the state of a port pin changes its value. When an interrupt occurs, the microcontroller leaves its normal flow of program execution and jumps to the Interrupt Service Routine (ISR). At this point the code inside the ISR is executed and at the end of this code the program returns and continues to execute the code just before the interrupt occurred. The ISR is usually at a fixed address of the program memory, known as the interrupt vector address. Some microcontrollers have priority based interrupt sources, with different interrupt vector addresses for different sources.

1.3.18 LCD Drivers

Some microcontrollers offer LCD drivers and interface signals, so that standard LCD modules can be directly connected. Since all of the LCD functions can be implemented in software, such microcontrollers are not popular.

1.3.19 Pipelining

Pipelining is a technique used in computer systems to overlap the instruction fetch time with execution time. This allows higher throughput as two operations are performed in parallel. In microcontrollers, pipelining is generally used to fetch the next instruction while executing the current instruction. PIC microcontrollers use two-stage pipelining to speed up the execution time.

1.3.20 Power-on Reset

The power-on reset circuit keeps the microcontroller in the reset state until all the internal circuitry has been initialised. This is important, as it places the microcontroller clock into a known state. The power-on reset can be enabled or disabled during programming of PIC microcontrollers.

1.3.21 PROM

Programmable read only memory (PROM) is a non-volatile memory similar to a ROM. But PROM can be programmed by the end user with the aid of a PROM programmer device. PROM can only be programmed once and its contents cannot be changed after programming the device.

1.3.22 RAM

Random access memory (RAM) is a general purpose read-write memory used to store temporary data in a program. RAM is a volatile memory where the stored data is cleared after the power is turned off. All microcontrollers have some amount of RAM. Some may have only a few hundred bytes, while others can have up to 4 KB or more.

1.3.23 Real-time Clock

A real-time clock enables a microcontroller to receive absolute date and time information. Some microcontrollers have built-in hardware real-time clock modules. In general, an external real-time clock chip can be connected to general purpose microcontroller I/O ports to receive the absolute date and time information.

1.3.24 Register

A register is a volatile, temporary high-speed storage for data. All microcontrollers have some amount of registers. Some microcontrollers, such as the PIC family, have a Special Function Register (SFR), used to hold the configuration data for various functions of the microcontroller. For example, the I/O direction registers hold the direction of each I/O pin. Similarly, the PORT registers hold the data received from a port, or data to be sent to an I/O port.

1.3.25 Reset

All microcontrollers have reset facilities. A reset action can be automatic by software (e.g. when the watchdog is enabled but not refreshed), or an external button can be used to reset the microcontroller. Reset puts the microcontroller into a known state. Usually, after a reset, the program starting from memory address 0 of the microcontroller is executed.

1.3.26 RISC

In a Reduced Instruction Set Computer (RISC) microcontroller, the data and instructions are not usually of the same width. For example, in an 8-bit RISC microcontroller, the data is 8-bits but the instructions can be 12, 14 or 16 bits wide. RISC microcontrollers have a limited number of instructions (e.g. not more than 50).

1.3.27 ROM

Read only memory (ROM) is non-volatile and is used to store user programs. A ROM is normally programmed in the factory during the manufacturing process. ROM is not re-programmable and its contents cannot be erased. ROM is normally used when a program has been tested and is working correctly, and it is desired to make thousands of copies of the same program.

1.3.28 Serial Input-Output

Serial ports on a microcontroller enable communication using the RS232 protocol. For example, the microcontroller can be connected to a PC via its serial port and then data can be exchanged between the microcontroller and the PC. Although serial communication can be implemented in software, most microcontrollers have built-in USART modules to read and write serial data through its ports. Most mid-range PIC microcontrollers are equipped with at least one USART module.

1.3.29 Sleep Mode

Some microcontrollers have built-in sleep modes where, in this mode, the internal oscillator is stopped. The reason for using this mode is to reduce the power consumption to a very low level. In this mode all the microcontroller internal circuitry and the peripheral devices are in the off state. The microcontroller is usually woken up from sleep mode by an external reset or a watchdog time-out.

1.3.30 Supply Voltage

Most microcontrollers operate with the standard logic voltage of +5 V. The range of acceptable voltage is usually in the range +4.75 to +5.25 V. The manufacturers' data sheets usually give the acceptable power supply voltage limits. PIC18F microcontrollers can operate with a power supply of +2 to +5.5 V. The required power supply voltage is usually obtained using a regulated power supply. In portable applications, the +5 V supply is obtained using a +9 V battery with a +5 V regulator chip (e.g. 78L05).

1.3.31 Timers

Timers are used in timing and counting applications. Most microcontrollers are equipped with at least one, and in many cases, several timers. A timer is usually 8 or 16 bits wide. Data is loaded into the timer under program control. The timer counts up at each clock pulse (or every time an external event occurs), and when the timer overflows an interrupt is generated (if interrupts are enabled). One common application of timers is to generate delays in programs, or to schedule events at regular intervals.

1.3.32 USB

USB is a powerful high-speed communications port used to connect various devices together. Some microcontrollers include built-in USB modules, which simplify the USB based communications. For example, the PIC18F2 × 50 microcontroller has a built-in USB module.

1.3.33 Watchdog

A watchdog is basically a programmable timer circuit that can be refreshed by the user program. It is usually used in real-time, and time based applications where time critical modules of a program are used to refresh the watchdog. If the watchdog fails to be refreshed, this is a sign that a time critical module has not completed its task. An automatic software reset occurs if the watchdog is enabled but is not refreshed. The watchdog is a safety feature, used to detect loops and runaway code in programs.

1.4 Display Devices

Display devices are output devices that can be connected to I/O ports of microcontrollers. Most electronic equipment, whether consumer related, commercial or industrial, have some form of display device, for example, mobile phones, calculators, GPS systems, printers, computers, MP3 players, microwave ovens, and so on.

In this section we are only concerned with small display devices commonly used in microcontroller based projects. In general, we can divide these display devices into three groups: LED based, OLED based and LCD based.

1.4.1 LED

Light Emitting Diode (LED) based displays are further divided into two groups: Simple LED based and 7-segment LED based. Simple LED devices (see Figure 1.3) consist of a single or an array of LEDs, commonly used in applications to indicate the status of something, for example, the on/off status of an electronic device, the selection of an item, and so on. Simple LEDs are available in various colours, such as red, green, orange, blue and white, and are directly connected to I/O ports of microcontrollers via current limiting resistors.

Figure 1.3 Simple LEDs


1.4.2 7-Segment LED

7-segment LEDs (see Figure 1.4) are generally used to display numeric data. The numbers are made up of 7 segments and the required number is displayed by turning on or off the appropriate segments. There are two types of 7-segment displays: common-anode or common-cathode. In common-anode displays, the anode pin is connected to the supply voltage and the individual segments are turned on by grounding the required segment. In a common-cathode type display, the cathode is connected to ground and the individual segments are turned on by applying voltage to the required segment. Both types can easily be connected and driven from a microcontroller I/O pin. To display numbers between 0 and 9, a single digit is used. To display higher numbers, it is necessary to use multiple digits (see Figure 1.5). In multi-digit applications, each digit is turned on or off by controlling its common pin. The digits are enabled and disabled alternately, and very fast in such a way that when viewed the user thinks that the display is stationary.

Figure 1.4 7-segment display


Figure 1.5 7-segment multiplexed 4-digit display


1.4.3 OLED

Organic Light Emitting Diode (OLED) displays can be used to display text as well as graphical images. These displays are constructed by inserting organic material between a pair of electrodes where at least one of the electrodes is transparent. When an electric current is applied to the two conductors, a bright, electro-luminescent light is produced from the organic material. There are two types of OLEDs, as far as the used material is concerned: those based on small molecules and those employing polymers. OLED displays work without a backlight and thus they can be used both outdoors and indoors in low ambient light conditions.

OLEDs have several advantages compared to other displays:

OLEDs have some disadvantages compared to other displays:

1.4.4 LCD

The Liquid Crystal Display (LCD) is one of the most commonly used displays today. There are basically three types of LCDs as far as the type of data that can be displayed is concerned: Segment LCD, Dot Matrix LCD and Graphic LCD.

Segment LCD is also known as the alphanumeric LCD. These LCDs can display numbers represented by 7 segments, or numbers and Roman letters represented by 14 or 16 segments. In addition, symbols can also be displayed. The segment LCDs are limited to displaying numbers, text and symbols. If we need to display other characters or shapes, then either a dot matrix display or a graphic display should be used. Figure 1.6 shows a typical 16-segment LCD display.

Figure 1.6 16-segment LCD display


Dot Matrix LCD is also known as the character LCD. The most commonly used dot matrix LCD displays are 2 lines of 16 characters. Each character is represented by 5 × 7 dots (or 5 × 8 characters including the cursor). Dot matrix LCDs can display alphanumeric data, including a subset of symbols. Figure 1.7 shows a typical dot matrix LCD display.

Figure 1.7 Dot matrix LCD display


Graphic LCDs are composed of pixels and provide the greatest flexibility to the user. In a graphic LCD, pixels are arranged in rows and columns and each pixel can be addressed individually. Graphic LCDs are used when we need to display numbers, letters, symbols, shapes or pictures. Figure 1.8 shows a typical graphics LCD display.

Figure 1.8 Graphics LCD display


LCD displays produce no light of their own and so require an external light source to be visible. On some displays, a cold cathode fluorescent lamp is inserted behind the LCD panel. On some other models, the ambient light is used to make the display visible.

LCD displays use the light modulating properties of liquid crystals. In a standard LCD display, a layer of molecules are aligned between two transparent Tin Oxide electrodes and two polarising filters placed at right angles to each other, as shown in Figure 1.9. Ambient light enters the LCD through the front polarising filter. The light then passes through the liquid crystals, which rotate the light passing through them. This rotation is usually 90 degrees in most type of LCDs. In the OFF state, since the light is rotated, it passes through the second polarising filter. Applying a voltage across the electrodes (ON state) orients the liquid crystals so that they are parallel to the electric field and the twisted structure disappears. Thus, the light is no longer rotated and light passing through the second polariser in the crossed shape is absorbed, thus causing the activated portion of the display to appear dark.

Figure 1.9 Operation of an LCD


LCD displays can be classified as Passive Matrix and Active Matrix, depending upon the pixel addressing scheme used. A pixel matrix is addressed by rows and columns. In a passive display, transistors are used to activate rows and columns, not each pixel. In an active display, on the other hand, transistors are used at each red, green and blue pixel to keep the pixel at the desired intensity. In general, passive matrix displays are less costly and have narrower viewing angles than active matrix displays. Active matrix displays are sharper, have more contrast than passive displays, and also have faster response times.

There are many types of LCD displays, depending upon the amount and type of twisting used in liquid crystals. Some examples are: TN (Twisted Nematic −90° Twist), STN (Supertwisted Nematic −270° Twist), FSTN (Film Compensated STN), DSTN (Double Layer STN), and so on.

One of the LCD displays that has become popular recently is the (TFT (Thin Film Transistor) LCD, used in most mobile phones, laptop monitors and desktop computer monitors. TFT is an active matrix display providing the best resolution of all the LCD types, but it is also the most expensive type. In a TFT display, the transistors are made from a thin film of amorphous silicon deposited on a glass panel. TFT displays offer excellent response times, and sharp and crisp images. Some TFT displays are incorporated with touch screen hardware panels that enable the user to make a selection by touching the appropriate places on the screen. LCD Viewing Modes

Reflective: In this mode, LCDs use ambient light to illuminate the display and are therefore more suitable for outdoor use.

Transmissive: In this mode, LCDs use ambient light to illuminate the display and are therefore more suitable for indoor use.

Transflective: Transflective mode includes both reflective and transmissive types, so can be used both indoors and outdoors. Key Specifications of LCDs

Resolution: Number of pixels, measured in horizontal and vertical (e.g. 1024 × 768);

View size: The diagonal size of the LCD display;

Dot pitch: The distance between two adjacent same colour pixels. The dot pitch is either specified as the number of dots per inch, or the distance is given in millimetres (e.g. 0.25 mm). The smaller the dot pitch size (or higher the number of dots per inch), the sharper the image becomes;

Response time: The minimum time it takes to change a pixel's brightness (or colour). The response time is measured in milliseconds and typical values are several milliseconds. A low response time is always desirable;

View angle: The angle from which the LCD can be viewed without loss of any detail;

Brightness: The amount of light emitted from the display;

Contrast ratio: The ratio of the luminance of the brightest colour (white) to that of the darkest colour (black). A high contrast ratio is a desirable feature of any display;

Aspect ratio: The ratio of the width of the LCD to its height (e.g. 16: 9, 4: 3, etc.)

1.5 Summary

This chapter has provided an introduction to the microcontroller and microprocessor based computer systems. The differences between the two types of computer systems have been explained in detail. In addition, some of the most commonly used concepts in microcontrollers have been described.

The final part of the chapter has provided an introduction to the display systems used in microcontroller based applications. An explanation of the important terms used in displays has also been given.


1.1 What is a microprocessor?

1.2 What is a microcontroller? Explain the differences between a microprocessor and a microcontroller.

1.3 Where would you use a flash memory?

1.4 Where would you use RAM memory?

1.5 What is an A/D converter? Give an example for its use in a microcontroller based application.

1.6 What is the purpose of the watchdog module in a microcontroller?

1.7 What happens when a microcontroller is reset?

1.8 How many types of LCDs are there? Which one would you choose if the number of I/O ports is limited?

1.9 What is a graphics LCD? Give an example for its use in practise.

1.10 Explain the operation of passive and active display technologies.

1.11 What is a TFT display? Why are TFT displays popular? In which type of applications are they commonly used?

1.12 What is an OLED display? Explain its operation. What are the differences between a TFT and an OLED display?

1.13 What are the advantages of touch screen displays? Give an example of touch screen based application.