home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_07_08 / v7n8123a.txt < prev    next >
Text File  |  1989-10-02  |  2KB  |  64 lines

  1.  
  2.  
  3. ******************************************************************************
  4.  
  5.                                  Listing 2
  6.  
  7.  
  8. #define LAMP_REG_1 (*((char *) (0x2808)))
  9. #define LAMP_REG_2 (*((char *) (0x2800)))
  10.  
  11. unsigned char shadow_1 = 0;
  12. unsigned char shadow_2 = 0;
  13.  
  14. enum LAMPS { RUN_LAMP, ERROR_LAMP, SETUP_LAMP, ALIGN_LAMP,
  15.              ALERT_LAMP, SURVEY_LAMP, BIT_LAMP, SPARE_1,
  16.              BATT_LAMP, CHARGE_LAMP, ZONE_LAMP, EAST_LAMP,
  17.              SPARE_2, SPARE_3, SPARE_4, SPARE_5, MID = 7 };
  18.  
  19. /*----------------------------------------------------------------------------
  20. MACRO to turn on a specific lamp. Use of literals of type LAMPS 
  21. for the parameter.
  22. ----------------------------------------------------------------------------*/
  23. #define turn_on( lamp ) \
  24. ( \
  25.      (lamp > MID) ? \
  26.      ( \
  27.           ( ( shadow_1 |= ( ( 1 << (lamp - 8) ) & 0xFF ) ) ) ,
  28.            (LAMP_REG_ 1 = shadow_1 )
  29.      ) \
  30.      : \
  31.      ( \
  32.           ( ( shadow_2 |= ( (1 << lamp) & 0xFF ) ) ) , \
  33.           LAMP_REG_1 = shadow_2) \
  34.      ) \
  35. ) \
  36.  
  37. /*----------------------------------------------------------------------------
  38. MACRO to turn off a specific lamp. Use literals of type
  39. LAMPS for the parameter.
  40. ----------------------------------------------------------------------------*/
  41. #define turn_off( lamp ) \
  42. ( \
  43.      (lamp > MID) ? \
  44.      ( \
  45.           ( shadow_1 &= ( ~( 1 << (lamp-8) ) & 0xFF) ), \
  46.           ( LAMP_REG_1 = shadow_1 ) \  
  47.      ) \
  48.      : \
  49.      ( \
  50.           ( shadow_2 &= ( ~(1 << lamp) ) & 0xFF ) ) , \
  51.           ( LAMP_REG_2 = shadow_2 ) \
  52.      ) \
  53. ) \
  54.  
  55. Note the use of the trinary operator instead of a control
  56. structure to decide which shadow register and lamp latch to
  57. update. The call to these macros looks like this:
  58.  
  59.      turn_on( RUN_LAMP ) ;
  60.      turn_off( RUN_LAMP ) ;      
  61.  
  62.  
  63. ******************************************************************************
  64.