/* * main.c for the MIPSfpga core running on Nexys4 DDR board. * * This program: * (1) reads the switches on the Nexys4 DDR board and * (2) flashes the value of the switches on the LEDs */ //#include void delay(); //------------------ // main() //------------------ int main() { volatile int *IO_SWITCHES = (int*)0xbf800008; volatile int *IO_LEDR = (int*)0xbf800000; volatile int *IO_PUSHBUTTON = (int*)0xbf80000c; volatile int *IO_SEGEN_N = (int*)0xbf800010; volatile int *IO_SEG0_N = (int*)0xbf800014; volatile int *IO_SEG1_N = (int*)0xbf800018; volatile int *IO_SEG2_N = (int*)0xbf80001c; volatile int *IO_SEG3_N = (int*)0xbf800020; volatile int *IO_SEG4_N = (int*)0xbf800024; volatile int *IO_SEG5_N = (int*)0xbf800028; volatile int *IO_SEG6_N = (int*)0xbf80002c; volatile int *IO_SEG7_N = (int*)0xbf800030; volatile unsigned int switches, pushbutton; // 2 byte -> 16bits int cont = 0; int pulsaciones = 0; *IO_SEGEN_N = 0B111111110; delay(); while (1) { switches = *IO_SWITCHES; delay(); *IO_LEDR = 0x00; delay(); // Si el switch 0 se pone a 1, cada dígito se mostrará solo durante ¼ segundo if((switches & 0B0000000000000001) == 0B0000000000000001){ cont = 0; while(cont<=15){ *IO_SEG0_N = cont; delay(); cont++; } } switches = *IO_SWITCHES; delay(); // Si el switch 1 se pone a 1, los dígitos se mostrarán en orden decreciente. else if(((switches & 0B0000000000000010) >> 1) == 0B0000000000000001){ cont = 15; while(cont>=0){ *IO_SEG0_N = cont; delay(); delay(); delay(); delay(); cont--; } } pushbutton = *IO_PUSHBUTTON; switches = *IO_SWITCHES; delay(); else if((pushbutton & 0B0000000000000001)==1){ //----------------------------------- pulsaciones++; *IO_SEGEN_N = (0B11111110 << pulsaciones); delay(); if(*IO_SEGEN_N & 0B0000000000000010 == 0){ //----------------------------------- *IO_SEG1_N = *IO_SEG0_N; delay(); } else if(*IO_SEGEN_N & 0B0000000000000100 == 4){ *IO_SEG2_N = *IO_SEG1_N; delay(); *IO_SEG1_N = *IO_SEG0_N; delay(); } else if(*IO_SEGEN_N & 0B0000000000001000 == 8){ *IO_SEG3_N = *IO_SEG2_N; delay(); *IO_SEG2_N = *IO_SEG1_N; delay(); *IO_SEG1_N = *IO_SEG0_N; } } switches = *IO_SWITCHES; delay(); else{ cont = 0; while(cont<=15){ *IO_SEG0_N = cont; delay(); delay(); delay(); delay(); //Sleep(2000); cont++; } } } return 0; } void delay() { volatile unsigned int j; for (j = 0; j < (1000000); j++) ; // delay } void incremento(){ }