December 98 Project : Computer Interface


Have you ever wanted to control devices from your computer. For example turn lights on/off, control electric motors or monitor events from outside your computer and then have the computer turn something on or dial a phone number. With this circuit you will be able to do all that through an interface connected to the parallel port and a program written in Qbasic. The program will give you the basic idea of how to control devices and how to monitor events. By modifying the program you can have the computer turn lights on while you are away from home or you could use it as a alarm system and have the computer dial a phone number. The possibilities are endless. Lets start with the circuit first and then discuss the program to control it. I will also be writing a program in Visual Basic so that you will be able to control the circuit directly from Windows 95/98.


The chart shows all the pins of a parallel printer port. You can see which pins we will be using for controlling output devices "O" and which ones will be used for input monitoring "I". Below is the actual circuit to control output devices. I have shown how to interface a relay and a light. You could have hooked up a motor or control a DC circuit.



This is a Quick Basic program to control the interface circuit. The program is very simple and can be built upon to be utilized for different applications.

'The following program is used to control the data lines

'This program will bring each data line high, one at a time.

'After each data line is brought high, the program waits for a key press before bringing the next line high

DataPort = &H3BC

'The DataPort value is the address of the parallel port

For I = 0 to 7

Out DataPort,2^I

Print "Data Port Bit ";I;"is high"

Print "Press any key to continue"

Do:Loop While Inkey$ =""

Next I

End


That's the whole program to turn on each output data line high which will turn on a relay and control other devices.

The next step is to read the status lines as inputs to monitor external devices. This can be accomplished by building the following circuit.


This Quick Basic Program will read 8 inputs at one time and display the value.

DataPort = &H3BC

StatusPort = DataPort + 1

ControlPort = DataPort + 2

StausMask = &H80

ControlMask = &HB

OUT ControlPort, 7 XOR ControlMask

'Brings C0 to C2 high and C3 low

DO

OUT ControlPort, &hF XOR ControlMask

'Brings C3 high then low to latch data

OUT ControlPort, 7 XOR ControlMask

C = INP(ControlPort) XOR ControlMask

'Read the control register

C = NOT(C)

'Invert the results because of the 7405 Inverters

C = C AND $h7

'Ignore bits 3 to 7

PRINT "Control Port =";HEX$(C)

'Display hex vaule of C0 to C2 Then dispaly each bit individually

FOR I = 0 TO 2

PRINT "Control Port Bit ";I;"=";(C AND 2^I)/2^I"

NEXT I

S = INP(StatusPort) XOR StausMask

'Read status register

S = S AND &hF8

'Ignore S0 to S2

PRINT "Status Port = ";HEX$(S)

'Display hex value of S3 to S7. Then display each bit individually

FOR I = 3 TO 7

PRINT "Status Port Bit ";I;"=";(S AND 2^I)/2^I

NEXT I

'Combine the 8 bits into a byte and display

PRINT "Byte read (C0-C2 + S3-S7) =";HEX$(C+S)

PRINT "Press any key to continue...."

DO: LOOP WHILE INKEY$=""

LOOP

END


That completes the project. With the two simply circuits and the code you can expand upon it to become anything you want it to do.

                                 Back to Projects Page                           Back to Home Page