/* * 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(); void incrementoLento(); void incrementoRapido(); void decrementoLento(); void pulsaboton(); 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; //------------------ // main() //------------------ int main() { *IO_SEGEN_N = 0B111111110; delay(); while (1) { switches = *IO_SWITCHES; delay(); *IO_LEDR = 0x00; delay(); incrementoLento(); // pushbutton = *IO_PUSHBUTTON; // switches = *IO_SWITCHES; // delay(); // else if((pushbutton & 0B0000000000000001)==1){ //----------------------------------- // // } // switches = *IO_SWITCHES; // delay(); } return 0; } void delay() { volatile unsigned int j; for (j = 0; j < (1000000); j++) ; // delay } void incrementoLento(){ cont = 0; while(cont<=15){ switches = *IO_SWITCHES; delay(); pushbutton = *IO_PUSHBUTTON; delay(); // Si el switch 0 se pone a 1, cada dígito se mostrará solo durante ¼ segundo if((switches & 0B0000000000000001) == 0B0000000000000001){ incrementoRapido(); } // Si el switch 1 se pone a 1, los dígitos se mostrarán en orden decreciente. else if(((switches & 0B0000000000000010) >> 1) == 0B0000000000000001){ decrementoLento(); } else if((pushbutton & 0B0000000000011111)!=0){ pulsaboton(); } *IO_SEG0_N = cont; *IO_SEG1_N = cont; *IO_SEG2_N = cont; *IO_SEG3_N = cont; *IO_SEG4_N = cont; *IO_SEG5_N = cont; *IO_SEG6_N = cont; *IO_SEG7_N = cont; delay(); delay(); delay(); delay(); //Sleep(2000); cont++; } } void incrementoRapido(){ cont = 0; while(cont<=15){ switches = *IO_SWITCHES; delay(); // Si el switch 0 se pone a 1, cada dígito se mostrará solo durante ¼ segundo if((switches & 0B0000000000000001) == 0B0000000000000000){ incrementoLento(); } // Si el switch 1 se pone a 1, los dígitos se mostrarán en orden decreciente. else if(((switches & 0B0000000000000010) >> 1) == 0B0000000000000001){ decrementoLento(); } *IO_SEG0_N = cont; *IO_SEG1_N = cont; *IO_SEG2_N = cont; *IO_SEG3_N = cont; *IO_SEG4_N = cont; *IO_SEG5_N = cont; *IO_SEG6_N = cont; *IO_SEG7_N = cont; delay(); cont++; } } void decrementoLento(){ cont = 15; while(cont>=0){ switches = *IO_SWITCHES; delay(); // Si el switch 0 se pone a 1, cada dígito se mostrará solo durante ¼ segundo if((switches & 0B0000000000000001) == 0B0000000000000001){ incrementoRapido(); } // Si el switch 1 se pone a 1, los dígitos se mostrarán en orden decreciente. else if(((switches & 0B0000000000000010) >> 1) == 0B0000000000000000){ incrementoLento(); } *IO_SEG0_N = cont; *IO_SEG1_N = cont; *IO_SEG2_N = cont; *IO_SEG3_N = cont; *IO_SEG4_N = cont; *IO_SEG5_N = cont; *IO_SEG6_N = cont; *IO_SEG7_N = cont; delay(); delay(); delay(); delay(); cont--; } } void pulsaboton(){ pulsaciones++; //*IO_SEGEN_N = (0B11111110 << pulsaciones); switch (pulsaciones) { case 0: *IO_SEGEN_N = 0B11111110; break; case 1: *IO_SEGEN_N = 0B11111101; break; case 2: *IO_SEGEN_N = 0B11111011; break; case 3: *IO_SEGEN_N = 0B11110111; break; case 4: *IO_SEGEN_N = 0B11101111; break; case 5: *IO_SEGEN_N = 0B11011111; break; case 6: *IO_SEGEN_N = 0B10111111; break; case 7: *IO_SEGEN_N = 0B01111111; break; default: *IO_SEGEN_N = 0B11111111; *IO_LEDR = 0xFFFF; pulsaboton(); } // delay(); // display2= display1; // if(~(*IO_SEGEN_N) & 0B0000000000000100 == 0B0000000000000100){ //----------------------------------- // *IO_SEG1_N = cont; // delay(); // } // else if(~(*IO_SEGEN_N) & 0B0000000000001000 == 0B0000000000001000){ // *IO_SEG2_N = *IO_SEG1_N; // delay(); // *IO_SEG1_N = cont; // delay(); // } // else if(~(*IO_SEGEN_N) & 0B0000000000010000 == 0B0000000000010000){ // *IO_SEG3_N = *IO_SEG2_N; // delay(); // *IO_SEG2_N = *IO_SEG1_N; // delay(); // *IO_SEG1_N = cont; // delay(); // *IO_SEGEN_N = 0B11111110; // } // delay(); }