you should prepared dos based program for this
you should boot your computer in dos and launch that program
this reduces the error in measurement
here is code
/* Project To mesure the velocity of the moving vehicle */
/* Uses two status port of parallel pin no. 10 and 11 */
/* For pinouts Reference
http://www.ctips.com/spp.html */
/* Base address for parallel port is 0x378 in hex */
/* Base address for parallel input port is 0x379 in hex */
# include<stdio.h>
/* conio.h is needed for the clrscr() and gotoxy() */
#include<conio.h>
/* dos.h is needed for the inportb() and delay()*/
#include<dos.h>
#define PORT 0x379 /* Assign the address of parallel port to PORT */
#define MAX_COUNT 3000
void main()
{
/* Defines the count variable to store the counted time interval */
unsigned long count;
/* Defines the variable for the sensor data and the input port address */
int SENSOR_1, SENSOR_2, data;
/* Assigns the input port address to variable data */
data= inportb(PORT+1);
/* Assigns the Status of the sensor -1 to variable SENSOR_1 */
SENSOR_1=(data & 0x80)/0x80;
/* data&0x80 masks the binary value availabe in data with 0x80 and division by 0x80 returns the status of the Pin 11 */
/* Assigns the Status of the sensor -2 to variable SENSOR_2 */
SENSOR_2=(data & 0x40)/0x40;
while(!kbhit()) /* loop continues until any key is pressed */
{
while (!(SENSOR_1&SENSOR_2)) /* Scans whether both port data is one or not */
{ ;
}
while (SENSOR_1) /* checks whether sensor-1 data changed to zero or not */
{;
}
for(count=0; ;count++) /* Counts the time interval with 1ms Precision */
{
delay(1);
if(SENSOR_2!=1&&count==MAX_COUNT) /* Checks whether sensor-2 data has changed to zero or not and stops count porcess */
break;
}
clrscr();
gotoxy(10,20);
printf("Velocity= %.3ul m/s",1000/count);
}
}
/* End of the program to compute velocity of moving vehicle */