home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 309_01 / dioboard.h < prev    next >
Text File  |  1990-03-20  |  2KB  |  95 lines

  1. /* dioboard.h */
  2.  
  3. #define DIOBASE 0x9227
  4. #define LEDS    0x9223
  5. #define SW      0x9225
  6. #define SEVENS  0x9224
  7. #define KEYS    0x9226
  8. #define ANALOG  0x9222
  9.  
  10. #const
  11. char table[16] = { 0x3f,6,0x5b,0x4f,0x66,0x6d,0x7d,7,0x7f,
  12.                    0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71 };
  13. char rowval[4] = { 0x70, 0xb0, 0xd0, 0xe0 };
  14. char key[20] =   {'0','4','8','C',
  15.                   '3','7','B','F',
  16.                   '2','6','A','E',
  17.                   '1','5','9','D'};
  18.  
  19. #code
  20.  
  21. initdio()
  22. {
  23.         char *dio;
  24.         dio = DIOBASE;
  25.         *dio = 0x83;
  26. }
  27.  
  28. writeleds( ch )
  29. char ch;
  30. {
  31.         char *leds;
  32.         leds = LEDS;
  33.         *leds = ch;
  34. }
  35.  
  36. readswitch()
  37. {
  38.         char *switches, data;
  39.         switches = SW;
  40.         data = *switches;
  41.         return data;
  42. }
  43.  
  44. readkey()            /* waits for a key press */
  45. {
  46.    int column, row;
  47.    char keyval, columndata, *keys;
  48.  
  49.    keys = KEYS;
  50.    row = 0; columndata = 15;
  51.    while( columndata == 15)
  52.    {
  53.         *keys = rowval[row];
  54.         columndata = *keys & 0x0f;
  55.         row++; if( row > 3 ) row = 0;
  56.    }
  57.    if( columndata == 14 ) column = 0;
  58.    else if( columndata == 13 ) column = 1;
  59.    else if( columndata == 11 ) column = 2;
  60.    else if( columndata == 7  ) column = 3;
  61.    else column = 4;
  62.    row = row << 2;
  63.    if( column == 4 ) keyval = '\0'; else keyval = key[row+column];
  64.    return keyval;
  65. }
  66.  
  67. writeseg( ch )
  68. char ch;
  69. {
  70.         char value, *sevenseg;
  71.  
  72.         if( ch >= 'a' )  ch = (ch - 'a') + 10;
  73.         if (ch >= 'A') ch = (ch - 'A') + 10;
  74.         if( ch >= '0' ) ch = ch - '0';
  75.         if( ch > 15 ) return -1;
  76.         value = table[ch];
  77.         sevenseg = SEVENS;
  78.         *sevenseg = value;
  79. }
  80.  
  81. readanalog( chn )       /*multiply by 20 to give millivolts*/
  82. int chn;
  83. {
  84.         char channel, data, *analog;
  85.  
  86.         if( chn > 7 ) return -1;
  87.         analog = ANALOG;
  88.         channel = chn;
  89.         *analog = channel;
  90.         while( (*analog & 1) != 1 )
  91.                 ;
  92.         data = *(analog - 1);
  93.         return data;
  94. }
  95.