Hardware Design
We need a microcontroller that will provide two inputs and eight outputs, which will drive the light-emitting diodes (LEDs) without additional interfacing, and has reprogrammable flash memory to allow the program to be developed in stages. An accurate clock is not required, so a crystal oscillator is not necessary. The PIC 16F84A meets these requirements; it is a basic device, so we will not be distracted by unused features. Later, we can replace it with a more recent processor, such as the PIC 16F690. The 16F84A should not be used for new designs.
PIC 16F84A Pin-Out
The PIC 16F84A microcontroller is supplied in an 18-pin dual in-line (DIL) chip. The pin labeling, taken from the data sheet (download from www.microchip.com), is shown in Figure 3.1. Some of the pins have dual functions, which will be discussed later.
The chip has two ports, A and B, consisting of five and eight pins, respectively. The port pins allow data to be input and output as digital signals, at the same voltage levels as the supply, which is connected between VDD and VSS, nominally 5 V. CLKIN and CLKOUT are used to connect clock circuit components, and the chip then generates a fixed frequency clock signal that drives all its operations along. !MCLR (NOT Master CLeaR) is a reset input, which can be used to restart the program. Note that the active low operation of this input is indicated by a bar over the pin label in the data sheet, or an exclamation mark here. In simple applications, this input does not need to be used, but it MUST be connected to the positive supply rail to allow the chip to run. If you construct a circuit and it does not work, check this point. A summary of the pin functions is provided in Table 3.1.
Port B has eight pins, so we will assign these pins to the LEDs and initialize them as outputs. Port A has five pins, two of which can be used for the input switches. A resistor and capacitor will be connected to the CLKIN pin to control the clock frequency. In this chip, an external crystal can be used for a more precise clock frequency, and in many current chips, an internal oscillator is provided, which means that no external clock components are needed.