/* SW1=BUSY: When SW1=0 run. When SW1=1 quit */ /* SW2=ACK: When SW2=0 flash. When SW2=1 show the count */ #include #include #define datalpt1 0x3BC /* LPT1's I/O port address for D0-D7*/ #define statlpt1 0x3BD /* status port address for LPT1 */ /* Notice: As shown in Chapter 18, in some PCs the port addresses of 378H,379H,and 37AH are assigned to LPT1. Modify the port addresses for your PC before you run it */ main() { int i; while(inp(statlpt1) & 0x80) /* keep monitoring bit 7 for BUSY */ { if(inp(statlpt1)&0x40) /* if ACK bit (bit 6) is high*/ for(i=0; i <= 0xFF;i++) /* then count up*/ { outp(datalpt1,i); /* and send it to LEDs*/ delay(200); /*and wait in between */ } else /* otherwise flash since ACK bit 6 is low */ { outp(datalpt1,0xFF); /* Turn on all LEDs */ delay(100); /* Wait */ outp(datalpt1,0x00); /* Now turn off all LEDs */ delay(100); /* wait. The flash rate is 100 ms */ } } } /* This example is adopted from a fine book "Technical C Programming" by Vincent Kassab, published by Prentice Hall */