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 DC-0600 8255/8253 Card Dual 8255 (48 lines) plus 8253 Timer / Counter Chip DC-0610 PCI 8255/8253 Card PCI version Dual 8255 (48 lines) plus 8253 Timer DC-0620 8255/8253 Lab Card Dual 8255 plus 8253 with Prototype Area. DC-064x Multi-8255 Card 2x to 8x 8255 (48 to 192 lines) plus Dual 8253 Timer 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