06/25/091 computer interfacing via the parallel port carlos m. oppus ecce program, admu
TRANSCRIPT
06/25/09 1
Computer Interfacing
Via the
Parallel Port
Carlos M. Oppus
ECCE Program, AdMU .
06/25/09 2
Objectives
This lecture aims :
1) to give an overview of computer interfacing.
2) to give the basics of interfacing via the parallel port
06/25/09 3
Introduction Computer Interfacing means
connecting different devices to the computer and being able to control or read the status of these devices.
There are many ways to achieve computer interfacing.
(1) Interfacing by making your own computer interface card.
(2) Interfacing via the existing ports in your computers.
06/25/09 4
Introduction (cont …)
namely (a) modem (b) internet (c) serial port (d) game port (e) parallel port (f) USB etc.
06/25/09 5
Parallel Port Computers are equipped with at least
one parallel printer port card. This parallel port can be used as a
general input-output device used for manipulating interfaced hardware.
The printer port is designated as LPT 1, LPT 2 & LPT 3
06/25/09 6
Printer PortParallel (printer) port as a general-purpose
set of digital input and output port for interfacing devices.
8-bit digital input/output (I/O) register if an
enhanced parallel port is being used otherwise it is just an output register
4-bit output register
4-bit input register (actually 5 inputs)
06/25/09 7
Parallel (Printer) Port
Port Configuration I/O Port address
LPT 1 378H to 37AH
LPT 2 278H to 27AH
06/25/09 8
8 output pins accessed via the DATA Port (pins 1 to 9) 5 input pins (one inverted) accessed via the STATUS Port (pins 10, 11, 12,
13, 15) 4 output pins (three inverted) accessed via the CONTROL Port (pins 1, 14,
16, 17)
The remaining 8 pins are ground (pins 18 to 25)
Parallel (Printer) Port
06/25/09 9
Parallel (Printer) Portnote: high TTL level = 2.4V to 5V low TTL level = 0V to 0.8V (normally 0V)
An OUT instruction to port address 378H (278H) and 37A (27A) can write the data directly to the connector pins.
An IN instruction to port address 378H (278H) [if an enhanced parallel port is in use] and 379H (279H) can read the data directly from the connector pins.
06/25/09 10
8-bit I/O if an enhanced parallel port is being used otherwise it is just an output port at address 378H (278H)
BIT TTL level when a 1 is written/read to/from
the port bit
pin position
description
0 high 2 D0 1 high 3 D1 2 high 4 D2 3 high 5 D3 4 high 6 D4 5 high 7 D5 6 high 8 D6 7 high 9 D7
example:
PASCAL: port[$0378] := 255; // outputs 11111111 to pins 2 to 9
C: outportb(0x378,255); // outputs 11111111 to pins 2 to 9
06/25/09 11
379H (279H)
4-bit input port at address 379H (279H) BIT TTL level when a
1 is read from the port bit
pin position
description
0 not used n/a n/a 1 not used n/a n/a 2 not used n/a n/a 3 not used n/a n/a 4 high 13 select 5 high 12 P.E. 6 high 10 ackn 7 low 11 busy
06/25/09 12
PASCAL: data := port[$037A] ; reads port 37AH i.e. reads the TTL levels of
pins 13,12,10 & 11 respectively and places the corresponding values at the higher nibble of variable “data”.
C: data = inportb(0x37A); reads port 37AH i.e. reads the TTL levels of
pins 13,12,10 & 11 respectively and places the corresponding values at the higher nibble of variable “data”.
Example
06/25/09 13
37AH (27AH)4-bit output port at address 37AH (27AH)
BIT TTL level when a 1 is written to the port bit
pin position
Description
0 low 1 strobe 1 low 14 autofeed 2 high 16 init prt 3 low 17 select inp 4 direction control bit of
data register (378H/278H) if enhanced parallel port (high for input, low for output)
not applicabl
e (n/a)
n/a
5 not used n/a n/a 6 not used n/a n/a 7 not used n/a n/a
06/25/09 14
PASCAL:
Port[$037A] := 4; outputs 0100 to pins 17,16,14 & 1 respectively
i.e. pin 17 is high, pin 16 is high, pin 14 is high and pin 1 is high.
C:
outportb(x037A,4); outputs 0100 to pins 17,16,14 & 1
respectively i.e. pin 17 is high, pin 16 is high, pin 14 is high and pin 1 is high.
Example
06/25/09 15
vbOut [port],[number] example:
'set port to 00001011 378H = 888vbOut 888, 11 [variable]=vbInp([port])
example:
‘input from 379H = 889PortNum%=vbInp(889)
For 32bit VB (WIN95IO.DLL), use: Declare Sub vbOut Lib "WIN95IO.DLL" (ByVal nPort As Integer, ByVal nData As Integer) Declare Sub vbOutw Lib "WIN95IO.DLL" (ByVal nPort As Integer, ByVal nData As Integer) Declare Function vbInp Lib "WIN95IO.DLL" (ByVal nPort As Integer) As Integer Declare Function vbInpw Lib "WIN95IO.DLL" (ByVal nPort As Integer) As Integer
06/25/09 16
Sample Circuits
06/25/09 17
Sample Circuits
06/25/09 18
Demonstration
Appliance controller …
06/25/09 19
Circuit Diagram
06/25/09 20
Sample Program
uses crt;
var ch :char;
begin
clrscr;
repeat
port[$37A] := $0B; gotoxy(20,20); write('off');
ch := readkey;
port[$37A] := $04; gotoxy(20,20); write('on ');
ch := upcase(readkey);
until ch = 'Q';
port[$37A] := $0B;
end