xDRV-driver for LPT with interrupt service routine

Driver xDRV.sys is driver developed by Иванов Д. Ð’.(www.pcports.ru) and is capable to work(read write) with any PC port under windows NT, 2000, XP. But main advantage of this driver is that it can catch and handle LPT port interrupts (in this case LPT1 with address 0x378 with IRQ 07). Program part of xDRV Lets see how this driver can be put in action. First of all download packed archive with driver and library with functions. xDRV.sys <13.2kB> In this package you will find driver xDRV.sys, dynamical library xDRV.dll, statical library xDRV.lib, which may be needed while compiling project with statical connection of dll and header file with function prototype description which can control driver. Let see the functions: bool xDRV_OpenDriver(); Driver xDRV.sys is dynamically loadable. For loading this driver and initializing this function is used. If driver is loaded successfully, then function returns TRUE otherwise FALSE. This function has to be called one time at the beginning. If function returned FALSE then try to restart computer might be xDRV.sys already has been loaded to the memory and function xDRV_StopDriver() wasn’t used. Driver and library has to be placed in same directory where project files are. void xDRV_StopDriver(); As it…

Continue reading

Control LPT port under windows XP using Delphi

Another way of controlling LPT port under Windows 2000 and XP using Delphi language. In this case library inpout32.dll is used which allows controlling LPT port registers. Ready project for Borland Delphi 7.0 you can download here: Project Files<187.5kB> And now how to do this from beginning. Start Borland Delphi 7.0 and make simple form where you can enter Data to be sent to port, Port Address, buttons for writing to and reading from port.   If you are familiar with building forms this should be ease task. OK now lets start programming. First of all wee need somehow to include inpout32.dll in to the project. For this Delphi has several ways, but lets stay to the easiest one when library is in same directory, where project is. Then in header in section uses we have to place function prototypes Out32 and Inp32 with special compiler directive external, saying where to find this finction. uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; function Inp32(PortAdr: word): byte; stdcall; external ‘inpout32.dll’; function Out32(PortAdr: word; Data: byte): byte; stdcall; external ‘inpout32.dll’;   Then lets go to the button methods. For this double click on button in form and you will…

Continue reading

Controlling external devices using COM port communications programmed using VB language

There are a lot of Radio amateurs that want to control external devices using computer standard ports. One of them is COM poert. Everybody wants things to be ease as people doing electronics are more hardware people not software. COM port is more often used than LPT because COM port is more resistive to bigger loads and there is less chances of failing. So if you know Visual Basic a little bit then this shouldn’t be very hard to use MSComm Control component which is located in Project->Components. You should check check box MSComm Control. Later you have to add this control to form and write some code for it. Main difficulty with this is that you have to follow RS232 protocol. This is why it is better to use microcontrollers that have built in USART interface. Of course MSComm component allows to read and control single COM pins and this way to control any external devices without using RS232 protocol. One good example is popular programming software PonyProg (which is programmed in other language than VB, but principals are same). You can see various supported circuits that PonyProg supports and you can see that Rx(2) and Tx(3) signals aren’t…

Continue reading

Sample routine of working with LPT1 port under windows XP in CPP language

This is simple routine of sending and reading of byte from LPT1 port under Windows XP. LPT port has four types of pins: 8 output pins accessed via the DATA Port 5 input pins (one inverted) accessed via the STATUS Port 4 output pins (three inverted) accessed via the CONTROL Port The remaining 8 pins are grounded Now we are interested in Data pins. Set up driver according to post: Acces LPT and COM ports easily under windows NT-2000-XP. I have written and compiled example under DEV-CPP tool-set, which you can download from https://www.bloodshed.net/. Start New console project Create new cpp file and save it to project directory. Also copy porttalk_IOCTL.h and pt_ioctl.c files to project directory. These files you will find in the package portalk22.zip. Test program: Compile this program and run it. You should see results like this: Now it is time to connect your microcontroller and start experimenting. Good luck. Test routine project files for DEV-CPP are here:LPT1 Sample Project

Continue reading

Program LPT and COM ports easily under windows NT-2000-XP

If you are working with embedded projects usually you have concerned about how directly control computer ports like LPT or COM. Basically no one wants to mess up with driver writing or reading tons of documentations in order to send some bytes via IO port to your target board. Earlier when DOS, win95 and win98 operating systems were popular accessing I/O ports was easy as there weren’t any protections – simple code could do the job. Under NT/2000/XP situation is different. These operating systems has strict control of I/O ports. Read more about this here: www.beyondlogic.org. If you will try to access ports directly under windows XP, then you will get error mesage: How to solve this problem without writing your own driver and without rewriting old DOS or win98 programs. Well there is a solution that allow you to run programs under windows 2000/XP and talk to ports directly. Download PortTalk program from www.beyondlogic.org. Now you have two ways of running programs – but don’t forget to read porttalk.pdf which is included in package. Solution No.1 Download portalk22.zip and unzip it in separate folder somewhere. Then copy allowio.exe directly to the directory where is you program which you want…

Continue reading

Variables in embedded C programming language

What are variables in C language. Variables are simple keywords which are defined by the values. Values can be changed. Variables are like a boxes with some size where values like apples can be put in. So variables can be various forms and sizes so called variable types. Variable type is defined by a reserved word which indicates the type and size of variable identifier: unsigned char my_char; long int all_my_numbers; int number; Why do we need variables? The basic answer is that memory is limited and compiler needs to know much space to reserve for each variable. The coder needs to specify the variable type and its size by using one of reserved words from the table:

Continue reading

Gauss-Zeidel optimization routines

This is simplest optimization routines. Using this algorithm optimization parameters are changed separately in each step. Only one parameter can be changed in one step while other are helt as constants. Xk+1=Xk+ΔXk , k=0,1,2,… ΔXk step of parameter Xk. Parameter is changed until function growth is noticed, and then next parameter follows and so on. After cycle with all parameters is completed, then step is changed to half of its value and repeat cycle again. Optimal point searching ends when there is no function increase and last point is held as optimal point. Lets see how it works with following function: Its plot: Using MATLAB script we get results bellow. In each picture start coordinates are different. Start coordinates. x=150; y=200; Start coordinates x=50; y=150; Other example Start coordinates x=10; y=10; Start coordinates x=100; y=200; Third example Start coordinates x=10; y=10; Start coordinates x=50; y=200; Matlab script: close all; clear all; clc; [X,Y] = meshgrid(-100:1:100, -100:1:100); Z =3*exp(-((X.^2)/78000) -((Y.^2)/20000))-5*exp(-(((X+31).^2)/123) -(((Y+20).^2)/5000)); xx=100; yy=100; contour3(Z,20); hold on; % figure(2); mesh(Z); % figure % plot3(X,Y,Z) X=70; Y=100; X1=0;Y1=0; X0=X; Y0=Y; z=160; figure(1); plot(X,Y,’r*’), hold on; X=X-xx; Y=Y-yy; TT1 =3*exp(-((X.^2)/78000) -((Y.^2)/20000))-5*exp(-(((X+31).^2)/123) -(((Y+20).^2)/5053)); for i=1:50 z=z/2; X=X-z; Z2 =3*exp(-((X.^2)/78000) -((Y.^2)/20000))-5*exp(-(((X+31).^2)/123) -(((Y+20).^2)/5053)); if Z2>=TT1 TT=Z2; X1=X;…

Continue reading