Advertisement
Paczek

lab2 stare

Oct 16th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.39 KB | None | 0 0
  1. #include <system.h>
  2. #include <stdio.h>
  3. #include <io.h>
  4.  
  5. #define  SW0 0x00000001
  6. #define  SW1 0x00000002
  7. #define  SW2 0x00000004
  8. #define  SW3 0x00000008
  9. #define  SW4 0x00000010
  10. #define  SW5 0x00000020
  11.  
  12. #define  L_NULL 0x00000000
  13. #define  LED0 0x00000001
  14. #define  LED1 0x00000002
  15. #define  LED2 0x00000004
  16. #define  LED3 0x00000008
  17. #define  LED4 0x00000010
  18. #define  LED5 0x00000020
  19. #define  LED6 0x00000040
  20.  
  21. #define  SEGA 0x00001
  22. #define  SEGB 0x00002
  23. #define  SEGC 0x00004
  24. #define  SEGD 0x00008
  25. #define  SEGE 0x00010
  26. #define  SEGF 0x00020
  27. #define  SEGG 0x00040
  28.  
  29. #define H_NULL 0x00000000
  30. #define ONE  SEGB | SEGC
  31. #define TWO  SEGA | SEGB | SEGD | SEGE | SEGG
  32. #define THREE SEGA | SEGB | SEGC | SEGD | SEGG
  33. #define FOUR  SEGB | SEGC | SEGF | SEGG
  34. #define FIVE  SEGA | SEGC | SEGD | SEGF | SEGG
  35. #define SIX  SEGA | SEGC | SEGD | SEGE | SEGF | SEGG
  36. #define CHAR_E SEGA | SEGD | SEGE | SEGF | SEGG
  37. #define CHAR_R SEGE | SEGG
  38.  
  39. int main() {
  40.     int sw, sw0, sw1, sw2, sw3, sw4, sw5;
  41.     short state = 0;
  42.    
  43.     IOWR(HEX_BASE, 0, 0);
  44.     IOWR(HEX_BASE, 1, 0);
  45.     IOWR(HEX_BASE, 2, 0);
  46.     IOWR(HEX_BASE, 3, 0);
  47.     IOWR(HEX_BASE, 4, 0);
  48.     IOWR(HEX_BASE, 5, 0);
  49.    
  50.     while (1){
  51.  
  52.         sw = IORD(SW_SLIDERS_BASE, 0);
  53.        
  54.         if       ((sw & sw0) && !(sw & (sw1 | sw2 | sw3 | sw4 | sw5))) {
  55.             IOWR(LEDS_BASE, 0, LED0);
  56.             IOWR(HEX_BASE, 0, ONE);
  57.         }else if ((sw & sw1) && !(sw & (sw0 | sw2 | sw3 | sw4 | sw5))) {
  58.             IOWR(LEDS_BASE, 0, LED1);
  59.             IOWR(HEX_BASE, 0, TWO);
  60.         }else if ((sw & sw2) && !(sw & (sw1 | sw0 | sw3 | sw4 | sw5))) {
  61.             IOWR(LEDS_BASE, 0, LED2);
  62.             IOWR(HEX_BASE, 0, THREE);
  63.         }else if ((sw & sw3) && !(sw & (sw1 | sw2 | sw0 | sw4 | sw5))) {
  64.             IOWR(LEDS_BASE, 0, LED3);
  65.             IOWR(HEX_BASE, 0, FOUR);
  66.         }else if ((sw & sw4) && !(sw & (sw1 | sw2 | sw3 | sw0 | sw5))) {
  67.             IOWR(LEDS_BASE, 0, LED4);
  68.             IOWR(HEX_BASE, 0, FIVE);
  69.         }else if ((sw & sw5) && !(sw & (sw1 | sw2 | sw3 | sw4 | sw0))) {
  70.             IOWR(LEDS_BASE, 0, LED5);
  71.             IOWR(HEX_BASE, 0, SIX);
  72.         }else if (!(sw & (sw0 | sw1 | sw2 | sw3 | sw4 | sw5))){
  73.             IOWR(LEDS_BASE, 0, L_NULL);
  74.             IOWR(HEX_BASE, 0, H_NULL);
  75.         }else {
  76.             IOWR(LEDS_BASE, 0, LED6);
  77.             IOWR(HEX_BASE, 0, CHAR_R);
  78.             IOWR(HEX_BASE, 1, CHAR_R);
  79.             IOWR(HEX_BASE, 2, CHAR_E);
  80.         }
  81.     }
  82.  
  83.     return 0;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement