You are on page 1of 11

Copyright 1998 Robert Woudsma,

UPPER CANADA TECHN ! "#E$

Reading & Writing through the Enhanced Parallel Port (EPP) Part A: Building and Testing the Interface
This project has two parts; constructing the Input/Output circuit and writing the test routine. The Simple PT Interface In project #1 we looked at directly driving eight LE !s with the eight digital outputs o" the L#T port. In project #$ we added digital input and output capa%ility to the printer port. In this circuit we will e&pand the inter"ace capa%ility to include %oth writing to and reading "ro' analog devices. (ttached is a circuit diagra' o" a si'ple L#T port inter"ace that provides "or eight %its o" digital input) eight %its o" digital output) an eight %it digital to analog converter and an eight %it analog to digital converter. !ote: *o'e o" the in"or'ation presented %elow is a repeat o" project #$. It is repeated here "or those who have skipped project #$. The Parallel Printer Port "ard#are The original speci"ication "or the L#T port allows "or only data "low in one direction) "ro' the co'puter to the printer. +ut the printer port is actually 'ade up o" three sections; the ,-%it output data port) the .-%it input port and the /-%it output control port. The (T( port contains eight %its o" data that are accessi%le %y writing to the L#T 1 port %ase I/O address) usually 01, 2e& or ,,, ec. +eside the data output port there is a "ive %it *T(T3* input port through which the co'puter could get status in"or'ation "ro' the printer such as paper out) or %usy or printer online etc. These %its are read %y reading the . 'ost signi"icant %its "ro' the L#T1 %ase I/O address 41) usually 015 he& or ,,5 ec. 6inally there is a "our %it 7O8T9OL port that is used to control various "unctions o" the printer such as initiali:ing) line"eed) etc. These %its can %e controlled %y writing to the least signi"icant / %its o" the L#T1 %ase I/O address 4$) usually 0,; he& or ,5; ec. The $i%directional Printer Port (lthough the original printer port speci"ication <called *## "or *tandard #arallel #ort= did not allow "or reading ,-%it data through the data port) this capa%ility %egan appearing with I+>!s #*-$ line o" co'puter syste's. >ost co'puter syste's today that are sold with the serial and printer ports integrated into the 'other%oard contain %i-directional parallel ports. On the other hand) 'any 'ulti"unction I/O cards that you can %uy today to plug into your co'puters 'other%oard 'ay still only contain the *## parallel port speci"ication. ?hen choosing a parallel port or 'ulti-"unction I/O card) ensure that the speci"ication "or the printer port is stated as %eing either E## "or Enhanced #arallel #ort or E7# "or E&tended 7apa%ilities #ort. Either o" these two speci"ications allow "or
Copyright 1998 Robert Woudsma, UPPER CANADA TECHN ! "#E$

