5. CHANGE OLD LPT CARD
As our discussion before, old LPT card can not support bi-directional data transfer. Why this option can not support? Because, in the beginning the LPT port only design for printing purpose (only for sending data, it is not necessary to read the data back). How if we want to connect device that want to transfer data to computer? It is the problem. Notice that this is not implied to the new card design. Because many new card can be reprogramming (have chip set) to work in SPP, ECP or EPP mode. Any who knows about this specification? please inform me. Besides that many LPT's card can work to operated as bi-directional port.
In the old card, data lines (DP) passed a tri-state buffer (LS245 IC) and latch by LS374 IC. This latch IC has output enable pin grounded (see Figure-6).
click the image for zooming
That means that data which is sending to it allways keep (latch by the 74LS374 IC). So any other data input from the outside allways read wired-OR with this kept data by the computer or wrong data (in fact that some people used this trick(by sending FF Hex to the output and ORed the data) for many-many years and it works!). We must make this data line to be tri-state in other word, we must make the output enable pin of LS374 IC can be high. Figure-7. show the necessary modification that we must do. Notice that the selection of pin 25 is by your choise only. To make it easy set to pin 25. You can choose from any other pins that not in used in the range18~25. Resistor 4.7 kOhm is used to keep the function of LPT so the normally operation still be working. But now we can disable the latch output if we make pin 25 high, data can be read to computer. Any extra care must be taken to free the output enable pin of LS374 IC. Don't damage it!
After everythings was done, LPT adapter now can be used as input data port. Remember to set pin 25 connector high went you sent data to computer and vice versa. Note that, this option could be done from external device.
Another way to make the card to be bi-directional port is like this (this way could be controlled from software/inside, like the standard bi-directional card), cut off pin 1 of the 74LS374 IC or the track layout from the ground and connect to the only one of the output of the 74LS174 spare (maybe pin 15th/6Q) by some wire. This spare latch is connected to the related bit PC-5 (direction bit). So, if this bit low, after the reset period, the direction also low, the DP port act as output port.
6. CHECKING LPT ADAPTER
How do we check an LPT adapter was installed in a computer? It is a quiet simple matter. In a new card (bidirectional card), simple send a byte to DP port and then read back again. If the result was not an FF Hex or if the result exactly the same to the byte wrote, then the card is installed at that port. This happend because, if the card not installed, the accessing port is a tri-state all, there is no connection to the hardware logic. Tri-state logic interpreted as logic 1. For the old card and also the new one, accessing the PC port is quiet the same thing to the above matter. But if a device was connected to this port, a read back byte may not be the same as to the write byte, because the upper 3 bits are not used interpreted as logic 1 all. Here is the examples to access this port in several languages :
In PASCAL routine : CONST
LPT_Port = $3BC;
Byte_R_W = $44;
There_is : BOOLEAN = FALSE;
PROCEDURE Check_LPT;
BEGIN
PORT[LPT_Port] := Byte_R_W; { Dummy Data }
IF (PORT[LPT_Port] = Byte_R_W) THEN There_is := TRUE; { this statement checking LPT Port }
IF (PORT[LPT_Port] <> $FF) THEN There_is := TRUE; { or this statement }
END; |
In ASSEMBLY routine : LPT_Port EQU 3BC H
Byte_R_W EQU 44 H
True EQU 1 H
False EQU -1 H
There_is DB ?
Check_LPT PROC NEAR
MOV AX,LPT_Port
MOV DX,AX
MOV AL,Byte_R_W ;Dummy Data
OUT DX,AL
IN AL,DX
CMP AL,Byte_R_W
JE It_is ;This statement checking LPT Port
CMP AL,0FFH
JNE It_Is ;or this statement
It_is_not:MOV There_Is,False
RET
It_Is: MOV There_is,True
RET
Check_LPT ENDP |
In BASIC routine : PROC Check_LPT
LPT_Port = &H3BC:Byte_R_W = &H44:There_is = FALSE
OUT LPT_Port,Byte_R_W
IF (INP(LPT_Port) = Byte_R_W) THEN There_is = TRUE :REM ----- This statement checking LPT Port
ELSE IF (INP(LPT_Port) <> &HFF) THEN There_is = TRUE :REM ----- or this statement
END PROC |
In C routine : #define 0 false
#define 1 true
#define There_Is false
void Check_LPT()
{
int LPT_Port = 0x3BC;
unsigned Byte_R_W = 0x44;
outp(LPT_Port) = Byte_R_W;
if (inp(LPT_Port) == Byte_R_W)
{
There_is = true /* This statement checking LPT Port */
}
else if (inp(LPT_Port) <> 0xFF)
{
There_is = true; /* or this statement */
}
} |
In PASCAL routine : CONST
Seg_LPT = $40;
Ofs_LPT = $8;
There_is : BOOLEAN = FALSE;
LPT_Is : ARRAY[1..3] of STRING = ('First','Second','Third');
VAR
No_LPT : BYTE;
PROCEDURE Check_LPT;
BEGIN
FOR No_LPT := 0 TO 2 DO
BEGIN
IF (MEMW[Seg_LPT,(Ofs_LPT+No_LPT*2)] <> 0) THEN { this statement checking LPT Port}
BEGIN
There_is := TRUE;
WRITE(LPT_Is[No_LPT],' LPT port found !');WRITELN;
END;
END;
IF NOT There_Is THEN WRITELN('There is no LPT adapter installed !');
END; |
In ASSEMBLY routine : Seg_LPT EQU 40 H
Ofs_LPT EQU 08 H
True EQU 1 H
False EQU -1 H
There_is DB False
LPT_Is LABEL BYTE
DB 'First$ '
Len_Str EQU $-LPT_Is
DB 'Second$'
DB 'Third$ '
Lpt_Found DB ' LPT port found !',13,10,'$'
No_LPT DB 'There is no LPT adapter installed !',13,10,'$'
Check_LPT PROC NEAR
MOV CX,3
MOV AX,Seg_LPT
MOV ES,AX
MOV BX,Ofs_LPT
Lop_LPT: MOV AX,WORD PTR ES:[BX]
CMP AX,0 ;This statement checking LPT Port
JZ Next_LPT
MOV There_Is,True
MOV AX,Len_Str
MUL CL
MOV DX,AX
ADD DX,OFFSET Lpt_Is
MOV AH,09H
INT 21H
LEA DX,LPT_Found
MOV AH,09H
INT 21H
Next_LPT: INC BX
INC BX
LOOP Lop_LPT
CMP There_Is,False
JNE End_Check_LPT
LEA DX,No_LPT
MOV AH,09H
INT 21H
End_Check_LPT:
RET
Check_LPT ENDP |
In BASIC routine : PROC Check_LPT
Seg_LPT = &H0040:Ofs_LPT = &H0008:There_is = FALSE
DIM LPT_Is$(2):FOR I=0 TO 2:READ LPT_Is$(I)
DATA "First","Second","Third"
FOR Count = 0 TO 2
DEFSEG = Seg_LPT :REM ----- This statement checking LPT Port
IF (PEEK(Ofs_LPT+Count) <> 0) THEN
There_is = TRUE:DEFSEG=:PRINT LPT_Is(Count);" LPT port found !":PRINT
END IF
IF (There_Is = FALSE) THEN "There is no LPT adapter installed !":PRINT
END IF
END PROC |
In C routine : #include |
7. CHECKING BI-DIRECTIONAL PORT
How to convince that my own LPT adapter card is bi-directional or not ?
The bi-directional card used bit PC-5 to control the direction of data in DP port. If the PC-5 bit is low, the DP port act as output port and if it is high, the DP port is used for input port.
What's going on of these bits of DP port ?
When the DP port act as output port, the data is latch at the output, so if we read this data back from the DP port, the data must always the same as that we send. But if DP port act as input port, the read data must be FF Hex, because the latch of DP port is in tri-state.
By this situation, we can check the LPT port rather it's a bi-directional port or not, by sending a byte (output a byte, not an FF Hex) to DP port, activating PC-5 direction control, and read the DP port back again and compare the result with the byte sender. If the data match (read data = a byte sender), the LPT port is not a bi-directional, and if the data is not match (read data = FF Hex), the LPT port is a bi-directional port. Okay... try your LPT port now !
I had compiled the checker in pascal program and in assembly program.
No comments:
Post a Comment