The 8051


 
<-Previous
   
  Introduction
   
 
I think there is a world market for maybe five computers.
- Thomas Watson, Chairman of IBM, 1943
   
 
There is no reason anyone would want a computer in their home.
- Ken Olson, President of Digital Equipment Corporation, 1977
   
 
One of the more surprising developments of the last few decades has been the ascendance of computers to a position of prevalence in human affairs. Today there are more computers in our homes and offices than there are people who live and work in them. Yet many of these computers are not recognized as such by their users.
- Programming Embedded Systems in C and C++, Michael Barr, 1999
   
 
  "An embedded system is a combination of computer hardware and software, and perhaps additional mechanical or other parts, designed to perform a specific function." - Programming Embedded Systems in C and C++, Michael Barr, 1999
   
  The Oxford Dictionary says a robot is "1 a machine with a human appearance or functioning like a human. 2 a machine capable of carrying out a complex series of actions automatically. 3 a person who works mechanically and efficiently but insensitively."
   
  Webopedia says a robot is "(1) a device that responds to sensory input. (2) A program that runs automatically without human intervention. Typically, a robot is endowed with some artificial intelligence so that it can react to different situations it may encounter."
   
 
   
 
Basic Microprocessor System/Microcontroller Block Diagram
   
  As we shall see, much of the work performed by the CPU involves reading from and writing to memory. There are three busses involved in accessing memory: the address bus, the data bus and the control bus. The function of each of these busses is illustrated in EdSim51's Read and Write Cycle Simulations.
   
  Read Cycle
  The steps involved in the read cycle are:
 
  • CPU places address on address bus.
  • Control signals memory - address on address bus is valid.
  • Memory chip fetches data from location specified by the address and places on the data bus.
  • Control signals CPU - data on data bus is valid.
  • CPU takes data from data bus
  Write Cycle
  The steps involved in the write cycle are:
 
  • CPU places address on address bus.
  • Control signals memory - address on address bus is valid.
  • CPU places data on the data bus.
  • Control signals memory - data on data bus is valid.
  • Memory chip takes data from data bus and places it in the location specified by the address.
   
 

An embedded system is made up of the basic functional blocks shown above. The Central Processing Unit (CPU) is the microprocessor and can be thought of as the system's brain. Memory, input ports and output ports are connected to the microprocessor through an address bus, a data bus and a control bus. Ports are physical interfaces through which data is sent to and from external peripherals such as keyboards, displays, etc.

   
 
Three Basic Elements of a Microprocessor
   
  A microprocessor has three basic elements, as shown above. The ALU performs all arithmetic computations, such as addition, subtraction and logic operations (AND, OR, etc). It is controlled by the Control Unit and receives its data from the Register Array.
  The Register Array is a set of registers used for storing data. These registers can be accessed by the ALU very quickly. Some registers have specific functions - we will deal with these later.
  The Control Unit controls the entire process. It provides the timing and control signals for getting data into and out of the registers and the ALU and it synchronizes the execution of instructions (we will deal with instruction execution at a later date).
   
  What's the difference between a microprocessor and a microcontroller?
  A microprocessor system consists of a microprocessor with memory, input ports and output ports connected to it externally. A microcontroller is a single chip containing a microprocessor, memory, input ports and output ports. Since all four blocks reside on the one chip, a microcontroller is much faster than a microprocessor system.
   
 
   
  Program Memory and Data Memory
  There are many different kinds of memory used in embedded systems and new kinds are being developed all the time. However, we can split memory into two types; RAM and ROM
 
  • RAM stands for random access memory. The are two features of RAM which distinguish it from ROM:
    • RAM is read/write - data can be written to and read from RAM.
    • RAM is volatile - data is lost once the power to a RAM chip is lost.
Random access refers to the fact that data from any location in the memory chip is accessible at any time (you simply put the desired address on the address bus). However, RAM is actually a poor choice of name for this type of memory (its name is rooted in history) because it does not refer to its main features and it may lead you to believe other types of memory are not random access. A memory chip is of little use if it's not random access.
 
  • ROM stands for read only memory. As with RAM, it is random access but it differs from RAM in two ways:
    • ROM, as the name suggests, is read only. You cannot write to a ROM chip. How then, you may ask, do you get data onto a ROM chip? A ROM chip must be programmed, but once programmed, it cannot be (easily) changed.
    • ROM is non-volatile - when power is removed from the chip data is not lost.
There are many types of ROM available; PROM, EPROM, EEPROM and Flash are the most common and we will deal with each at a later date.
   
  Which do we use, RAM or ROM?
  The obvious advantage of RAM over ROM is the fact that data can be written to it as well as read from it. The obvious advantage of ROM over RAM is the fact that data is not lost on power down. So which is used in embedded systems?
 

The answer is both.

 
  • RAM is used for storing data that is used by the system.
    • For example, if you wish to heat some food and you set the timer on your microwave oven for two minutes, this piece of data (2 minutes) is stored in RAM and used by the system to count down to zero. But this data is not required afterwards and so it doesn't matter if it is lost when you unplug the oven.
    • Another example is the time and date on a VCR. This is also stored in RAM and is lost once you unplug the VCR. You then need to reset the time when you plug it in again.
 
  • ROM is used for storing the system program. The program is the set of step-by-step instructions for the system to operate.
    • If we take the microwave example again; the program tells the oven what it should do when the user sets a time and presses the 'start' button. If this data was lost once we unplugged the oven it would be useless. Therefore, the program is stored in ROM. And since the program doesn't change it does not matter that we cannot write to the chip. In fact, for safety reasons, it is better that we cannot write to the chip; we might, accidentally (ie; a bug in the program) write over some of the program and corrupt the system.
  Therefore, we should always keep in mind the two types of memory. RAM for data, ROM for the program.

 

The Best of Both Worlds

So, the system code is stored in ROM because it must not be lost when power is removed.

And data that's only needed temporarily (or for as long as the power is on) is stored in RAM. And the values of such data may change – ie: it's variable.


But you might wonder about variable data that must not be lost when the power is removed. Take, for example, the odometer in modern cars, where the car's mileage is stored electronically. This piece of data is variable, so it can't be stored in ROM. But it also can't be stored in RAM. You wouldn't be too confident buying a used car if all that was needed to reset the odometer was disconnecting the car's battery.

Nowadays, the solution to this problem is FLASH. This type of semiconductor memory can be written to as well as read from, and its data is not lost when power is removed. Memory sticks that you plug into your computer's USB port are an example of this type of memory.
   
 
<-Previous
 
   
 
Copyright (c) 2005-2011 James Rogers