%i-directional data "low. In order to know i" your co'puter has an E## or E7# parallel port installed on it "ollow the procedure outlined %elow. 6ro' the @&' (omputerA icon or "ro' the ?indows 5. @StartA %utton and Settings selection) select ()!TR) PA!E * 6ro' the 7ontrol #anel select S+STE&* 6ro' the syste' properties dialog %o& 'ake sure that the ,e-ice &anager ta% is selected. ('ong the devices that are listed under evice >anager there should %e an ite' called P)RTS (()& & PT). ou%le-click on this ite' to e&pand the listing. The list should contain at least one L#T port and one or 'ore 7O> ports. The listing 'ay already state that the L#T port is an *##) E## or E7# type. I" not) dou%le-click on the L#T ite' in the list. ( @#rinter #ort #ropertiesA screen will %e displayed as shown %elow.

.igure /: Printer Port Properties Page

I" the description suggests the printer port is an E## or E7# type then it will work with the circuit we will %e %uilding here. I" it is a *## though) it will not work with this circuit. Bou then have two options. 6irstly) you can purchase a E## or E7# printer port %oard and add it to your co'puter at a cost o" C0; or less. *econdly you can download the

Interface (ircuit ,escription The *i'ple #rinter #ort Inter"ace 7ircuit The circuit "or a si'ple L#T inter"ace is shown on an attached page. It contains the "ollowing sectionsD

Copyright 1998 Robert Woudsma,

UPPER CANADA TECHN ! "#E$

&

( 1/(L*.1/ octal Latch to provide an ,-%it digital output port which will %e used to light , LE s or any device that you wish to send digital signals to. ( 1/L*$/. octal %i-directional latch to provide an ,-%it digital input port which will %e connected to , switches or any devices that you wish to read digital in"or'ation "ro'. (n (nalog evices ( .., ,-%it digital to analog converter to provide an analog output ranging "ro' ; to $... volts. The ( .., is uniEue in that it has an on-%oard ,-%it latch that we will use to hold the data that is delivered to it "ro' the printer port. ( 8ational *e'iconductor ( 7;,;/ ,-%it analog to digital converter that will read an analog input "ro' ; to . volts and provide an ,-%it corresponding output to the printer port. Initially) the analog input will %e connected to a 1;;F to .;;F potentio'eter that is connected %etween 4.volts and ground to provide an analog input signal.

Each I7 will %e controlled %y one o" the %its o" the 7O8T9OL section o" the L#T port. These control %its will %e 'anipulated %y Gisual +asic to latch data to %e written out o" the inter"ace or to read data "ro' the digital or analog inputs to the co'puter. The , data lines o" the L#T port now "or' a data %us) which at ti'es will contain data to %e read %y the co'puter and at other ti'es will carry the data to %e delivered "ro' the co'puter to the digital or analog output. (onstructing the Interface The initial construction o" the inter"ace should %e done on electronic proto-typing %oards or @proto-%oardsA. #roto-%oards are arranged to accept integrated circuit chips and electronic co'ponents and allows the interconnection o" the co'ponents to "or' co'plete circuits. #roto-%oards can %e interlocked together to "or' as large a proto-typing area as you wish ( diagra' o" a typical proto%oard section is shown in "igure #$) %elow.

.igure 01: ,iagram of a single proto%$oard section


Copyright 1998 Robert Woudsma, UPPER CANADA TECHN ! "#E$

'

The reEuired I7s and various other parts "or the inter"ace are shown n the sche'atic diagra' o" "igure0 %elow. 3se the circuit shown to %uild the co'plete printer port inter"ace. The layout o" the parts should occupy 0 proto-%oards) one "or the I#-$/ connector "ro' the L#T port ca%le) one to hold all "our I7!s in a row as illustrated in the circuit diagra' and a "inal one to contain the ,-%it I# switch) the , LE s and the potentio'eter. Take the ti'e to lay out a neat circuit. This will always 'ake trou%le-shooting easier i" it is necessary later. 8oteD The ju'per wire "ro' the ( 7;,;/ pins #0 and #. to ground is usually le"t open. 8or'ally this circuit will trigger and %egin per"or'ing "ree-running (/ conversions at power-up. I" it does not) then touching this connection to ground 'o'entarily will trigger the circuit. Po#er Suppl' This second project needs an e&ternal power supply to operate. The circuit is powered %y a single . volt supply which can %e constructed using a 5volt %attery and the 1,;. voltage regulator. (n alternate arrange'ent is to use a 1v 7 or higher wall adapter and connect it into the circuit as you would the %attery. The 1,;. regulator can regulate any supply voltage "ro' 1 to $.v 7 down to the reEuired . v "or this circuit. Test the Interface ("ter the circuit is constructed test it!s operation %y running the Gisual +asic progra'D read2#rite2test*e3e* This test progra' will veri"y the operation o" the digital output port on the LE s) the digital input port through the I# switches) the analog input through the use o" the potentio'eter and the analog output port. 3se a digital or analog volt'eter to check the output voltage "ro' the ( ..,.

Copyright 1998 Robert Woudsma,

UPPER CANADA TECHN ! "#E$

.igure 04:

Simple Printer Port Interface (ircuit

Copyright 1998 Robert Woudsma,

UPPER CANADA TECHN ! "#E$

Part B: Programming the Interface


Programming for the PT Interface Three progra's have %een included in the project "ile in Gisual +asic ..; to allow you to test your inter"ace circuit. The operation o" these progra's uses so'e new capa%ilities that you can use to create your own progra's to operate the inter"ace. The e&e) "or' and project "iles "or read2#rite2test) trend/ and trendfile have %een included so that you can study the' to see how these new capa%ilities have %een i'ple'ented.

.igure 05: Test ,ispla' Trend/ ,ispla'

.igure 06:

.igure 07: Trendfile ,ispla'

Copyright 1998 Robert Woudsma,

UPPER CANADA TECHN ! "#E$

Copyright 1998 Robert Woudsma,

UPPER CANADA TECHN ! "#E$

Read2#rite2test is a si'ple progra' that allows each "unction o" the circuit to %e tested; reading and writing %oth digital and analog data. Trend/ only reads data "ro' the analog input section and displays the analog value as a @B verses ti'eA graph on a trend display. Trendfile o""ers a nu'%er o" desira%le enhance'ents to the trend1 progra' including user selecta%le %ackground and graph pen colour) saving a trend graph to a "ile as (*7II data) redisplaying a previously saved trend graph "ile and selecta%le trend speeds. (ontrolling the Interface Sections 3sing 'ultiple devices all connected to a co''on data %us raises so'e design and progra''ing issues. 7ontrol o" the data %us One and only one device 'ay place data on the data %us at a ti'e. I" we wish to send digital or analog signals out o" the co'puter) the co'puter will have control o" the data %us. I" we wish to read digital or analog in"or'ation into the co'puter) the digital input I7 or the analog to digital converter will have control o" the data %us. It %eco'es the jo% o" the progra' to 'ake sure that only one o" the inter"ace sections will have access to the data %us at a ti'e in order to read data "ro' or to place data onto the %us. *electing Input or Output devices *uppose we wish to output a digital value to the LE s and so we there"ore cause the co'puter to place a digital value onto the data %us. ?e want the digital output latch) the 1/.1/ to then react to the data on the %us and deliver it to the LE s. ?e 'ust ensure that the digital to analog converter) the ( 7;,;/ does not react to the digital value that is placed on the data %us. In short) we need to have control in our hardware and our so"tware to %e a%le to deter'ine what each section o" the inter"ace will do and when it is allowed to do it. The hardware control is achieved through the use o" "our control lines "ro' the L#T port. These lines are 7;) 71) 7$ and 70 which are connected to L#T pins 1) 1/) 1H and 11 respectively. Each ti'e we wish to cause a value to %e read or written to a device in our inter"ace we 'ust change the state o" it!s control line. This will allow the device to either latch the data on the data %us i" it is an output device or to place data onto the data %us i" it is an input device. (ontrolling the (ontrol Register In project #1 we took direct control o" the L#T port data lines %y writing values to the L#T port I/O address. In project #$ we use the single 7; control register %it which in turn controlled the logic level o" the printer port pin #1. In this project we need to control "our %its o" the control register. 6or 'ost syste's with a single printer port) designated as L#T-1 this would %e at address ,,, <dec= or 01,
Copyright 1998 Robert Woudsma, UPPER CANADA TECHN ! "#E$

<he&=. I" there was a second printer port; L#T-$ it!s address would %e H0$ <dec= or $1, <he&=. (s we have seen %e"ore) each L#T port has at least 0 sections. Each section has it!s own register) or I/O address. The data register is at the %ase address o" the L#T port The *tatus register is at the %ase address 41 o" the L#T port The 7ontrol register is at the %ase address4$ o" the L#T port

The ta%le %elow illustrates this arrange'entD

PT%/
Base address 8 ,ata register 8 999d:4;9h Base < / 8 Status register 8 99=d:4;=h Base < 1 8 (ontrol register 8 9=>d:4;Ah

PT%1
Base address 8 ,ata register 8 741d:1;9h Base < / 8 Status register 8 744d:1;=h Base < 1 8 (ontrol register 8 745d:1;Ah

In order to control the %its o" the control register we 'ust write to the %ase address 4 $ o" the L#T port we are connected through. 8otice that control lines 7;) 71 and 70 are inverted logic. This 'eans that when a @1A is written to that %it %y the progra') the logic level at the respective pin at the L#T port is @;A. Only 7$) the third %it at pin #1H) which controls the ( .., digital to analog converter is positive logic. It 'ust %e kept high 'ost o" the ti'e until it is %rought low to trigger the ( .., to read the data %us and deliver a corresponding analog output. Allo#ing for PT%/ or PT%1 I" there is only one L#T port on a co'puter then we could speci"y it!s data and control register directly %y using the appropriate address value. +ut your progra' 'ay %e used on a co'puter that has the inter"ace connected to either L#T-1 or L#T-$. Bour progra' 'ust have a si'ple way o" %eing a%le to de"ine which L#T port the inter"ace is connected to. Instead o" speci"ying the data and control registers using their address) use a varia%le such as @+aseA. In this way you will %e a%le to set the value o" the @+aseA varia%le to ,,, "or L#T-1 or set it to H$0 "or L#T-$. Look at the code "or the Option %uttons in the read2#rite2test progra' "or ideas on how this is done. (ode E3ample The code listing "or the read2#rite2test) on the "ollowing page shows how the so"tware 'anipulates the control lines o" the inter"ace %y writing various data values to the control register "or each read or write operation.

Copyright 1998 Robert Woudsma,

UPPER CANADA TECHN ! "#E$

1+

7ode listings "or igital and (nalog read and write


Read a digital -alue from the ;5156
#rivate *u% c'dreadI7lick<= Jplace si&th %it o" control port to 1 to allow 9E( 'ode Jkeep 0rd %it at a high to prevent analog output to respond Jand "irst %it to high to cause 7; at pin 1 to go low J<inverted logic= to 7ontrol the 1/$/. to read. #ort.(ddress K %ase 4 $ #ort.Galue K 01 Jnow read the data at the L#T port ata pins #ort.(ddress K %ase inval K #ort.Galue Jnow disa%le the read o" the 1/$/. %y setting the control Jport "irst %it) 7; to low and causing pin #1 to go high L %ut keep 7$; %it 0 high "or analog output #ort.(ddress K %ase 4 $ #ort.Galue K 0H J show the value that was read in the te&t %o& t&tinvalue K inval End *u%

Read an analog -alue through the A,(>9>5


#rivate *u% c'dreadanalogI7lick<= Jplace si&th %it o" control port to 1 to allow 9E( 'ode Jkeep third %it high to prevent analog output "ro' responding Jand "ourth %it to high to cause 70 at pin 11 to go low J<inverted logic= to 7ontrol the ( 7;,;/ to read. #ort.(ddress K %ase 4 $ #ort.Galue K // Jnow read the data at the L#T port ata pins #ort.(ddress K %ase inval K #ort.Galue Jnow disa%le the read o" the ( 7;,;/ %y setting the control Jport "ourth 70 to low and causing pin #11 to go high J%ut keep 7$; %it 0 high "or analog output #ort.(ddress K %ase 4 $ #ort.Galue K 0H J show the value that was read in the analog in te&t %o& t&tain K inval End *u%

Write a digital -alue through the ;56;5


#rivate *u% t&toutvalueIFey#ress<Fey(scii (s Integer= Jonly respond i" the E8TE9 has %een pressed I" Fey(scii K 10 Then J"irst check "or a valid value enteredD I" Gal<t&toutvalue.Te&t= M ; Or Gal<t&toutvalue.Te&t= N $.. Then >sg+o& OIllegal value entered PPO) v%E&cla'ation) O 9eally +ig E99O9O t&toutvalue.Te&t K OO Else Jset control port %it . to a low to allow a write L %ut keep 7$; %it 0 high to prevent Janalog output "ro' writing #ort.(ddress K %ase 4 $ #ort.Galue K / Jnow send the t&toutvalue to the data port #ort.(ddress K %ase #ort.Galue K Gal<t&toutvalue= Jnow %ring control port %it $ to high and low to %ring pin #1/ Jlow then high to latch the data to itJs output. #ort.(ddress K %ase 4 $ #ort.Galue K H #ort.Galue K / End I" End I" End *u%

Write an analog -alue through the A,669


#rivate *u% t&taoutIFey#ress<Fey(scii (s Integer= Jonly respond i" the E8TE9 has %een pressed I" Fey(scii K 10 Then J"irst check "or a valid value enteredD I" Gal<t&toutvalue.Te&t= M ; Or Gal<t&toutvalue.Te&t= N $.. Then >sg+o& OIllegal value entered PPO) v%E&cla'ation) O 9eally +ig E99O9O t&toutvalue.Te&t K OO Else Jset control port %it . to a low to allow a write L%ut keep 7$; %it 0 to a low to allow a write "ro' the analog output #ort.(ddress K %ase 4 $ #ort.Galue K ; Jnow send the t&toutvalue to the data port #ort.(ddress K %ase #ort.Galue K Gal<t&taout= Jnow %ring control port %it 0 to high and low to %ring pin #1H Jlow then high to latch the data to itJs output. #ort.(ddress K %ase 4 $ #ort.Galue K / #ort.Galue K ; End I" End I" End *u%

Copyright 1998 Robert Woudsma,

UPPER CANADA TECHN ! "#E$

11

You might also like