Can anyone help me to build Stopwatch with Start/stop, reset, pause/resume functionalities?
I have .xsa bitstream from Vivado and want to implement it on 7-segment display of Xilinx NEXYS A7 board using C-Code (Xilinx Vitis ISE).
I'm not good with C and have to consider C in this case. The following is the code but not really working.
#include "xparameters.h" #include "xgpio.h" #include "xtmrctr.h" #include <unistd.h> #include "xstatus.h"
#define LED_AN_ADDR 0x40000000 //base address for digit select signals #define LED_DIS_ADDR 0x40010000 //base address for 7-segment displays #define SW_ADDR 0x40020000 //base address for 16 switches #define TMRCTR_DEVICE_ID XPAR_TMRCTR_0_DEVICE_ID //device ID for the on-board timer
#define TIMER_FREQ 100000000 // Timer frequency in Hz #define DISPLAY_PERIOD 100000000/10 // Period for updating the display in clock cycles
XGpio Gpio_LedAn; XGpio Gpio_LedDis; XGpio Gpio_Sw; XTmrCtr Timer;
unsigned int hours = 0; // Time in hours unsigned int minutes = 0; // Time in minutes unsigned int seconds = 0; // Time in seconds int state = 0; // 0 = stopped, 1 = running void delay(unsigned int delay_count) { unsigned int i; for (i = 0; i < delay_count; i++); }
unsigned int get7segData(int num) { static const unsigned int segData[] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F}; if(num >= 0 && num <= 999999) { unsigned int result = 0; int i; for (i = 0; i < 6; i++) { result |= segData[num % 10] << (i * 8); num /= 10; } return result; } else { return 0; } }
void update_display() { // turn off all digit select signals XGpio_DiscreteWrite(&Gpio_LedAn, 1, 0x00000000);
1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
}
void timer_interrupt(void *CallbackRef, u8 TmrCtrNumber) { // call the function to display the time on the 7-segment displays update_display(); // increment the time seconds++; if (seconds == 60) { seconds = 0; minutes++; } if (minutes == 60) { minutes = 0; hours++; } if (hours == 100) { hours = 0; } // reset the timer counter value XTmrCtr_Reset(CallbackRef, TmrCtrNumber); // call the function to display the time on the 7-segment displays //Read switches int switches = XGpio_DiscreteRead(&Gpio_Sw, 1);
1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
}
int main() { int status;
1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|