Advertisement
Sothian

Untitled

Nov 5th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.78 KB | None | 0 0
  1. #include <alt_types.h>
  2. #include <altera_avalon_pio_regs.h>
  3. #include <io.h>
  4. #include <sys/alt_irq.h>
  5. #include <system.h>
  6. #include <sys/alt_alarm.h>
  7.  
  8. #define A 1
  9. #define B 2
  10. #define C 4
  11. #define D 8
  12. #define E 16
  13. #define F 32
  14. #define G 64
  15.  
  16. int lastState = 0;
  17. int startTime = 0;
  18. int updateTimeLeds = 0;
  19. int updateTimeHex = 0;
  20.  
  21. int main() {
  22.     while (1) {
  23.         int state = IORD(SW_SLIDERS_BASE, 0);
  24.         state = state & (32 | 16 | 8 | 4 | 2 | 1);
  25.  
  26.         if (lastState != state) {
  27.             printf("up\n");
  28.             startTime = alt_nticks();
  29.  
  30.             switch (state) {
  31.             case 0:
  32.                 updateTimeLeds = 2;
  33.                 updateTimeHex = 1;
  34.                 break;
  35.             case 1:
  36.                 updateTimeLeds = 1;
  37.                 updateTimeHex = 2;
  38.                 break;
  39.             case 2:
  40.                 updateTimeLeds = 1;
  41.                 updateTimeHex = 2;
  42.                 break;
  43.             case 4:
  44.                 updateTimeLeds = 1;
  45.                 updateTimeHex = 2;
  46.                 break;
  47.             case 8:
  48.                 updateTimeLeds = 1;
  49.                 updateTimeHex = 2;
  50.                 break;
  51.             case 16:
  52.                 updateTimeLeds = 1;
  53.                 updateTimeHex = 2;
  54.                 break;
  55.             case 32:
  56.                 updateTimeLeds = 1;
  57.                 updateTimeHex = 2;
  58.                 break;
  59.             default:
  60.                 updateTimeLeds = 3;
  61.                 updateTimeHex = 1;
  62.                 break;
  63.             }
  64.  
  65.             //shouldRefresh = 1;
  66.         }
  67.  
  68.         if (((alt_nticks() - startTime)
  69.                 > (updateTimeLeds * alt_ticks_per_second()))) {
  70.  
  71.             switch (state) {
  72.             case 0:
  73.                 IOWR(LEDS_BASE, 0, 0);
  74.                 break;
  75.             case 1:
  76.                 IOWR(LEDS_BASE, 0, state);
  77.                 break;
  78.             case 2:
  79.                 IOWR(LEDS_BASE, 0, state);
  80.                 break;
  81.             case 4:
  82.                 IOWR(LEDS_BASE, 0, state);
  83.                 break;
  84.             case 8:
  85.                 IOWR(LEDS_BASE, 0, state);
  86.                 break;
  87.             case 16:
  88.                 IOWR(LEDS_BASE, 0, state);
  89.                 break;
  90.             case 32:
  91.                 IOWR(LEDS_BASE, 0, state);
  92.                 break;
  93.             default:
  94.                 IOWR(LEDS_BASE, 0, 32);
  95.                 break;
  96.             }
  97.         }
  98.  
  99.         if (((alt_nticks() - startTime)
  100.                 > (updateTimeHex * alt_ticks_per_second()))) {
  101.             //shouldRefresh = 0;
  102.             IOWR(HEX_BASE, 0, 0);
  103.             IOWR(HEX_BASE, 1, 0);
  104.             IOWR(HEX_BASE, 2, 0);
  105.  
  106.             switch (state) {
  107.             case 0:
  108.                 break;
  109.             case 1:
  110.                 IOWR(HEX_BASE, 0, A | F | G | C | D);
  111.                 IOWR(HEX_BASE, 1, A | B | G | E | D);
  112.                 break;
  113.             case 2:
  114.                 IOWR(HEX_BASE, 0, A | F | G | C | D);
  115.                 IOWR(HEX_BASE, 1, A | B | G | C | D);
  116.                 break;
  117.             case 4:
  118.                 IOWR(HEX_BASE, 0, A | F | G | C | D);
  119.                 IOWR(HEX_BASE, 1, F | G | C | B);
  120.                 break;
  121.             case 8:
  122.                 IOWR(HEX_BASE, 0, A | F | G | C | D);
  123.                 IOWR(HEX_BASE, 1, F | G | C | B);
  124.                 break;
  125.             case 16:
  126.                 IOWR(HEX_BASE, 0, A | F | G | C | D);
  127.                 IOWR(HEX_BASE, 1, A | F | G | C | D);
  128.                 break;
  129.             case 32:
  130.                 IOWR(HEX_BASE, 0, A | F | G | C | D);
  131.                 IOWR(HEX_BASE, 1, A | B | C);
  132.                 break;
  133.             default:
  134.                 IOWR(HEX_BASE, 0, E | G);
  135.                 IOWR(HEX_BASE, 1, E | G);
  136.                 IOWR(HEX_BASE, 2, A | F | G | E | D);
  137.                 break;
  138.             }
  139.         }
  140.  
  141.         lastState = state;
  142.     }
  143.  
  144.     return 0;
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement