|
| |
|
|
SWITCH CONTROL SOFTWARE PROJECT
|
When I've decided to interface the switch to LPT port I felt into doubt a bit understanding that almost all modern PCs has a number of USB ports, probably one COM port and no parallel ports. Despite that, I've chosen LPT due to simplicity to understand how it works, at least in my project I should not care about handling output/input by complicated protocols or soldering sophisticated circuits.
|
Download VB6 sample project
| |
The functionality of the software in my project is straight enough - read the input (recognize which pushbutton of the device is pressed or command button of the application clicked), switch the appropriate relay and display related message on LCD. In other words it should work as simple as that - when I write a number to the port, voltages appear on the corresponding output pins and when 5v appear on the input pins I get the status of corresponding bits back. A few important topics described bellow.
Matching and meaning of LPT,LCD pins
Talking with LPT in Windows XP
Sending outputs
Reading inputs
Matching and meaning of LPT,LCD pins. In my project the following parallel port pins are used: data output pins 2-9, control output pins 1,16, status input pins 10,12,13,15 and ground pins 18-25. Please note, that four data bits (DB4-DB7) are used to send data to LCD module (4bit interface) and the rest four bits (DB0-DB3) are used to control relays. The soldering is performed accordingly. The matching of pins and their functionality is ilustrated in the figure below.
|
| LCD function |
LCD Pin |
LPT Pin |
LPT Function |
Project software function |
| Ground |
1 |
18-25 |
Ground |
- |
| VCC (+5V) |
2 |
- |
|
- |
| VO (Contrast voltage) |
3 |
- |
|
- |
| RS. Instruction input-0, Data input-1 |
4 |
16 |
Init |
Desides to send characters or control LCD |
| R/W. Write to LCD1-0, Read from LCD-1 |
5 |
18-25 |
Ground |
Writes to LCD only |
| E Enable signal |
6 |
1 |
Strobe |
Initiates data sending to LCD |
| DB0 |
7 |
2 |
DB0 |
Controls relay 1 |
| DB1 |
8 |
3 |
DB1 |
Controls relay 2 |
| DB2 |
9 |
4 |
DB2 |
Controls relay 3 |
| DB3 |
10 |
5 |
DB3 |
Controls relay 4 |
| DB4 |
11 |
6 |
DB4 |
Data to LCD |
| DB5 |
12 |
7 |
DB5 |
Data to LCD |
| DB6 |
13 |
8 |
DB6 |
Data to LCD |
| DB7 |
14 |
9 |
DB7 |
Data to LCD |
| - |
10 |
Ack |
Reads pushbutton 4 status |
| - |
12 |
Paper End |
Reads pushbutton 3 status |
| - |
13 |
Selected |
Reads pushbutton 2 status |
| - |
15 |
Error |
Reads pushbutton 1 status |
Talking with LPT in Windows XP. You definately know, that it's imposible to talk to parallel port in Win NT,2000,XP directly. The great tool to solve this issue is provided by Logix4U.net. They distribute freeware dll InpOut32.dll, which installs a kernel mode driver and allows to talk to parallel port through that driver. For the code developer it's almost enough to call functions Out32 and Inp32 to write or read data from specified port register. Check out the site for more detailed information.
|
Sending outputs. The content of the data sent to the parallel port tells to our device what relay should be swiched on or what data should be displayed on LCD. Every bit of the binary number controls one output bit. Here is the relation of the bits, parallel port output pins and the decimal value of those bits.
| Port Pin | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
| Bit | DB0 | DB1 | DB2 | DB3 | DB4 | DB5 | DB6 | DB7 |
| Value | 1 | 2 | 4 | 8 | 16 | 32 | 64 | 128 |
For example if you want to switch on all four relays simultaneously then you have to output value 1+2+4+8=15, that will make +5v on each of pins 2,3,4,5.
|
Reading inputs. PC parallel port has 5 input pins, four of them (15,10,12,13) are used in the project. To be able to read status of input pins we need to send TTL-level signals (0V=logic 0, 5V=logic 1). When the pushbutton is pressed, the assigned pin goes to logic state 0. The input pins can be read from the I/O address LPT port base address+1. Here is the relation of bits and port pins.
| Port Pin | - | - | - | 15 | 13 | 12 | 10 | 11 |
| Bit | S0 | S1 | S2 | S3 | S4 | S5 | S6 | S7 |
And finaly, the screenshot of the sample application
| |
|
|