Advertisement
Sothian

sw2

Oct 19th, 2019
475
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.58 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <system.h>
  3. #include "altera_up_avalon_parallel_port.h"
  4. #include "sys/alt_irq.h"
  5.  
  6. #define  SW0 0x00000001
  7. #define  SW1 0x00000002
  8. #define  SW2 0x00000004
  9. #define  SW3 0x00000008
  10. #define  SW4 0x00000010
  11. #define  SW5 0x00000020
  12.  
  13. #define  LEDG0 0x00000001
  14. #define  LEDG1 0x00000002
  15. #define  LEDG2 0x00000004
  16. #define  LEDG3 0x00000008
  17. #define  LEDG4 0x00000010
  18. #define  LEDG5 0x00000020
  19.  
  20. #define  LEDR17 0x00020000
  21.  
  22. #define  SEGA 0b0000001
  23. #define  SEGB 0b0000010
  24. #define  SEGC 0b0000100
  25. #define  SEGD 0b0001000
  26. #define  SEGE 0b0010000
  27. #define  SEGF 0b0100000
  28. #define  SEGG 0b1000000
  29.  
  30. typedef enum POZIOM_TEMP{
  31.     POZIOM_0 = 0,
  32.     POZIOM_1 = 1,
  33.     POZIOM_2 = 2,
  34.     POZIOM_3 = 4,
  35.     POZIOM_4 = 8,
  36.     POZIOM_5 = 16,
  37.     POZIOM_6 = 32,
  38.     POZIOM_7 = 64,
  39.     POZIOM_8 = 128
  40.  
  41. }TEMP;
  42.  
  43.  
  44.  
  45. struct alt_up_dev
  46. {
  47.     alt_up_parallel_port_dev * uchwytSW;
  48.     alt_up_parallel_port_dev * uchwytLEDR;
  49.     alt_up_parallel_port_dev * uchwytLEDG;
  50.     alt_up_parallel_port_dev * uchwytHEX3;
  51.  
  52. };
  53.  
  54. void interrupt_handler(struct alt_up_dev* up_dev, alt_u32 id)
  55. {
  56.      // Nie  należy używać funkcji wykorzystujących przerwania (np. printf).
  57.      // Należy pamiętać o wyzerowaniu źródła przerwania np. clear_edge_capture
  58.       int state=0;
  59.       int HEX0 = SEGA|SEGB|SEGC|SEGD|SEGE|SEGF;
  60.       int HEX3 = SEGA|SEGB|SEGC|SEGD|SEGG;
  61.       int HEX4 = SEGF|SEGG|SEGB|SEGC;
  62.       int HEX5 = SEGA|SEGF|SEGG|SEGC|SEGD;
  63.       int HEX6 = SEGA|SEGF|SEGG|SEGC|SEGD|SEGE;
  64.       int HEX8 = SEGA|SEGB|SEGC|SEGD|SEGE|SEGF|SEGG;
  65.       int HEX9 = SEGA|SEGB|SEGC|SEGD|SEGF|SEGG;
  66.       int HEXE = SEGA|SEGF|SEGG|SEGE|SEGD;
  67.       int HEXr = SEGE|SEGG;
  68.       int switches = alt_up_parallel_port_read_data(up_dev->uchwytSW);
  69.       state = switches & (SW0|SW1|SW2|SW3|SW4|SW5);
  70.       alt_up_parallel_port_write_data(up_dev->uchwytLEDG, 0);
  71.       alt_up_parallel_port_write_data(up_dev->uchwytHEX3, 0);
  72.       alt_up_parallel_port_write_data(up_dev->uchwytLEDR, 0);
  73.           switch(state){
  74.           case 0:
  75.                   break;
  76.           case 1:
  77.                   alt_up_parallel_port_write_data(up_dev->uchwytLEDG, LEDG0);
  78.                   alt_up_parallel_port_write_data(up_dev->uchwytHEX3, (HEX3<<8)| HEX0);
  79.                   break;
  80.           case 2:
  81.                 alt_up_parallel_port_write_data(up_dev->uchwytLEDG, LEDG1);
  82.                 alt_up_parallel_port_write_data(up_dev->uchwytHEX3, (HEX3<<8)| HEX5);
  83.                   break;
  84.           case 4:
  85.                 alt_up_parallel_port_write_data(up_dev->uchwytLEDG, LEDG2);
  86.                 alt_up_parallel_port_write_data(up_dev->uchwytHEX3, (HEX4<<8)| HEX0);
  87.                   break;
  88.           case 8:
  89.                 alt_up_parallel_port_write_data(up_dev->uchwytLEDG, LEDG3);
  90.                 alt_up_parallel_port_write_data(up_dev->uchwytHEX3, (HEX6<<8)| HEX0);
  91.                   break;
  92.           case 16:
  93.                 alt_up_parallel_port_write_data(up_dev->uchwytLEDG, LEDG4);
  94.                 alt_up_parallel_port_write_data(up_dev->uchwytHEX3, (HEX8<<8)| HEX0);
  95.                   break;
  96.           case 32:
  97.                 alt_up_parallel_port_write_data(up_dev->uchwytLEDG, LEDG5);
  98.                 alt_up_parallel_port_write_data(up_dev->uchwytHEX3, (HEX9<<8)| HEX0);
  99.                   break;
  100.  
  101.           default:
  102.                 alt_up_parallel_port_write_data(up_dev->uchwytHEX3, (HEXE<<16) | (HEXr<<8) | HEXr);
  103.                 alt_up_parallel_port_write_data(up_dev->uchwytLEDG, 0);
  104.                 alt_up_parallel_port_write_data(up_dev->uchwytLEDR, LEDR17);
  105.                   break;
  106.           }
  107.  
  108. }
  109.  
  110. int main()
  111. {
  112.  
  113.   while(1)
  114.   {
  115.  
  116.       struct alt_up_dev up_dev;
  117.       alt_up_parallel_port_dev *uchwytSW = alt_up_parallel_port_open_dev("/dev/SW_SLIDERS");
  118.       alt_up_parallel_port_dev *uchwytLEDR = alt_up_parallel_port_open_dev("/dev/LEDS_RED");
  119.       alt_up_parallel_port_dev *uchwytLEDG = alt_up_parallel_port_open_dev("/dev/LEDS_GREEN");
  120.       alt_up_parallel_port_dev * uchwytHEX3 = alt_up_parallel_port_open_dev("/dev/HEX_3");
  121.  
  122.  
  123.       if (uchwytSW != NULL)
  124.           {
  125.  
  126.           up_dev.uchwytSW=uchwytSW;
  127.           }
  128.       if (uchwytLEDG != NULL)
  129.           {
  130.           up_dev.uchwytLEDG=uchwytLEDG;
  131.           }
  132.       if (uchwytLEDR != NULL)
  133.           {
  134.           up_dev.uchwytLEDR=uchwytLEDR;
  135.           }
  136.       if (uchwytHEX3 != NULL)
  137.           {
  138.           up_dev.uchwytHEX3=uchwytHEX3;
  139.           }
  140.       alt_irq_register(1, (void*) &up_dev, (void *) interrupt_handler);
  141.  
  142.       alt_up_parallel_port_set_interrupt_mask(uchwytSW, 0xff);
  143.       };
  144.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement