Electronics Components: Introducing Microcontrollers
A microcontroller is a complete computer on a single electronic chip. They can be purchased for $50 or less. Like all computer systems, microcomputers consist of several basic subsystems:
Central processing unit (CPU): A CPU carries out the instructions provided to it by a program. The CPU can do all the operations necessary to the proper functioning of the computer, such as moving data from one location of memory to another or receiving data as input from the outside world.
Clock: The CPU and other components of the microcontroller are driven by a clock that provides timing pulses that control the pacing of program instructions as they are executed one at a time by the CPU. For most microcontrollers, the clock ticks along at a pace of a few million ticks per second. In contrast, the clock that drives a typical desktop computer ticks along at a few billion ticks per second.
Random access memory (RAM): Provides a scratchpad area where the computer can store the data it's working on. For example, if you want the computer to determine the result of a calculation (such as two plus two), you need to provide a location in RAM where the computer can store the result.
In a desktop computer, the amount of available RAM is measured in billions of bytes (GB for gigabytes). In a microcontroller, the RAM is often measured just bytes. That’s right: not billions (GB), millions (MB; megabytes), or even thousands (KB; kilobytes) of bytes, but plain old bytes. For example, the popular BASIC Stamp 2 has a total of 32 bytes of RAM.
EEPROM: A special type of memory that holds the program that runs on a microcontroller. EEPROM stands for Electrically Erasable Programmable Read-Only Memory, but that won’t be on the test.
EEPROM is read-only, which means that once data has been stored in EEPROM, the data can't be changed by a program running on the microcontroller’s CPU. However, it's possible to write data to EEPROM memory by connecting the EEPROM to a computer via a USB port. Then, the computer can send data to the EEPROM.
This is how microcontrollers are programmed. You use special software on a PC to create the program that you want to run on the microcontroller. Then, you connect the microcontroller to the PC and transfer the program from the PC to the microcontroller. The microcontroller then executes the instructions set forth in the program.
Most microcontrollers have a few thousand bytes of EEPROM memory, which is enough to store relatively complicated programs downloaded from a PC.
One of the most important features of EEPROM memory is that it doesn’t lose its data when you turn off the power. Thus, once you transfer a program from a PC to a microcontroller’s EEPROM, the program remains in the microcontroller until you replace it with some other program.
You can turn the microcontroller off and put it on a closet shelf for years, and when you turn the microcontroller back on, the program that was recorded years ago will run again.
I/O pins: One of the most important features of a microcontroller is its I/O pins, which enable the microcontroller to communicate with the outside world. Although some microcontrollers have separate input pins and output pins, most have shared I/O pins that can be used for both input and output.
I/O pins usually use the basic TTL logic interface: HIGH (logic 1) is represented by +5 V, and LOW (logic 0) is represented by 0 V.
Most microcontrollers can handle only a small amount of current directly through the I/O pins. 20–25 mA is typical. That’s enough to light up an LED, but circuits that require more current should isolate the higher current load from the microcontroller I/O pins. This is usually done by using a transistor driver.