Menu English Ukrainian russian Home

Free technical library for hobbyists and professionals Free technical library


ENCYCLOPEDIA OF RADIO ELECTRONICS AND ELECTRICAL ENGINEERING
Free library / Schemes of radio-electronic and electrical devices

Another life of the LPT port. Part 2. Encyclopedia of radio electronics and electrical engineering

Free technical library

Encyclopedia of radio electronics and electrical engineering / Computers

Comments on the article Comments on the article

To record signals on the LPT port, I recommend assembling a circuit (Fig. 1) consisting of eight switches and eight resistors with a resistance of 270 Ohm - 1 kOhm. With this position of the switches (buttons) SW1-SW8, there is a logical "1" on all upper contacts, when any one is closed, a logical "0" will appear on the corresponding contact. Pins can be connected directly to the D0-D7 bus (pins 2-9, address &H378) or to ERROR, SELECT, PAPER END, ACK, and -BUSY (pins 15, 13, 12, 10, and 11, address &H379).

Another life of LPT port
Fig. 1

To display data coming from the LPT port, I recommend the following scheme.

Another life of LPT port
Fig. 2

Resistors R1-R8 with a nominal value of 270 - 330 ohms, any LEDs, say AL307B. Such a circuit does not require power, everything will glow anyway. I brought all the signals to myself, everything is immediately visible. In general, I strongly recommend downloading the LPT 3D HARD Analyzer program at valery-us4leh.narod.ru/dlpt.html. Written by Valery Kovtun. With the help of this program ... in general, you will see for yourself.

Let's assemble a rectangular pulse generator on a K561LA7 chip. Power generator + 5V. The fact is that it is more convenient to assemble all devices, for example, on 155, 555 series, so that the signals have a TTL level. Logic "zero" 0-0,8V and log "one" 2,4-4,2V. The convenience of the 561 series lies in the versatility of the power supply - it works equally well from + 3V to + 12V. Therefore, the choice of microcircuits remains to your taste, the only question is to get rectangular pulses with an amplitude of no more than + 5V. A diagram of a simple pulse generator is shown in Figure 3.

Another life of LPT port
Fig. 3

The generator itself is assembled on the elements D1.1-D1.3, and I simply used the element D1.4 for more "beautiful" fronts of the output pulses. R1, R2, C1 - frequency setting elements. With these parameters of the elements, the generation frequency is approximately 5-7 Hz. For clarity, the operation of the generator can be represented in the form of the following graph:

Another life of LPT port
Fig. 4

The inverter output D1.4 is connected to pin 2 of the LPT connector (bus D0). Before using the generator, it is necessary to put the D0-D7 bus into the data receiving mode. To do this, we send 37 to &H43A.
The code is next. For those who use
inpout32.dll dlportio.dll DOS
Out&H37A, 43 DlPortWritePortUchar &H37A, 43 OUT&H37A, 43

After that, we start polling port &H378.
The code is next. For those who use
inpout32.dll dlportio.dll DOS
DimA as IntegerA = Inp(&H378) Dim A as IntegerDlPortReadPortUchar(&H378) DEFINT A-ZA=INP(&H378)

Variable A will take the value either 254 or 255. Why?
D0 D1 D2 D3 D4 D5 D6 D7  
20 21 22 23 24 25 26 27  
1 2 4 8 16 32 64 128  
1 1 1 1 1 1 1 1 255
0 1 1 1 1 1 1 1 254

The fact is that after the D0-D7 buses are switched to the data reception mode, they are set to the level of a logical unit (yellow row).

When the D0 level appears on the D0 bus, the log "0" (blue row) - the first bit takes the value of zero, which means 2 + XNUMX1+22+23+24+25+26+27 = 254.

Thus, we can track the change in the signal on the D0 bus, but if we count the number of changes in 1 second, we will get ... right - a digital frequency counter. Knowing number incoming impulses per second can be said about frequency in hertz.

So, the program is a frequency counter. The form should have 3 buttons and a Label. Button 1 start frequency meter, Button 2 stop, Button 3 - exit, Label - indicates the frequency.

*******************************************

For those using inpout32.dll

Option Explicit

'library declaration for working with port addresses

Private Declare Function Inp Lib "inpout32.dll" Alias ​​"Inp32" (ByVal PortAddress As Integer) As Integer

