Below is the code for my clock.
The 2nd switch function doesn't operate properly. After it goes through all the cases from 1-5, it doesn't loop back. I think I've misunderstood the purpose of default. I thought it switches into default whenever it doesn't match the case.
I've tried inserting my countersec2=0; at the end of the 2nd switch function but it doesn't work. any ideas?
Well to be more precise, it doesn't display 1-5 again on the hardware im using, but it still counts up. So its reaching countersec2++; but i don't have a way of resetting the countersec2 to be able to loop the 2nd switch function. btw i haven't put the countersec2=0; in the code below..
oops nevermind i just did it lol. i put the countersec2=0; at the end of default.Code:while(1) { //if(IORD_ALTERA_AVALON_PIO_DATA(TICK_PIO_BASE) ^ 1) //{/*this checks to see if you have pressed hte button or not IORD_ALTER... is the button*/ countersec++; switch (countersec) { case 1: led = hex_num[1]; IOWR_ALTERA_AVALON_PIO_DATA(LED_10HRS_PIO_BASE, led); break; case 2: led = hex_num[2]; IOWR_ALTERA_AVALON_PIO_DATA(LED_10HRS_PIO_BASE, led); break; case 3: led = hex_num[3]; IOWR_ALTERA_AVALON_PIO_DATA(LED_10HRS_PIO_BASE, led); break; case 4: led = hex_num[4]; IOWR_ALTERA_AVALON_PIO_DATA(LED_10HRS_PIO_BASE, led); break; case 5: led = hex_num[5]; IOWR_ALTERA_AVALON_PIO_DATA(LED_10HRS_PIO_BASE, led); break; case 6: led = hex_num[6]; IOWR_ALTERA_AVALON_PIO_DATA(LED_10HRS_PIO_BASE, led); break; case 7: led = hex_num[7]; IOWR_ALTERA_AVALON_PIO_DATA(LED_10HRS_PIO_BASE, led); break; case 8: led = hex_num[8]; IOWR_ALTERA_AVALON_PIO_DATA(LED_10HRS_PIO_BASE, led); break; case 9: led = hex_num[9]; IOWR_ALTERA_AVALON_PIO_DATA(LED_10HRS_PIO_BASE, led); break; default: led = hex_num[0]; IOWR_ALTERA_AVALON_PIO_DATA(LED_10HRS_PIO_BASE, led); countersec2++; printf("countersec2:\n%d\n", countersec2); switch (countersec2) { case 1: led = hex_num[1]; IOWR_ALTERA_AVALON_PIO_DATA(LED_10HRS2_PIO_BASE, led); break; case 2: led = hex_num[2]; IOWR_ALTERA_AVALON_PIO_DATA(LED_10HRS2_PIO_BASE, led); break; case 3: led = hex_num[3]; IOWR_ALTERA_AVALON_PIO_DATA(LED_10HRS2_PIO_BASE, led); break; case 4: led = hex_num[4]; IOWR_ALTERA_AVALON_PIO_DATA(LED_10HRS2_PIO_BASE, led); break; case 5: led = hex_num[5]; IOWR_ALTERA_AVALON_PIO_DATA(LED_10HRS2_PIO_BASE, led); break; default: led = hex_num[0]; IOWR_ALTERA_AVALON_PIO_DATA(LED_10HRS2_PIO_BASE, led); break; }//second switch case ends. printf("countersec:\n%d\n", countersec); countersec=0; }//switch case ends. //while(IORD_ALTERA_AVALON_PIO_DATA(TICK_PIO_BASE) ^ 1) // { // random++; // } /*this makes it pause after you press the button*/ i =0; while(i<300000) i++; }
though when i tried that for the 1st switch case it didn't work.



LinkBack URL
About LinkBacks



