'ParPortTest johnf john.fisher@tauntonschool.co.uk 11 12 2004 'Use a LED & 1k resistor from output pins on 2 3 4 5 6 7 8 9 to common earth on 18-25. 'Uses reed switches to pull input pins to earth as input signal. ' They are pulled high internally; you are simply pulling down a mA or so... 'This means I do not have to worry about setting the 888 port to input via the control register. 'Instead I use the five available inputs on 10 11 12 13 15 ie port 889 ' and four more 1 14 16 17 ie port 890 ' out --------> LED-------> 1k ohm resistor--------> common earth. '888decimal = 378hex ( 8 outports d0 to d7) '889decimal = 379hex ( 5 inputs i3 to i7) so mask by 'and 11111000' ie 'and 248'. ' BEWARE!- i7 is internally inverted!! '890decimal = 37Ahex ( 4 inputs i0 to i3) so mask by 'and 00000111' ie 'and 7'. ' BEWARE! i1 and i3 are internally inverted!! ' SOME COMPUTERS USE 278 NOT 378 nomainwin WindowWidth = 860 WindowHeight = 440 UpperLeftX = 32 UpperLeftY = 32 graphicbox #w.g1, 780, 10, 10, 10 graphicbox #w.g2, 727, 50, 110, 10 graphicbox #w.g3, 727, 110, 110, 10 graphicbox #w.g4, 727, 170, 110, 10 textbox #w.t1, 020, 20, 820, 30 textbox #w.t2, 020, 80, 820, 30 textbox #w.t3, 020, 140, 820, 30 texteditor #w.t4, 020, 200, 820, 140 button #w.b, "Quit", [out_of_here] , UL, 380, 360, 64, 24 open "Parallel Port tester" for window_nf as #w #w "trapclose [out_of_here]" #w.t1, "!font courier_new 16" #w.t2, "!font courier_new 16" #w.t3, "!font courier_new 16" #w.t4, "!font courier_new 8" #w.t4, " The output port 378H is being refreshed with random values 4 times a second, & the input lines read too" #w.t4, " Change one of the inputs 379H & 37AH & see the value change (there is an extra colour mimic for b3 of port 379)" #w.t4, " NB While all 8 output lines are available & used" #w.t4, " the two input ports have only some available, and some of them are internally inverted" #w.t4, " Watch the effect as you pull ines low- you'll see the inversion." #w.t4, " I had just a switch on the mimic line b3 & LEDs on all eight data out lines" [begin] for a =1 to 1000 scan now =time$( "milliseconds") [loop] if time$( "milliseconds") -now <100 then goto [loop] p889 =inp( 889) if (p889 =126) then #w.g1, "fill red" else #w.g1, "fill green" for y=0 to 7 if mid$( bin$( p889), y+1, 1) ="1" then #w.g2, "down ; goto "; y*13; " 0 ; backcolor red ; boxfilled "; y*13+10; " 10 ; up" else #w.g2, "down ; goto "; y*13; " 0 ; backcolor green ; boxfilled "; y*13+10; " 10 ; up" end if next y #w.t1, " Decimal input on port 379 hex = "; p889; " and as binary = "; bin$( p889) p890 =inp( 890) for y=0 to 7 if mid$( bin$( p890), y+1, 1) ="1" then #w.g3, "down ; goto "; y*13; " 0 ; backcolor red ; boxfilled "; y*13+10; " 10 ; up" else #w.g3, "down ; goto "; y*13; " 0 ; backcolor green ; boxfilled "; y*13+10; " 10 ; up" end if next y #w.t2, " Decimal input on port 37A hex = "; p890; " and as binary = "; bin$( p890) p888 =int( 256 *rnd(1)) for y=0 to 7 if mid$( bin$( p888), y+1, 1) ="1" then #w.g4, "down ; goto "; y*13; " 0 ; backcolor red ; boxfilled "; y*13+10; " 10 ; up" else #w.g4, "down ; goto "; y*13; " 0 ; backcolor green ; boxfilled "; y*13+10; " 10 ; up" end if next y #w.t3, " Decimal output on port 378 hex = "; right$( "000" +str$(p888), 3); " and as binary = "; bin$( p888) out 888, p888 next a ' --------------------------------------------------------------- [out_of_here] close #w end function bin$( v) b$ ="" for l =0 to 7 re =v -int( v/2)*2 if re =0 then b$ =b$ +"0" else b$ =b$ +"1" v =int( v/2) next l bin$ =right$( "00000000" +b$, 8) end function