Understanding Data and Port Registers

Your program might (and likely will) use variables to temporarily store data that are needed for later on. In addition to variables, which are stored in the RAM memory, microcontrollers also have special “cells” for storing little scraps of information. These cells are called registers, and there are two types: data and port.

Data (or working) registers are variables provided in the microcontroller hardware. They’re separate from flash, RAM, and EEPROM data storage on the chip. But don’t get too excited—many controllers don’t give you more than 32 bytes (yes, bytes) of data register space. Then again, given the applications microcontrollers do, you probably don’t need a lot of this space.

When working with data registers you can access individual bits of each byte. So, for example, if a microcontroller gives you 32 8-bit data registers, you actually have 32 × 8, or 256, of these cells for use to store various aspects about your robot’s current condition. Remember that a bit can hold either of two values, 0 (OFF) or 1 (ON). With just 19 bits—less than 3 bytes—you could store:

Port (or I/O) registers store the current values of the I/O lines and other hardware on the microcontroller. In most programming languages for microcontrollers you get and set hardware values using symbols; the symbol for the data value for pin 3 of port D might be PORTD3. Behind the symbol is a specific port register—an actual piece of hardware deep inside the microcontroller—that stores the current value of the data pin.