你好,在上面你说的中断函数名是PWMInterrupt,但是本人找对应的gld文件搜索连PWM这个字眼都没有。
还有一个就是查找手册中断这一章时,本人只看到PWM错误事件和故障事件。
在代码中定义PWMInterrupt也没报错,但是也没有进入PWMInterrupt函数。下面是在下写的代码。
void pwm1_init()//RE0,RE1
{
PTPER=3125-1;//控制周期,越大频率也越小,14位寄存器,最大取值=2^14=16384
PTCONbits.PTEN = 1; //PWM time base is on
PTCONbits.PTMOD = 0b01; // operates in a Free-Running mode
PTCONbits.PTCKPS = 0b11; // PWM time base input clock period is TCY (1:64 prescale)
PWMCON1bits.PMOD1 = 1; //PWM I/O pin pair is in the Independent PWM Output mod
PWMCON1bits.PEN1H = 1; //PWMxH pin is enabled for PWM output
PWMCON1bits.PEN1L = 1; //PWMxL pin is enabled for PWM output
PWMCON2bits.SEVOPS = 0; //PWM Special Event Trigger Output Postscale
PWMCON2bits.IUE = 1; // Updates to the active PDC registers are immediate
PDC1 = PTPER; //控制占空比,范围是(0~2)*PTPER
}
void pwmINT_init()
{
IPC14bits.PWMIP = 0b001;
IEC3bits.PWMIE = 0b1;
IFS3bits.PWMIF = 0b0;
}
void __attribute__((interrupt, no_auto_psv)) _PWMInterrupt()
{
if(IFS3bits.PWMIF == 1)
{
PTCONbits.PTEN = 1;
IFS3bits.PWMIF = 0;
}
}
int main()
{
pwmINT_init();
pwm1_init();
while(1);
}
|