Private Declare Sub Out Lib "inpout32.dll" Alias ​​"Out32" (ByVal PortAddress As Integer, ByVal Value As Integer)

'library declaration for counting milliseconds

Private Declare Function GetTickCount Lib "kernel32" () As Long

Dim FTV As Long ' initial value of the system time

Dim STV As Long ' end value of the system time

Dim FV As Integer 'FV is the initial state of the port

Dim SV As Integer 'SV-comparable port state

Dim cntr 'pulse counter

Dim J As Integer 'J=1 count allowed, J=0 count not allowed

Private Sub Command1_Click ()

Out &H37A, 43 'we put tires D0-D7 into read mode

FTV = GetTickCount 'remembered system time in milliseconds

J = 1 'count - allow

FV = Inp(&H378) 'read port state

SV = FV 'SV equals port state

cntr = 0 'counter to zero

Do While J <> 0

DoEvents

STV = GetTickCount 'remember the current system time

If STV > FTV + 1000 Then FrequencyShow 'if a second has passed, display result

FV = Inp(&H378) 'constantly poll address &H378

If FV <> SV Then 'if the port state has changed

SV = FV 'SV equals port state

cntr = cntr + 0.5 ' counter + 0.5

End If

If J = 0 Then Exit Do 'if the user pressed Stop

loop

End Sub

Private Sub Command2_Click ()

'stop loop

'if the user pressed Stop

J = 0

End Sub

Private Sub Command3_Click ()

J = 0 'count - stop

Out &H37A, 0 'restore D0-D7 bus state

Unload me 'exit the program

End Sub

'Frequency display routine

Public SubFrequencyShow()

Label1.Caption = Int(cntr) & " Hz" 'display result

cntr = 0 'counter to zero

Pause (0.2) 'delay. Needed to measure low frequencies

FTV = GetTickCount 'remembered system time in milliseconds

End Sub

'Delay routine. Call format: Pause(number of seconds)

Public Sub Pause(Value As Single)

Dim Start, Finish

Start = Timer

Do While Timer < Start + Value

DoEvents

loop

Finish=Timer

End Sub

*******************************************

For those using dlportio.dll

Option Explicit

'library declaration for working with port addresses

Private Declare Function DlPortReadPortUchar Lib "dlportio.dll" (ByVal Port As Long) As Byte

Private Declare Sub DlPortWritePortUchar Lib "dlportio.dll" (ByVal Port As Long, ByVal Value As Byte)

'library declaration for counting milliseconds

Private Declare Function GetTickCount Lib "kernel32" () As Long

Dim FTV As Long ' initial value of the system time

Dim STV As Long ' end value of the system time

Dim FV As Integer 'FV is the initial state of the port

Dim SV As Integer 'SV-comparable port state

Dim cntr 'pulse counter

Dim J As Integer 'J=1 count allowed, J=0 count not allowed

Private Sub Command1_Click ()

DlPortWritePortUchar &H37A, 43 'put D0-D7 buses into read mode

FTV = GetTickCount 'remembered system time in milliseconds

J = 1 'count - allow

FV = DlPortReadPortUchar (&H378) 'read port state

SV = FV 'SV equals port state

cntr = 0 'counter to zero

Do While J <> 0

DoEvents

STV = GetTickCount 'remember the current system time

If STV > FTV + 1000 Then FrequencyShow 'if a second has passed, display result

FV = DlPortReadPortUchar (&H378) 'constantly poll address &H378

If FV <> SV Then 'if the port state has changed

SV = FV 'SV equals port state

cntr = cntr + 0.5 ' counter + 0.5

End If

If J = 0 Then Exit Do 'if the user pressed Stop

loop

End Sub

Private Sub Command2_Click ()

'stop loop

'if the user pressed Stop

J = 0

End Sub

Private Sub Command3_Click ()

J = 0 'count - stop

DlPortWritePortUchar &H37A, 0 'restore D0-D7 bus state

Unload me 'exit the program

End Sub

'Frequency display routine

Public SubFrequencyShow()

Label6.Caption = Int(cntr) & " Hz" 'display result

cntr = 0 'counter to zero

Pause (0.2) 'delay. Needed to measure low frequencies

FTV = GetTickCount 'remembered system time in milliseconds

End Sub

'Delay routine. Call format: Pause(number of seconds)

Public Sub Pause(Value As Single)

Dim Start, Finish

