Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <system.h>
- #include "altera_up_avalon_parallel_port.h"
- #include "sys/alt_irq.h"
- #define SW0 0x00000001
- #define SW1 0x00000002
- #define SW2 0x00000004
- #define SW3 0x00000008
- #define SW4 0x00000010
- #define SW5 0x00000020
- #define LEDG0 0x00000001
- #define LEDG1 0x00000002
- #define LEDG2 0x00000004
- #define LEDG3 0x00000008
- #define LEDG4 0x00000010
- #define LEDG5 0x00000020
- #define LEDR17 0x00020000
- #define SEGA 0b0000001
- #define SEGB 0b0000010
- #define SEGC 0b0000100
- #define SEGD 0b0001000
- #define SEGE 0b0010000
- #define SEGF 0b0100000
- #define SEGG 0b1000000
- typedef enum POZIOM_TEMP{
- POZIOM_0 = 0,
- POZIOM_1 = 1,
- POZIOM_2 = 2,
- POZIOM_3 = 4,
- POZIOM_4 = 8,
- POZIOM_5 = 16,
- POZIOM_6 = 32,
- POZIOM_7 = 64,
- POZIOM_8 = 128
- }TEMP;
- struct alt_up_dev
- {
- alt_up_parallel_port_dev * uchwytSW;
- alt_up_parallel_port_dev * uchwytLEDR;
- alt_up_parallel_port_dev * uchwytLEDG;
- alt_up_parallel_port_dev * uchwytHEX3;
- };
- void interrupt_handler(struct alt_up_dev* up_dev, alt_u32 id)
- {
- // Nie należy używać funkcji wykorzystujących przerwania (np. printf).
- // Należy pamiętać o wyzerowaniu źródła przerwania np. clear_edge_capture
- int state=0;
- int HEX0 = SEGA|SEGB|SEGC|SEGD|SEGE|SEGF;
- int HEX3 = SEGA|SEGB|SEGC|SEGD|SEGG;
- int HEX4 = SEGF|SEGG|SEGB|SEGC;
- int HEX5 = SEGA|SEGF|SEGG|SEGC|SEGD;
- int HEX6 = SEGA|SEGF|SEGG|SEGC|SEGD|SEGE;
- int HEX8 = SEGA|SEGB|SEGC|SEGD|SEGE|SEGF|SEGG;
- int HEX9 = SEGA|SEGB|SEGC|SEGD|SEGF|SEGG;
- int HEXE = SEGA|SEGF|SEGG|SEGE|SEGD;
- int HEXr = SEGE|SEGG;
- int switches = alt_up_parallel_port_read_data(up_dev->uchwytSW);
- state = switches & (SW0|SW1|SW2|SW3|SW4|SW5);
- alt_up_parallel_port_write_data(up_dev->uchwytLEDG, 0);
- alt_up_parallel_port_write_data(up_dev->uchwytHEX3, 0);
- alt_up_parallel_port_write_data(up_dev->uchwytLEDR, 0);
- switch(state){
- case 0:
- break;
- case 1:
- alt_up_parallel_port_write_data(up_dev->uchwytLEDG, LEDG0);
- alt_up_parallel_port_write_data(up_dev->uchwytHEX3, (HEX3<<8)| HEX0);
- break;
- case 2:
- alt_up_parallel_port_write_data(up_dev->uchwytLEDG, LEDG1);
- alt_up_parallel_port_write_data(up_dev->uchwytHEX3, (HEX3<<8)| HEX5);
- break;
- case 4:
- alt_up_parallel_port_write_data(up_dev->uchwytLEDG, LEDG2);
- alt_up_parallel_port_write_data(up_dev->uchwytHEX3, (HEX4<<8)| HEX0);
- break;
- case 8:
- alt_up_parallel_port_write_data(up_dev->uchwytLEDG, LEDG3);
- alt_up_parallel_port_write_data(up_dev->uchwytHEX3, (HEX6<<8)| HEX0);
- break;
- case 16:
- alt_up_parallel_port_write_data(up_dev->uchwytLEDG, LEDG4);
- alt_up_parallel_port_write_data(up_dev->uchwytHEX3, (HEX8<<8)| HEX0);
- break;
- case 32:
- alt_up_parallel_port_write_data(up_dev->uchwytLEDG, LEDG5);
- alt_up_parallel_port_write_data(up_dev->uchwytHEX3, (HEX9<<8)| HEX0);
- break;
- default:
- alt_up_parallel_port_write_data(up_dev->uchwytHEX3, (HEXE<<16) | (HEXr<<8) | HEXr);
- alt_up_parallel_port_write_data(up_dev->uchwytLEDG, 0);
- alt_up_parallel_port_write_data(up_dev->uchwytLEDR, LEDR17);
- break;
- }
- }
- int main()
- {
- while(1)
- {
- struct alt_up_dev up_dev;
- alt_up_parallel_port_dev *uchwytSW = alt_up_parallel_port_open_dev("/dev/SW_SLIDERS");
- alt_up_parallel_port_dev *uchwytLEDR = alt_up_parallel_port_open_dev("/dev/LEDS_RED");
- alt_up_parallel_port_dev *uchwytLEDG = alt_up_parallel_port_open_dev("/dev/LEDS_GREEN");
- alt_up_parallel_port_dev * uchwytHEX3 = alt_up_parallel_port_open_dev("/dev/HEX_3");
- if (uchwytSW != NULL)
- {
- up_dev.uchwytSW=uchwytSW;
- }
- if (uchwytLEDG != NULL)
- {
- up_dev.uchwytLEDG=uchwytLEDG;
- }
- if (uchwytLEDR != NULL)
- {
- up_dev.uchwytLEDR=uchwytLEDR;
- }
- if (uchwytHEX3 != NULL)
- {
- up_dev.uchwytHEX3=uchwytHEX3;
- }
- alt_irq_register(1, (void*) &up_dev, (void *) interrupt_handler);
- alt_up_parallel_port_set_interrupt_mask(uchwytSW, 0xff);
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement