用DSP28335写一个秒表的程序
时间: 2023-09-11 14:12:07 浏览: 68
下面是一个使用DSP28335的秒表程序示例:
```c
#include "DSP2833x_Device.h"
#include "DSP2833x_Examples.h"
// 定义计时器变量
Uint32 timerCount = 0;
// 定时器中断处理函数
interrupt void timerISR(void)
{
timerCount++; // 计数器加1
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; // 清除中断标志
}
void main(void)
{
// 禁用全局中断
DINT;
// 初始化系统时钟
InitSysCtrl();
// 初始化GPIO
InitGpio();
// 初始化定时器
InitCpuTimers();
ConfigCpuTimer(&CpuTimer0, 150, 1000000); // 定时1秒
CpuTimer0Regs.TCR.all = 0x4001;
// 配置中断
EALLOW;
PieVectTable.TINT0 = &timerISR;
PieCtrlRegs.PIEIER1.bit.INTx7 = 1;
IER |= M_INT1;
EINT;
EDIS;
// 启用全局中断
EINT;
while(1)
{
// 显示计时器值
Uint32 seconds = timerCount % 60;
Uint32 minutes = timerCount / 60;
printf("%02d:%02d\n", minutes, seconds);
}
}
```
该程序使用CpuTimer0来实现1秒的定时,并在中断处理函数中将计数器加1。在主循环中,程序将计数器的值转换为分和秒,并输出到终端。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![-](https://csdnimg.cn/download_wenku/file_type_lunwen.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)