Start = Timer

Do While Timer < Start + Value

DoEvents

loop

Finish=Timer

End Sub

*******************************************

And all? You ask. Yes, that's all. That's the whole program, which for some reason works.

Ø As you can see, the code is almost the same for different libraries, therefore, in the following examples, we will consider the code only with the library dlportio.dll

If you carefully analyze the frequency counter program code, you will notice that 0.5 is added to the counter,

cntr = cntr + 0.5,

and not 1. The fact is that this program code considers the transition of the port state both from 1 to 0, and vice versa from 0 to 1, therefore, in order to count the frequency, you must either add 0.5, and then output

Label1.Caption = Int(cntr) & "hz"

Or add 1

cntr = cntr + 1,

And then output

Label1.Caption = Int(cntr/2) & "hz"

Here's the math.

By the way, have you tried to put some kind of sensor on the rotating shaft of some engine. Probably, with the help of this program you will get a wonderful tachometer J

Well, let's move on.

We take the same pulse generator and instead of the resistor R2 or R1 we solder the thermistor (the author of the article went to a car shop and bought a temperature sensor from a VAZ-30 for 2101 rubles). This temperature sensor changes its resistance depending on the temperature (3200 ohms at +140C and 143 Ohm at a temperature of +1000C.) Since we change the resistance, the frequency of the generator also changes, which means we get a converter temperature-frequency, i.e. digital thermometer. I want to draw your attention to the fact that the change in resistance depending on temperature does not occur linearly, as can be seen in the following graph,

Another life of LPT port
Fig. 5

therefore, "explaining" to the computer that 100 pulses is 20 degrees, and 110 pulses is 21 degrees will not be very easy, but nevertheless possible. The question is only in the size of the code and the algorithm.

If instead of a resistor we put a fuel sensor from the gas tank, then we get a liquid level indicator. It is more convenient to build such an indicator as follows:

1. We measure the pulse frequency with an empty tank

2. We add some volume (depending on what gradation - accuracy you want to get) and again measure the frequency

3. And so on to the very top of your container.

And you can build a liquid level indicator according to a different principle, if you assemble the structure in the figure below.

Another life of LPT port
Fig. 6

If the liquid level changes, then the position of the float with the magnet also changes, so the corresponding reed switches close (open). It is best to use a thin-walled plastic tube. The scheme of this device is as follows:

Another life of LPT port
Fig. 7

You can process information from such a device according to the following algorithm.

  1. Put buses at address &H378 in read mode.
  2. Empty tank - 255
  3. One division from the bottom - 254
  4. Two divisions from the bottom - 252
  5. Three divisions - 248
  6. Four divisions - 240
  7. Five divisions - 224, etc.

Ø Some may object to me that it is not necessary to put the D0-D7 buses into read mode, and this will work. To this I can only answer the following - whoever wants, let him not translate. I will not discuss this subject. If the &H378 port is not in data receive mode and the used pin (in our case 2 - D0 ) has a logical "1", then generator won't work. The output current of the D0-D7 bus in data transfer mode is greater than the output current of the CMOS chip (561LA7), so there will be no generation. Of course, if you short-circuit the contact to ground with tweezers, then no current will be enough. But it seems to me that it is not difficult to type an extra line of code and do as the developers of computer hardware advise.

Let's now consider the reverse process, i.e. the process of transferring data from a computer to your device. Let's take for example the same pulse generator, just change its circuit a little.

Another life of LPT port
Fig. 8

After applying power to the generator, we suddenly find that the generator is not working. And it will work only when the logical level "2" appears at the input 1.1 of the D1 element.

DlPortWritePortUchar &H378, 1

And everything immediately worked. Here is a computer controlled generator. Well, the generator is all small, although we must pay tribute to this device - in so many electronic circuits, it is the pulse generator that is taken as the basis. Why don't we connect something more serious to the computer.

Here is such a scheme

Another life of LPT port
Fig. 9

We connect the input of this device to any output we like, for example, to D3, we connect the GND input to the common wire of the connector, but + 12V will have to be taken from a separate power source. The relay can be taken automobile. In general, all the parameters of the elements can be completely different (I took what was at hand)

DlPortWritePortUchar &H378, 8

or

DlPortWritePortUchar &H378, 9

or

DlPortWritePortUchar &H378, 10

