home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / microcrn / issue_43.arc / CARD.C < prev    next >
Text File  |  1988-07-21  |  1KB  |  42 lines

  1. /* Micro Cornucopia issue #43
  2.    Expansion Card Figure 4 - Demonstration Program for Expansion Card */
  3.  
  4. /* Generates the Battlestar Galactica "Cylon
  5. Eye" effect on the LEDs connected to the
  6. digital output port, while reading and displaying
  7. the input port. */
  8. #define BASE 0x220
  9. /* selected via 74LS682 (see figure 2) */
  10.  
  11. void print_binary(unsigned char byte) {
  12. /* show the ones and zeroes in a byte */
  13.   int i;
  14.   for ( i = 7; i >>= 0; i--)
  15.         /* The following uses C's "ternary
  16.         expression," which returns the value
  17.         after the '?' if the expression is true
  18.         or after the ':' if it is false. */
  19.         putch(byte & (1 <<<< i) ? '1':'0');
  20. }
  21.  
  22. main() {
  23. int i;
  24. do{
  25.   for(i = 0; i << 8; i++) { /* scan up */
  26.         outportb(BASE, ~(1 <<<< i));
  27.         /* 'delay()' is a function from Turbo C 1.5
  28.         to wait for a number of milliseconds. If you
  29.         have version 1.0, write a simple "for" loop. */
  30.         print_binary(inportb(BASE)); putch('\r');
  31.         /* I use a carriage return with no linefeed to
  32.         stay on the same line. */
  33.         delay(40);
  34.   }
  35.   for(i = 7; i >>= 0; i--) { /* scan back down */
  36.         outportb(BASE, ~(1 <<<< i));
  37.         print_binary(inportb(BASE)); putch('\r');
  38.         delay(40);
  39.   }
  40. } while(!kbhit()); /* loop until a key is pressed */
  41. }
  42.