8255 PPI Tutorial
The 8255 Programmable Peripheral Interface (PPI) is a very popular and versatile input / output chip that is easily configured to function in several different configurations. The 8255 is used on several of our range of cards that plug into an available slot in your IBM PC. This chip allows you to do both digital input and output (DIO) with your PC. For example, you may want to have your PC turn on a switch, or have a switch electronically activate your PC to execute a program. Each 8255 has 3 off 8-bit TTL-compatiable I/O ports which will allows the control of up to 24 individual outputs or to read 24 individual inputs, or indeed a mixture of both input or output. For example, you could attach this to a robotic device to control movement by use of motors to control motion and switches to detect position etc.
Our range of cards utilising the 8255
To use this card some knowledge of programming will be required, the simple examples below use Microsoft's QuickBasic. This language is fairly easy to obtain and was supplied with DOS 6.22. By no means is the use of these cards limited to programming with any particular language, but the language does need to be able to input and output to ports.
Ports vs. Memory
Addressing ports is different to addressing memory. Ports have port addresses and memory has memory addresses, port address 1234 is different to memory address 1234. Our range of cards use port addresses and cannot be set to use memory addresses. Sorry to go on about this but there is a lot of confusion surrounding this subject.
Theory of Operation
The Base Address
Our range of cards plug into any available 8 or 16-bit slot (also known as an AT or ISA slot) on your PC's motherboard, just like a sound card or disk drive controller card does. Your CPU (Central Processing Unit) communicates with cards by knowing the card's address and sending data to it. By physically using jumpers on the card, we can assign a set of addresses to the card, then in software, we can tell the CPU what these addresses are (more about this in the Programming section).
Table 2: DC-0600 Addresses
| |
Option 1 : default (JP2 Linked) |
Option 2 (JP2 Open) |
| 8255 Port |
Address [Hex (dec)] |
Address [Hex (dec)] |
| Port 1A |
300H (768) |
360H (864) |
| Port 1B |
301H (769) |
361H (865) |
| Port 1C |
302H (770) |
362H (866) |
| Port 1 Control Reg. |
303H (771) |
363H (867) |
| Port 2A |
304H (772) |
364H (868) |
| Port 2B |
305H (773) |
365H (869) |
| Port 2C |
306H (774) |
366H (870) |
| Port 2 Control Reg. |
307H (775) |
367H (871) |
For notation purposes, a number with an H next to it denotes hexadecimal notation and plain numbers will denote denote plain decimal.
8255 Configuration
The first thing that must be done, before the chip can be used, is to tell it which configuration is required. The configuration tells the 8255 whether ports are input or output and even some strange arrangements called bi-directional and strobed, but these 'funny' modes go a little beyond the scope of this tutorial. The 8255 allows for three distinct operating modes (Modes 0, 1 and 2) as follows:
- Mode 0: Ports A and B operate as either inputs or outputs and Port C is divided into two 4-bit groups either of which can be operated as inputs or outputs
- Mode 1: Same as Mode 0 but Port C is used for handshaking and control
- Mode 2: Port A is bidirectional (both input and output) and Port C is used for handshaking. Port B is not used.
For most applications using this range of cards Mode 0 will be used.
Each of the 3 ports has 8 bits, each of these bits can be individually set on or off, it's a bit like having 3 banks of 8 light switches. These bits are configured in groups to be inputs or outputs allowing their function to either read data into the computer or control data out of the computer. The various modes can be set by sending a value to the control port. The control port is Base Address + 3 (i.e. 768+3 = 771 Decimal). The table below shows the different arrangements that can be configured and the values to be sent to the configuration port.
TABLE 3: 8255 Control Register Configuration ( Mode 0: )
| Control Word [Hex(Dec)] |
Port A |
Port B |
Port C |
| 80H (128) |
OUT |
OUT |
OUT |
| 82H (130) |
OUT |
IN |
OUT |
| 85H (133) |
OUT |
OUT |
IN |
| 87H (135) |
OUT |
IN |
IN |
| 88H (136) |
IN |
OUT |
OUT |
| 8AH (138) |
IN |
IN |
OUT |
| 8CH (140) |
IN |
OUT |
IN |
| 8FH (143) |
IN |
IN |
IN |
As mentioned the Control port is Base Address + 3. Port A is always at Base Address; Port B is Base Address + 1; Port C is Base Address + 2. Thus in our example Ports A, B and C are at 768, 769 and 770 (Decimal) respectively. By writing say, 128 to the Control port will then configure the 8255 to have all three Ports set for output. This can be done using QuickBasic's OUT statement, for example:
| 110 BaseAddress = 768 |
| 120 PortA = BaseAddress |
| 130 ControlPort = BaseAddress + 3 |
| 140 OUT ControlPort, 128 |
| 150 OUT PortA, 1 |
QBasic Programming
For this section it will be assumed that you are using the DC-0600 card which includes LED's on each of the Port A lines which allow for a visual check of operation. Under Quick Basic type in and execute the following code:
| 100 REM 8255 PPI SET PORTS A,B,C TO OUTPUT |
| 110 BASEADDR = 768: REM 300H/JP2 SHORT |
| 120 PORTA = BASEADDR |
| 130 CNTRL = BASEADDR + 3 |
| 140 OUT CNTRL, 128 |
| 150 FOR SGNAL = 0 TO 255 |
| 160 OUT PORTA, SGNAL:PRINT "DECIMAL="; SGNAL |
| 170 FOR DELAY = 1 TO 500: NEXT DELAY |
| 180 NEXT SGNAL |
| 999 END |
If everything is working, then you should see the 8 LEDs "count" from 0 to 255 in a binary fashion. In other words what you will see is the top LED flashing very fast, the second LED down flashing at half the speed of the top, the third LED half the speed of the second, and so on down the top eight LED's. The speed of the flash depends on the speed of your computer, if you have a very fast computer the top few LED's may seem steady as they are flashing so fast!. To slow the whole thing down a bit increase the value of the DELAY loop at line 170 to say 5000, and the program will run at a tenth of the speed.
The above program is very simple, but hopefully this has given you a little confidence in completing much larger projects, maybe even some sort of robotic control, but a least your first steps into the world of control and automation.