The main thing is that there should be a "3" log on the D1 bus. The relay will work, but what you pick up to it is your business. In general, when switching high-voltage devices, it is necessary (just in case) to protect yourself from short circuits, from breakdown to the case, in general, to do so. So that in case of an accident your wonderful LPT port does not burn out. Therefore, for such connections it is convenient to use the galvanic isolation of the port and your device, for example, through an optocoupler.

Another life of LPT port
Fig. 10

If everything in your device "burns out", then through the light - alas, the current will not pass, they have not yet come up with such a thing.

This is where the second part ends. Will there be a third part - I think it will, but here's what it will be about ...

Author: Alexey Klyushnikov, Ivanovo; Publication: cxem.net

See other articles Section Computers.

Read and write useful comments on this article.

<< Back

Latest news of science and technology, new electronics:

Artificial leather for touch emulation 15.04.2024

In a modern technology world where distance is becoming increasingly commonplace, maintaining connection and a sense of closeness is important. Recent developments in artificial skin by German scientists from Saarland University represent a new era in virtual interactions. German researchers from Saarland University have developed ultra-thin films that can transmit the sensation of touch over a distance. This cutting-edge technology provides new opportunities for virtual communication, especially for those who find themselves far from their loved ones. The ultra-thin films developed by the researchers, just 50 micrometers thick, can be integrated into textiles and worn like a second skin. These films act as sensors that recognize tactile signals from mom or dad, and as actuators that transmit these movements to the baby. Parents' touch to the fabric activates sensors that react to pressure and deform the ultra-thin film. This ... >>

Petgugu Global cat litter 15.04.2024

Taking care of pets can often be a challenge, especially when it comes to keeping your home clean. A new interesting solution from the Petgugu Global startup has been presented, which will make life easier for cat owners and help them keep their home perfectly clean and tidy. Startup Petgugu Global has unveiled a unique cat toilet that can automatically flush feces, keeping your home clean and fresh. This innovative device is equipped with various smart sensors that monitor your pet's toilet activity and activate to automatically clean after use. The device connects to the sewer system and ensures efficient waste removal without the need for intervention from the owner. Additionally, the toilet has a large flushable storage capacity, making it ideal for multi-cat households. The Petgugu cat litter bowl is designed for use with water-soluble litters and offers a range of additional ... >>

The attractiveness of caring men 14.04.2024

The stereotype that women prefer "bad boys" has long been widespread. However, recent research conducted by British scientists from Monash University offers a new perspective on this issue. They looked at how women responded to men's emotional responsibility and willingness to help others. The study's findings could change our understanding of what makes men attractive to women. A study conducted by scientists from Monash University leads to new findings about men's attractiveness to women. In the experiment, women were shown photographs of men with brief stories about their behavior in various situations, including their reaction to an encounter with a homeless person. Some of the men ignored the homeless man, while others helped him, such as buying him food. A study found that men who showed empathy and kindness were more attractive to women compared to men who showed empathy and kindness. ... >>

Random news from the Archive

The oldest coral 19.11.2008

At a depth of 400 meters near the Hawaiian Islands, a bush of coral with a height of a meter and a little was found. American oceanographers by radiocarbon analysis determined the age of the coral - about 4200 years.

On land, one of the pine species is distinguished by such longevity. It turns out that the coral grew at a rate of five microns per year. Ancient corals can serve to reconstruct climatic conditions (mainly ocean temperatures) over thousands of years of their life.

Other interesting news:

▪ A useful variety of corn for popcorn has been developed

▪ New technology instead of painful injections

▪ 24 GHz radar for motion and distance control

▪ DC-DC module Texas Instruments TPSM84209

▪ FOCL data transmitted over a record distance

News feed of science and technology, new electronics

 

Interesting materials of the Free Technical Library:

▪ section of the site Electricity for beginners. Article selection

▪ article And everywhere fatal passions, and there is no protection from fate. Popular expression

▪ article Why did the ace of cards go from one to the highest card? Detailed answer

▪ article First aid for drowning. Health care

▪ article Paper. Simple recipes and tips

▪ article Foreign integrated amplifiers of low frequency. Encyclopedia of radio electronics and electrical engineering

Leave your comment on this article:

Name:


Email (optional):


A comment:





All languages ​​of this page

Home page | Library | Articles | Website map | Site Reviews

www.diagram.com.ua

www.diagram.com.ua
2000-2024