ENCYCLOPEDIA OF RADIO ELECTRONICS AND ELECTRICAL ENGINEERING Another life of the LPT port. Part 2. Encyclopedia of radio electronics and electrical engineering Encyclopedia of radio electronics and electrical engineering / Computers 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).
To display data coming from the LPT port, I recommend the following scheme.
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.
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:
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.
After that, we start polling port &H378.
Variable A will take the value either 254 or 255. Why?
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,
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.
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:
You can process information from such a device according to the following algorithm.
Ø 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.
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
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.
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. Latest news of science and technology, new electronics: Artificial leather for touch emulation
15.04.2024 Petgugu Global cat litter
15.04.2024 The attractiveness of caring men
14.04.2024
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
Leave your comment on this article: All languages of this page Home page | Library | Articles | Website map | Site Reviews www.diagram.com.ua |