/**************************************************/ /* Software control function generator */ /* Using the printer port */ /* Free running Sine wave generator */ /* Frequency depends on the loop value entered */ /**************************************************/ #include #include #include #include unsigned char inval, top, topcnt, printcontrol ; int loop, base, angle ; /***********************************************/ /* Reads the input data */ /***********************************************/ unsigned char readport() { unsigned char dummy ; dummy = inp(base + 2) ; outp((base + 2), (dummy & 0X0D)) ; inval = (inp(base + 1) & 0XF0) >> 4 ; outp((base + 2), (dummy | 0X02)) ; inval = (inval | inp(base + 1) & 0XF0) ^ 0X88 ; return inval ; } /***********************************************/ /* Reads a port and prints the value */ /***********************************************/ unsigned char readwrite() { inval = readport() ; gotoxy(10, 17) ; printf("%d",inval) ; return inval ; } /*************************************************/ /* output a test waveform */ /*************************************************/ void out_test() { int angabs ; float sinang ; unsigned int cnt ; unsigned char inprt ; sinang = 511 * sin(angle * 0.017453) ; angabs = sinang ; cnt = angabs ; cnt = cnt & 0X03FF ; if(cnt <= 0X0200) cnt = cnt + 0X01FF ; else cnt = cnt - 0X0200 ; inprt = cnt ; topcnt = cnt >> 8 ; topcnt = topcnt & 0X03 ; if (topcnt == 0X00) top = (top & 0X02) | 0X01 ; if (topcnt == 0X01) top = top & 0X02 ; if (topcnt == 0X02) top = top | 0X05 ; if (topcnt == 0X03) top = (top & 0X02) | 0X04 ; gotoxy(10, 15) ; printf("Angle %3d Binary %4x LSB %2x MSB %2x",angle, cnt, inprt, top) ; outp(base, inprt) ; outp(base + 2, top) ; angle = angle + 1 ; if (angle >= 360) angle = 0 ; delay(loop) ; } /*****************************************************/ /* Main Program */ /*****************************************************/ int main(void) { int LPT1 = 0X378 ; int LPT2 = 0X278 ; int LPT3 = 0X3BC ; int dummy ; clrscr() ; base = LPT2 ; top = 0 ; angle = 0 ; printf ("FREE RUNNING SINE WAVE GENERATOR \n\n") ; printf ("Enter loop delay ") ; scanf("%d", &loop) ; fflush(stdin) ; while (!kbhit()) out_test() ; return 0 ; }