dsp28335数码管显示代码
时间: 2023-07-10 19:39:40 浏览: 48
以下是DSP28335驱动四位共阳数码管进行静态显示的代码,供参考:
```c
// 数码管段选码表
const unsigned char SEG_CODE[16] = {
0x3f, 0x06, 0x5b, 0x4f,
0x66, 0x6d, 0x7d, 0x07,
0x7f, 0x6f, 0x77, 0x7c,
0x39, 0x5e, 0x79, 0x71
};
// 数码管位选码表
const unsigned char BIT_CODE[4] = {
0x01, 0x02, 0x04, 0x08
};
// 数码管数据缓存
unsigned char DISP_BUF[4] = {0};
// 数码管扫描函数
void DispScan(void)
{
static unsigned char bit = 0;
unsigned char data = DISP_BUF[bit];
unsigned char seg = SEG_CODE[data & 0x0F];
unsigned char bit_ctrl = BIT_CODE[bit];
// 输出段选信号
GPIO_WritePin(SEG_A, (seg & 0x01));
GPIO_WritePin(SEG_B, (seg & 0x02) >> 1);
GPIO_WritePin(SEG_C, (seg & 0x04) >> 2);
GPIO_WritePin(SEG_D, (seg & 0x08) >> 3);
GPIO_WritePin(SEG_E, (seg & 0x10) >> 4);
GPIO_WritePin(SEG_F, (seg & 0x20) >> 5);
GPIO_WritePin(SEG_G, (seg & 0x40) >> 6);
GPIO_WritePin(SEG_DP, 0);
// 输出位选信号
GPIO_WritePin(BIT0, (bit_ctrl & 0x01));
GPIO_WritePin(BIT1, (bit_ctrl & 0x02) >> 1);
GPIO_WritePin(BIT2, (bit_ctrl & 0x04) >> 2);
GPIO_WritePin(BIT3, (bit_ctrl & 0x08) >> 3);
// 切换到下一个位
bit++;
if (bit >= 4) bit = 0;
}
// 定时器中断服务函数
interrupt void TimerISR(void)
{
// 清除中断标志位
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
// 数码管扫描
DispScan();
}
// 主函数
int main(void)
{
// 初始化GPIO端口
GPIO_Init();
// 初始化定时器
InitCpuTimers();
ConfigCpuTimer(&CpuTimer0, 150, 1000);
CpuTimer0Regs.TCR.bit.TSS = 0;
CpuTimer0Regs.TCR.bit.TRB = 1;
PieCtrlRegs.PIEIER1.bit.INTx7 = 1;
// 主循环
while (1) {
// 更新数码管显示数据
DISP_BUF[0] = 1;
DISP_BUF[1] = 2;
DISP_BUF[2] = 3;
DISP_BUF[3] = 4;
}
}
```
其中,`SEG_A ~ SEG_G`和`SEG_DP`分别对应数码管的7段LED和小数点控制端口,`BIT0 ~ BIT3`分别对应四位数码管的位选端口。`DispScan()`函数用于将要显示的数据转换为相应的段选和位选信号,并依次输出到数码管的控制端口上。`TimerISR()`函数是定时器中断服务函数,用于驱动数码管的刷新。在主函数中,可以通过更新`DISP_BUF`数组中的数据实现数码管的静态显示。