Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <io.h>
- #include <system.h>
- /* Przełączniki */
- #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
- #define SW10 0x00000400
- #define SW11 0x00000800
- #define SW12 0x00001000
- #define SW13 0x00002000
- #define SW14 0x00004000
- #define SW15 0x00008000
- #define SW16 0x00010000
- #define SW17 0x00020000
- /* PushButtony */
- #define KEY1 0x00000002
- #define KEY2 0x00000004
- #define KEY3 0x00000008
- /* Ledy */
- #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
- #define LED10 0x00000400
- #define LED11 0x00000800
- #define LED12 0x00001000
- #define LED13 0x00002000
- #define LED14 0x00004000
- #define LED15 0x00008000
- #define LED16 0x00010000
- #define LED17 0x00020000
- /* Segmenty HEX */
- #define SEGA 1
- #define SEGB 2
- #define SEGC 4
- #define SEGD 8
- #define SEGE 16
- #define SEGF 32
- #define SEGG 64
- int main() {
- printf("Hello from Nios II!\n");
- /* Litery i cyfry z hex 7 segmentowych */
- int HEX0 = SEGA|SEGB|SEGC|SEGD|SEGE|SEGF;
- int HEX1 = SEGB|SEGC;
- int HEX2 = SEGA|SEGB|SEGG|SEGE|SEGD;
- 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 HEX7 = SEGA|SEGB|SEGC;
- 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 HEXA = SEGA|SEGB|SEGC|SEGE|SEGF|SEGG;
- int HEXF = SEGA|SEGE|SEGF|SEGG;
- int HEXC = SEGA|SEGE|SEGF|SEGD;
- int HEXD = SEGB|SEGC|SEGD|SEGE|SEGG;
- /* Stan do sprawdzenia jaki przycisk jest wciśnięty */
- int state = 0;
- /* Pętla nieskończona w której działa program */
- while(1) {
- /* Pobranie panelu switchów */
- int switches = IORD(SW_SLIDERS_BASE,0);
- /* Odczyt który slajder został użyty */
- state = switches & (SW0|SW1|SW2|SW3|SW4|SW5|SW6);
- /* Robienie czegoś w zależności jaki slider został użyty */
- switch(state) {
- case 0:
- /* Reset wszystkich diod i segmentów, żaden slider nie został użyty*/
- /* !!!UWAGA!!!
- Jeśli jest jakiś problem z odczytywanie tych nazw LEDS_GREEN itp to używamy adresów typu 0x00000030, które można odczytać w Qsys lub z pliku system.h znajdującego się w bibliotece BSP danego projektu)
- */
- IOWR(LEDS_BASE,0,0);
- IOWR(HEX_BASE,0,0);
- break;
- case 1:
- /* Zapala diode na pozycji 0 przy uzyciu slidera na pozycji 0 */
- IOWR(LEDS_BASE,0,LED0);
- /* Instrukcja segmentów HEX:
- Pierwszy z lewej: Po prostu nazwa zdefiniowanej cyfry lub liczby HEX__
- Drugi od lewej: (HEX__ << 8)
- Trzeci z lewej: (HEX__ << 16)
- Czwarty z lewej: (HEX__ << 24)
- Na przykład:
- IOWR(HEX_BASE, (HEX3 << 24) | (HEX2 <<16) | (HEX1 <<8) |HEX0);
- Wyświetli: |0|1|2|3|
- */
- IOWR(HEX_BASE,0,HEX1);
- int subSwitches = IORD(SW_SLIDERS_BASE,0);
- if((subSwitches & SW7) && (subSwitches & SW8)) {
- IOWR(LEDS_BASE,0,LED17);
- IOWR(HEX_BASE,0,((HEXE<<24) | (HEXr<<16) | (HEXr<<8)));
- } else if(subSwitches & SW7) {
- IOWR(LEDS_BASE,0,LED7);
- IOWR(HEX_BASE,0,(HEXA<<8));
- } else if(subSwitches & SW8) {
- IOWR(LEDS_BASE,0,LED8);
- IOWR(HEX_BASE,0,(HEXF<<8));
- }
- break;
- case 2:
- IOWR(LEDS_BASE,0,LED1);
- IOWR(HEX_BASE,0,HEX2);
- break;
- case 4:
- IOWR(LEDS_BASE,0,LED2);
- IOWR(HEX_BASE,0,HEX3);
- break;
- case 8:
- IOWR(LEDS_BASE,0,LED3);
- IOWR(HEX_BASE,0,HEX4);
- int subSubSwitches = IORD(SW_SLIDERS_BASE,0);
- if(((subSubSwitches & SW9) && (subSubSwitches & SW10)) ||
- ((subSubSwitches & SW9) && (subSubSwitches & SW11)) ||
- ((subSubSwitches & SW9) && (subSubSwitches & SW12)) ||
- ((subSubSwitches & SW10) && (subSubSwitches & SW11)) ||
- ((subSubSwitches & SW10) && (subSubSwitches & SW12)) ||
- ((subSubSwitches & SW11) && (subSubSwitches & SW12))) {
- IOWR(LEDS_RED_BASE,0,LED17);
- IOWR(HEX_3_BASE,0,((HEXE<<24) | (HEXr<<16) | (HEXr<<8)));
- } else if(subSubSwitches & SW9) {
- IOWR(LEDS_BASE,0,LED9);
- IOWR(HEX_BASE,0,((HEXC<<16)| (HEX1 <<8)));
- } else if(subSubSwitches & SW10) {
- IOWR(LEDS_BASE,0,LED10);
- IOWR(HEX_BASE,0,((HEXC<<16)| (HEX2 <<8)));
- } else if(subSubSwitches & SW11) {
- IOWR(LEDS_BASE,0,LED11);
- IOWR(HEX_BASE,0,((HEXD<<16)| (HEX1 <<8)));
- } else if(subSubSwitches & SW12) {
- IOWR(LEDS_BASE,0,LED12);
- IOWR(HEX_BASE,0,((HEXD<<16)| (HEX2 <<8)));
- }
- break;
- case 16:
- IOWR(LEDS_BASE,0,LED4);
- IOWR(HEX_BASE,0,HEX5);
- break;
- case 32:
- IOWR(LEDS_BASE,0,LED5);
- IOWR(HEX_BASE,0,HEX6);
- break;
- case 64:
- IOWR(LEDS_BASE,0,LED6);
- IOWR(HEX_BASE,0,HEX7);
- break;
- default:
- /* Reset diod niebieskich, zapalenie ostatniej diody czerwonaj i wyświetlenie na HEX "Err"*/
- IOWR(HEX_BASE,0,((HEXE<<16) | (HEXr<<8) | HEXr));
- IOWR(LEDS_BASE,0,0);
- IOWR(LEDS_BASE,0,LED17);
- break;
- }
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment