/* * "Hello World" example. * * This example prints 'Hello from Nios II' to the STDOUT stream. It runs on * the Nios II 'standard', 'full_featured', 'fast', and 'low_cost' example * designs. It runs with or without the MicroC/OS-II RTOS and requires a STDOUT * device in your system's hardware. * The memory footprint of this hosted application is ~69 kbytes by default * using the standard reference design. * * For a reduced footprint version of this template, and an explanation of how * to reduce the memory footprint for a given application, see the * "small_hello_world" template. * */ #include #include "system.h" #include #include #include // sw_sliders #define SW0 0x00000001 #define SW1 0x00000002 #define SW2 0x00000004 #define SW3 0x00000008 #define SW4 0x00000010 #define SW5 0x00000020 #define SW6 0x00000040 #define SW7 0x00000080 #define SW8 0x00000100 #define SW9 0x00000200 // leds #define LED0 0x00000001 #define LED1 0x00000002 #define LED2 0x00000004 #define LED3 0x00000008 #define LED4 0x00000010 #define LED5 0x00000020 #define LED6 0x00000040 #define LED7 0x00000080 #define LED8 0x00000100 #define LED9 0x00000200 // hex #define SEGA 0x00001 #define SEGB 0x00002 #define SEGC 0x00004 #define SEGD 0x00008 #define SEGE 0x00010 #define SEGF 0x00020 #define SEGG 0x00040 // hex - numbers #define ZERO SEGA | SEGB | SEGC | SEGD |SEGE | SEGF #define ONE SEGB | SEGC #define TWO SEGA | SEGB | SEGG | SEGE | SEGD #define THREE SEGA | SEGB | SEGC | SEGD | SEGG #define FOUR SEGB | SEGC | SEGF | SEGG #define FIVE SEGA | SEGC | SEGD | SEGF | SEGG #define SIX SEGA | SEGC | SEGD | SEGE | SEGF | SEGG #define SEVEN SEGA | SEGB | SEGC #define EIGHT SEGA | SEGB | SEGC | SEGD | SEGE | SEGF | SEGG #define NINE SEGA | SEGB | SEGC | SEGD | SEGF | SEGG #define R SEGE | SEGG #define E SEGA | SEGD | SEGE | SEGF | SEGG #define O SEGC | SEGD | SEGE | SEGG void hex_print(int pos, int num) { if(num == 0) IOWR(HEX_BASE, pos, ZERO); if(num == 1) IOWR(HEX_BASE, pos, ONE); if(num == 2) IOWR(HEX_BASE, pos, TWO); if(num == 3) IOWR(HEX_BASE, pos, THREE); if(num == 4) IOWR(HEX_BASE, pos, FOUR); if(num == 5) IOWR(HEX_BASE, pos, FIVE); if(num == 6) IOWR(HEX_BASE, pos, SIX); if(num == 7) IOWR(HEX_BASE, pos, SEVEN); if(num == 8) IOWR(HEX_BASE, pos, EIGHT); if(num == 9) IOWR(HEX_BASE, pos, NINE); } int main() { IOWR(HEX_BASE, 4, 0x0); IOWR(HEX_BASE, 3, 0x0); IOWR(HEX_BASE, 2, 0x0); IOWR(HEX_BASE, 1, 0x0); IOWR(HEX_BASE, 0, 0x0); if(alt_timestamp_start() < 0){ printf("Brak timera w systemie\n"); } else{ alt_u32 time = 0; alt_u32 time2 = 0; int on = 0; int sw = 0; int leds = 0; int temp = 0; int p1 = 0, p2 = 0, p3 = 0, p4 = 0, p5 = 0; int off1 = 0, off2 = 0, off3 = 0, off4 = 0, off5 = 0; int er = 0; while(1){ sw = IORD(SW_SLIDERS_BASE, 0); if(sw != temp) { on = 0; switch(sw) { case 0: alt_timestamp_start(); break; case (SW0 | SW9): time = alt_timestamp(); time2 = alt_nticks(); if(p1 < 9) p1++; else er = 1; break; case (SW0): time = alt_timestamp(); time2 = alt_nticks(); if(p1 > 0) p1--; else er = 1; break; case (SW1 | SW9): time = alt_timestamp(); time2 = alt_nticks(); if(p3 < 9) p3++; else er = 1; break; case (SW1): time = alt_timestamp(); time2 = alt_nticks(); if(p3 > 0) p3--; else er = 1; break; case (SW2 | SW9): time = alt_timestamp(); time2 = alt_nticks(); if((p1 > 0)&&(p3 < 9)) { p1--; p3++; } else er = 1; break; case (SW2): time = alt_timestamp(); time2 = alt_nticks(); if((p1 < 9)&&(p3 > 0)) { p3--; p1++; } else er = 1; break; case (SW3 | SW9): time = alt_timestamp(); time2 = alt_nticks(); if((p2 > 0)&&(p4 < 9)) { p2--; p4++; } else er = 1; break; case (SW3): time = alt_timestamp(); time2 = alt_nticks(); if((p2 < 9)&&(p4 > 0)) { p4--; p2++; } else er = 1; break; case (SW4 | SW9): time = alt_timestamp(); time2 = alt_nticks(); if(p4 < 9) p4++; else er = 1; break; case (SW4): time = alt_timestamp(); time2 = alt_nticks(); if(p4 > 0) p4--; else er = 1; break; case (SW5 | SW9): time = alt_timestamp(); time2 = alt_nticks(); if(p2 < 9) p2++; else er = 1; break; case (SW5): time = alt_timestamp(); time2 = alt_nticks(); if(p2 > 0) p2--; else er = 1; break; case (SW6 | SW9): time = alt_timestamp(); time2 = alt_nticks(); if(p5 < 9) p5++; else er = 1; break; case (SW6): time = alt_timestamp(); time2 = alt_nticks(); if(p5 > 0) p5--; else er = 1; break; case (SW7 | SW9): time = alt_timestamp(); time2 = alt_nticks(); if((p2 > 0)&&(p5 < 9)) { p2--; p5++; } else er = 1; break; case (SW7): time = alt_timestamp(); time2 = alt_nticks(); if((p2 < 9)&&(p5 > 0)) { p5--; p2++; } else er = 1; break; case (SW8 | SW9): time = alt_timestamp(); time2 = alt_nticks(); if((p1 > 0)&&(p2 < 9)) { p1--; p2++; } else er = 1; break; case (SW8): time = alt_timestamp(); time2 = alt_nticks(); if((p1 < 9)&&(p2 > 0)) { p2--; p1++; } else er = 1; break; default: leds = 0; break; } temp = sw; } IOWR(HEX_BASE, 5, 0); switch(er) { case 1: if((alt_timestamp() - time) / alt_timestamp_freq() >= 1){ IOWR(HEX_BASE, 4, E); IOWR(HEX_BASE, 3, R); IOWR(HEX_BASE, 2, R); IOWR(HEX_BASE, 1, O); IOWR(HEX_BASE, 0, R); } if(alt_nticks() - time2 >= 2 * alt_ticks_per_second()){ IOWR(LEDS_BASE, 0, LED9); } if((alt_timestamp() - time) / alt_timestamp_freq() <= 3) break; if(alt_nticks() - time2 >= 3 * alt_ticks_per_second()){ er = 0; } break; case 0: if(on == 0) { off1 = 0; off2 = 0; off3 = 0; off4 = 0; off5 = 0; //sprawdzenie ktora dioda bedzie zgaszona if((leds & LED0) && (p1==0)) off1 = 1; if((leds & LED1) && (p2==0)) off2 = 1; if((leds & LED2) && (p3==0)) off3 = 1; if((leds & LED3) && (p4==0)) off4 = 1; if((leds & LED4) && (p5==0)) off5 = 1; leds = 0; if((p1 > 0) || (off1 == 1)) leds = leds | LED0; if((p2 > 0) || (off2 == 1)) leds = leds | LED1; if((p3 > 0) || (off3 == 1)) leds = leds | LED2; if((p4 > 0) || (off4 == 1)) leds = leds | LED3; if((p5 > 0) || (off5 == 1)) leds = leds | LED4; on = 1; } //opoznienie licznika osob if((alt_timestamp() - time) / alt_timestamp_freq() >= 1){ if(off1 == 1) hex_print(0, p1 + 1); else hex_print(0, p1); if(off2 == 1) hex_print(1, p2 + 1); else hex_print(1, p2); if(off3 == 1) hex_print(2, p3 + 1); else hex_print(2, p3); if(off4 == 1) hex_print(3, p4 + 1); else hex_print(3, p4); if(off5 == 1) hex_print(4, p5 + 1); else hex_print(4, p5); } //opoznienie swiatla w pokoju if(alt_nticks() - time2 <= 2 * alt_ticks_per_second()) break; IOWR(LEDS_BASE, 0, leds); if(off1) leds = leds & (~LED0); if(off2) leds = leds & (~LED1); if(off3) leds = leds & (~LED2); if(off4) leds = leds & (~LED3); if(off5) leds = leds & (~LED4); //opoznienie gaszenia swiatelka if(alt_nticks() - time2 <= 1 * alt_ticks_per_second()) break; IOWR(LEDS_BASE, 0, leds); if((alt_timestamp() - time) / alt_timestamp_freq() <= 2) break; hex_print(0, p1); hex_print(1, p2); hex_print(2, p3); hex_print(3, p4); hex_print(4, p5); break; } } } return 0; }