Chapter 1

Microcomputer Systems

Introduction

A cookbook is not usually meant to be read from end to end. The reader knows what effect he or she wishes to achieve, and just browses the recipes of direct interest. So it is intended with this book. I have tried to cover all the aspects of using two of the most common and popular microcontrollers. Both of these can now be considered to be mature and well-established products which have their individual adherents and devotees. There are a lot of variants within each family to satisfy most memory/input-output/data conversion/timing needs of the users. I have taken the embedded controller market as my target, and used as many examples of hardware and software design as I thought relevant and appropriate (not just my opinion, but from many and diverse industrial colleagues).

Histories

Microcontrollers were introduced when the skills of the semiconductor industry allowed several functions such as CPU, memory and I/O to be integrated onto one piece of silicon. This in turn reduced the size (and usually the power consumption) of any microprocessor-based solution within a problem. Because of the low cost and ease of integration within an application, they are used whenever possible to reduce the chip count of a piece of electronics. The word ‘intelligent’ tends to be applied to any device which contains some sort of processing/memory capability. The intelligence, of course, belongs to the hardware and software designers who program the device.

Intel introduced the 8051 family in 1980, and from a simple microcontroller, it has grown into at least 30 different versions and been second-sourced by many manufacturers. One of the difficulties of writing a book such as this is the moving nature of the target at which I am aiming. Each week brings out new, better, faster, lower-power, larger-memory versions. I have included some of the more interesting variants – usually those which easily solve a specific problem. For example, it seems somewhat perverse to implement a serial communication channel via a digital I/O port when both products have perfectly good family members with features which can handle this task automatically. Having said that, there are occasions when it is necessary in the interests of cost or compactness to solve this problem. Thus, there are examples of code structures to do this (page 46).

The newcomer PIC from Microchip Technology was developed in the late 1980s and was marketed with the two similar versions – a PROM-based version and an EPROM version. The earlier models were smaller (0.3 inch) width and had less I/O capability. However, the manufacturers came up with a cheap programmer which included assembler and simulator software. This immediately gave them a market advantage, since one of the difficulties when a designer considers a new microprocessor is the cost of the development system. It is one thing to have to learn a new structure and instruction set, without the bother of having to fight the budget holders for the cost of the hardware as well. So, for around £100, an engineer could obtain enough hardware and software to evaluate the product effectively. The product family developed, and the company now have a considerable market share.

Brief Comparisons

8051

The 8051 was introduced to replace the older 8048 family which was originally used as a keyboard handler for IBM PCs. The original product lineup was as follows:

ROM-based 8051 The program memory is on-chip and is specified by the user. The manufacturer mask-programs the silicon die so that the CPU can only execute the one program. There is a cost advantage if the IC is bought in sufficient quantities.

EPROM-based 8751 This variant is used mostly for development or very small production runs. It is quite an expensive item in one-off costs, but has the advantage that the program can be erased and a new version ‘blown’ into the internal memory.

ROMless 8031 This needs external memory (EPROM) to hold the program. To access the memory, the 8031 has to use some of its input/output (I/O) ports. This means that an 8031-based microcontroller has only 14 I/O lines left to directly interface to the world.

When referring to the family, most engineers simply refer to the 8051. It was introduced at a time when a single +5 V supply was a pleasant relief to digital design engineers. The original 40-pin DIL package was easily configured and the availability of 4 × 8-bit ports was pure luxury.

The basic device was blessed with:

• 128 bytes of on-chip RAM (expandable to 64 kbytes externally)

• 32 I/O lines

• two 16-bit counter timers

• 6 sources of program interrupt (each vectoring (jumping) to 6 different addresses and with priorities set by the programmer)

• Full duplex serial port (full duplex = the ability to simultaneously receive and transmit serial data).

PIC

