Advertisement
Paczek

lab2 nowe

Oct 16th, 2019
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.42 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;
  41.    
  42.     IOWR(HEX_3_BASE, 0, 0);
  43.     IOWR(HEX_3_BASE, 1, 0);
  44.     IOWR(HEX_3_BASE, 2, 0);
  45.     IOWR(HEX_3_BASE, 3, 0);
  46.     IOWR(HEX_3_BASE, 4, 0);
  47.     IOWR(HEX_3_BASE, 5, 0);
  48.    
  49.     while (1){
  50.  
  51.         sw = IORD(SW_SLIDERS_BASE, 0);
  52.        
  53.         if       ((sw & SW0) && !(sw & (SW1 | SW2 | SW3 | SW4 | SW5))) {
  54.             IOWR(LEDS_GREEN_BASE, 0, LED0);
  55.             IOWR(HEX_3_BASE, 0, ONE);
  56.         }else if ((sw & SW1) && !(sw & (SW0 | SW2 | SW3 | SW4 | SW5))) {
  57.             IOWR(LEDS_GREEN_BASE, 0, LED1);
  58.             IOWR(HEX_3_BASE, 0, TWO);
  59.         }else if ((sw & SW2) && !(sw & (SW1 | SW0 | SW3 | SW4 | SW5))) {
  60.             IOWR(LEDS_GREEN_BASE, 0, LED2);
  61.             IOWR(HEX_3_BASE, 0, THREE);
  62.         }else if ((sw & SW3) && !(sw & (SW1 | SW2 | SW0 | SW4 | SW5))) {
  63.             IOWR(LEDS_GREEN_BASE, 0, LED3);
  64.             IOWR(HEX_3_BASE, 0, FOUR);
  65.         }else if ((sw & SW4) && !(sw & (SW1 | SW2 | SW3 | SW0 | SW5))) {
  66.             IOWR(LEDS_GREEN_BASE, 0, LED4);
  67.             IOWR(HEX_3_BASE, 0, FIVE);
  68.         }else if ((sw & SW5) && !(sw & (SW1 | SW2 | SW3 | SW4 | SW0))) {
  69.             IOWR(LEDS_GREEN_BASE, 0, LED5);
  70.             IOWR(HEX_3_BASE, 0, SIX);
  71.         }else if (!(sw & (SW0 | SW1 | SW2 | SW3 | SW4 | SW5))){
  72.             IOWR(LEDS_GREEN_BASE, 0, L_NULL);
  73.             IOWR(HEX_3_BASE, 0, H_NULL);
  74.         }else {
  75.             IOWR(LEDS_RED_BASE, 0, LED6);
  76.             IOWR(HEX_3_BASE, 0, CHAR_R);
  77.             IOWR(HEX_3_BASE, 1, CHAR_R);
  78.             IOWR(HEX_3_BASE, 2, CHAR_E);
  79.         }
  80.     }
  81.  
  82.     return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement