Listing 4: From example.c.
void printchr(char c)
{
long retry = 0;
/* Set the data pins on the parallel port to the char */
iowr(lpt1_data, c);
/* If the printer is busy, it will miss the STROBE */
while (!(iord(lpt1_status) & NOTBUSY)) {
/* retry for up to 100 seconds */
if (++retry > 100000) {
printf("Printer busy. Exiting.\n");
exit(EXIT_FAILURE);
}
delay(1);
}
/* Turn on the STROBE pin on the parallel port. This causes the
* printer to read the data pins on the port. */
ioor(lpt1_control, STROBE);
/* We must hold STROBE for a time in microseconds, but we'll
* hold it for a millisecond since that's our smallest delay. */
delay(1);
/* Turn off STROBE, thus getting ready to write another char. */
ioand(lpt1_control, ~STROBE);
}