dsp28335呼吸灯代码
时间: 2023-07-03 15:19:54 浏览: 169
呼吸灯代码
以下是DSP28335呼吸灯的代码:
```
#include "DSP2833x_Device.h"
#include "DSP2833x_Examples.h"
#define PWM_PERIOD 37500
//PWM 周期为 150MHz/(2*PWM_PERIOD) = 1KHz
Uint16 duty = 0;
Uint16 step = 1;
interrupt void epwm1_isr(void)
{
EPwm1Regs.CMPA.half.CMPA = duty;
duty += step;
if(duty >= PWM_PERIOD || duty <= 0)
step = -step;
EPwm1Regs.ETCLR.bit.INT = 1;
PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
}
void Init_EPwm1(void)
{
EPwm1Regs.TBPRD = PWM_PERIOD - 1;
EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN;
EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE;
EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1;
EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1;
EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_CTR_ZERO;
EPwm1Regs.CMPA.half.CMPA = 0;
EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
EPwm1Regs.AQCTLA.bit.CAU = AQ_SET;
EPwm1Regs.AQCTLA.bit.CAD = AQ_CLEAR;
EPwm1Regs.ETSEL.bit.INTSEL = ET_CTR_ZERO;
EPwm1Regs.ETSEL.bit.INTEN = 1;
EPwm1Regs.ETPS.bit.INTPRD = ET_1ST;
}
void main(void)
{
InitSysCtrl();
InitPieCtrl();
IER = M_INT3;
Init_EPwm1();
EINT;
ERTM;
while(1);
}
```
这段代码使用了DSP28335的EPWM模块来实现呼吸灯的效果。在中断服务函数中,改变PWM的占空比,从而控制LED的亮度。在主函数中,初始化系统、中断控制器、EPWM模块,并开启中断。
阅读全文