8255 I/O DECODER
PREFACE
As you can see from the article LPT port expander, this PPI-8255 is a general purpose I/O programmable function. But usually this IC are tired to the computer bus directly. Return to this idea, here I will show you that the card can be used to dual function purpose. Beside for the expander port, it can be used for I/O functional directly. So we can used the card both for the expander experiment or for direct connection to the computer bus experiment. Why do you need this I/O directly connection for? Many article on the net usually used this method for I/O interfacing. So by doing this, we can take 2 benefits. First, we can used many useful routines (usually with the tested ones) or directly used the softwares (?) or routines; secondly, we can used many hardware design by someone else (compatibility type). At most we can replace the I/O parts. Happy programming and happy surfing on the net.DETAILS
To directly connected a hardware to computer bus, we need an I/O decoding. Here I don't explain anymore, please refer to the topic of decoding technique at the other page. There are 2 type of decoding technique, ie: partial decoding, when we want to reduce the components using or full decoding. I prefer the last one. The decoder circuit must be preserve all of the possible unused I/O ports, easy to select the address, and not ambiguous for the future compatibility design. I used a comparator 74LS682 type and a dip switch for this purpose. Besides that the lines need buffers because the card may put far away from the PC. The complete circuit diagram shown at fig-1.One thing must remember that, when doing re-boot-ing the PC, the expander card must be connected to this decoder card. So the PPI can be reset. If not, the PPI can not be initialized. To anticipate this purpose, we can add a push on switch between +Vcc and reset pin of PPI. So you can connected the expander card at any time, when ever you want and without re-boot-ing the PC. Initialized perform when the software being execute. Some connection also must be changed to make the circuit work with this decoder card. The explanation will be clearly later.
click the image for enlarge
Fig-1. I/O decoding for PPI-8255 circuit diagram.
SOFTWARE
Nothing to say about this card programming. It is quiet easy. You can access the port by accessing directly to 4 contiguous port location, eg: if the decoder set to port 220 hex, so port-A = 220 H, port-B = 221 H, port-C = 222 H, port-CW = 223 H.First, initialize it by sending the control word data to port-CW (control word data contain mode setting for each port). Refer to PPI-8255 data book for more detailed explanation. Then each port can be accessing directly. Here are a sample of initialize routine for mode-0 for any language.
In PASCAL routine : CONST
Base_Port = $220;
Port_A = Base_Port;
Port_B = Base_Port+1;
Port_C = Base_Port+2;
Port_CW = Base_Port+3;
CW_Data = $82; { Port-A = output, Port-B = input, port-C = output }
PROCEDURE Initialize_Port;
BEGIN
PORT[Port_CW] := CW_Data; { Send Control Word }
END; PROCEDURE Read_Write_Port_A(Datanya : BYTE);
BEGIN
...
PORT[Port_A] := Datanya; { Send a Byte }
...
END;
FUNCTION Read_Port_B : BYTE;
BEGIN
...
Read_Port_B := PORT[Port_B]; { Receive a Byte }
...
END; PROCEDURE Write_Port_C(Datanya : BYTE);
BEGIN
...
PORT[Port_C] := Datanya; { Send a Byte }
...
END; |
In ASSEMBLY routine : Base_Port EQU 220 H
Port_A EQU Base_Port
Port_B EQU Base_Port+1
Port_C EQU Base_Port+2
Port_CW EQU Base_Port+3
CW_Data EQU 82 H ;Port-A = output, Port-B = input, Port-C = output
Dummy EQU 5A H
Initialize_Port PROC NEAR
MOV DX,Port_CW
MOV AL,CW_Data ;Send Control Word
OUT DX,AL
RET
Initialize_Port ENDP Write_Port_A PROC NEAR
...
MOV DX,Port_A
MOV AL,Dummy ;Send a Byte
OUT DX,AL
...
RET
Write_Port_A ENDP Read_Port_B PROC NEAR
...
MOV DX,Port_B
IN AL,DX
MOV Dummy,AL ;Receive a Byte
...
RET
Read_Port_B ENDP Write_Port_C PROC NEAR
...
MOV DX,Port_C
MOV AL,Dummy ;Send a Byte
OUT DX,AL
...
RET
Write_Port_C ENDP |
In BASIC routine : Base_Port = &H220
Port_A = Base_Port
Port_B = Base_Port+1
Port_C = Base_Port+2
Port_CW = Base_Port+3
CW_Data = &H82 ;REM ----- Port-A = output, Port-B = input, Port-C = output
Dummy = &H5A PROC Initialize_Port
OUT Port_CW,CW_Data :REM ----- Send Control Word
END PROC PROC Write_Port_A
...
OUT Port_A,Dummy :REM ----- Send a Byte
...
END PROC PROC Read_Port_B
...
INP Dummy,Port_B :REM ----- Receive a Byte
...
END PROC PROC Write_Port_C
...
OUT Port_C,Dummy :REM ----- Send a Byte
...
END PROC |
In C routine : #define Base_Port 0x220
int Port_A = Base_Port;
int Port_B = Base_Port+1;
int Port_C = Base_Port+2;
int Port_CW = Base_Port+3;
unsigned CW_Data = 0x82;/* Port-A = output, Port-B = input, Port-C = output */
unsigned Dummy = 0x5A;
void Initialize_Port()
{
...
outp(Port_CW) = Dummy; /* Send Control Word */
...
} void Write_Port_A()
{
...
outp(Port_A) = Dummy; /* Send a Byte */
...
} void Read_Port_B()
{
...
Dummy = inp(Port_B); /* Receive a Byte */
...
} void Write_Port_C()
{
...
outp(Port_C) = Dummy; /* Send a Byte */
...
} |
At last, I found a good software to demonstrate this mode programming capabilities. This program was made by someone else and could shows the I/O state for each mode setting, as input port or output port. A good example software.
No comments:
Post a Comment