In this chapter we will learn how we interface an MCU to the real world by first learn- ing how to create outputs with the microprocessor and then learning how to read inputs into the microprocessor. In following chapters we will combine the outputs and the inputs to control the operation of small motors of all kinds.
All the programs that we will be discussing are provided on the support web site for this book. You can copy them from the site to run them. The exercises listed at the end of various chapters are designed to increase your familiarity and competence with the 16F877A. The answers to them are not provided.
In preparation for writing programs, set up the LAB-X1 so that it can be pro- grammed with one mouse button click or by pressing F10 as is described in detail in Appendix A.
The I/O that uses ICs in the seven empty sockets on the LAB-X1 board is covered separately in Chapters 7 and 8. These chapters also cover one wire memory, A to D converters, and a number of thermometric devices.
The I/O that uses the serial port (as RS232 or RS485) is covered in Chapter 8. Specifically, this covers communications between the PIC 16F877A and personal computers.
We will learn about input and output by writing simple programs that control the outputs and read the inputs. We will learn how to control the outputs first because this can be done directly from the software without need for any input or any external hardware. Once we can control the output, we will learn how to read the inputs and make them interact with the output.
The following are output programs to be developed:
N A program to blink one LED on the bar graph.
N Blink all eight LEDs in the bar graph consecutively.
N Dim and brighten one LED.
N Write “Hello World” to the LCD on its two lines.
N Write binary and decimal values to the LCD.
N Output a simple tone on the speaker.
N Output a telephone tone signal on the speaker.
N Advanced: Move an R/C servo back and forth.
The following are input programs to be developed:
N A program to read the first column, first row button, and turn on one LED while this button is down.
N Read the entire keyboard and display the binary value of the row and column read on the LCD.
N Read the keyboard and display decimal key number on the LCD.
N Read one potentiometer and display its 8-bit value on the LCD in binary, hex, and decimal notation. Also display the binary value on the bar graph.
N Read all three potentiometers on the LAB-X1 and display their values on the LCD.
N Advanced: Use the three potentiometers on the LAB-X1 to control an R/C servo.
Control the location of the center position, the limit position of the end positions, and the rate of movement. Use three switches on the keypad to move the servo clockwise, center the servo, and move it counterclockwise.