The original 8-bit PIC microcontroller was introduced with a small number of variants with a choice of I/O ranging from the 13-line 16C54 to the 21-line 16C57. These were originally conceived as One Time Programmable (OTP) or as EPROM-based versions. An attraction of the plastic OTP version was that it was very cheap. The EPROM version, as in all microcontrollers, is relatively expensive. This is because of the expense of the ceramic body needed to be formed around the quartz UV transparent window which is used to erase the memory. The smaller package sizes were an interesting development, coming as they did in the 0.3 inch ‘skinny DIP’ IC. The larger I/O configurations reverted to the same 0.6 inch wide package as the 8051 for the DIL IC. All devices are available in other packages such as flatpack, leadless chip carrier, plastic leaded chip carrier (PLCC), small outline IC (SOIC), plastic shrink small outline (SSOP) and other variations on these themes. In this book, I will concentrate on Dual In Line ICs.

Like the 8051, there are now so many versions of the device, that almost any memory or interface requirement can be catered for. However, the basic PIC comes equipped with:

• small, compact instruction set (33 or 35 instructions)

• 32 bytes of RAM

• 13/21 I/O pins

• one 8-bit Real Time Clock Counter.

Written like this, the basic PIC seems to be very underequipped when compared with the basic 8051, but it’s very much a case of choosing the right version. This will be dealt with in the PIC section.

Microprocessors are fairly stupid machines. They are capable of performing very simple tasks very quickly. It is this relative speed that gives them the reputation for ‘intelligent’ or ‘smart’ functions. They all have certain characteristics in common, and this section looks at these common functions before specializing in the two specific families.

Microprocessors fetch instruction codes from memory, find out what that instruction is commanding it to do, and then they do it. This is formally called the ‘FETCH-EXECUTE CYCLE’. The three main areas of microprocessor-based systems are the

• CPU Central Processing Unit

• Memory Read Only or Read/Write

• I/O Input/Output.

Instructions can cause

• Memory ↔ CPU data transfer

• I/O ↔ CPU data transfer

• Data manipulation within the CPU.

Microprocessors can be called 4-, 8-, 16-, 32- or even 64-bit machines. This characterization refers to the number of bits in a data word, i.e. the ‘width’ or size of data that is handled in one operation. (However, even this simple definition doesn’t cover all situations: the Intel 8088 reads data in from memory in 8-bit chunks but deals with it internally in 16-bit words.) The most common term is the ‘byte’ or 8 bits of data. Half of this is the ‘nibble’. A general-purpose term which does not need to be too specific about the size of the data is the ‘word’.

Internally, all microprocessors have ‘registers’ which are capable of holding a data word. The number of registers depends on the type of processor. Data in a register can be transferred to another register, a location in memory, or to an input/output device. One register which is common to all microprocessors is the Program Counter. This always holds the memory address of the next instruction to be executed. Another common register is the Instruction Register. This is where each instruction is held while it is being decoded. After that, the particular action to take place depends on the microprocessor.

The Arithmetic and Logic Unit is another common element in all microprocessors. This device allows data in registers or memory to be compared or subjected to various arithmetic/logical operations such as addition, subtraction, multiplication, division, logical ‘AND’ing, ‘OR’ing, ‘NOT’ing or ‘EXCLUSIVE-OR’ing. Appendix B explains these logic operations and their various uses.

There are many software examples in this book, but not many complete programs. When trying to get the hang of a new microprocessor, I have always found that the example software almost, but never quite, solves the problem I am wrestling with; or that the author has tackled it in a different way to the way I would have gone about it. Thus, in this book, I have shown how to achieve certain effects without getting too specific about the nature of the problems. The best source of full examples is over the Internet. Sites are available at:

The amount of software at these sites is huge. There are examples of all sorts. However, I hope that with this book, you will be able to start appreciating the potential and capabilities of these devices. An internet search on ‘8051’ or ‘PIC’ will turn up links to example code and assemblers/simulators and compilers from a diverse range of high level languages such as C, BASIC and FORTH. One such site is www.idiom.com/free-compilers/.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.102.112