| |
/* Prog for PWM on the parallel port */
/****************************************
*Because the ouput pulse was originaly *
*5.5 times what it should be, I divided *
*the on time and off time by 5. This *
*means the final pulse period is *
*slightly above the specified 0.8s *
*(+4x10-2) *
****************************************/
#include <stdio.h>
#include <conio.h>
#include <dos.h> /*For struct time*/
int LPT = 0x378; /* Assign a var name to parallel port*/
void main(void)
{
int i = 0;
struct time curTime; /*Create a variable called curTime of type struct time*/
struct time newTime; /*Create a variable called newTime of type struct time*/
while(1){
gettime (&curTime);
i = 0;
outp(LPT, 0xFF);/*Turn the pins HIGH*/
while (i < 9){ /*48 hundredths divided by 5.5, because inital pulse was out by a factor of 5.5*/
gettime(&newTime);
if(curTime.ti_hund != newTime.ti_hund){
curTime.ti_hund = newTime.ti_hund;
i++;
}
}
i = 0;
outp(LPT, 0x00);/*Turn the pins LOW*/
while (i < 6){ /*32 hundredths divided by 5.5, because inital pulse was out by a factor of 5.5*/
gettime(&newTime);
if(curTime.ti_hund != newTime.ti_hund){
curTime.ti_hund = newTime.ti_hund;
i++;
}
}
}
}
|