void main(void)
{
Set_All_GPIO_Quasi_Mode;//所有IO设置为双向模式
EA=1;//开启总中断
set_EPWM;//使能pwm中断
PWM_INT_PWM4;//设定中断源为PWM4
PWM_FALLING_INT;//下降沿触发
PWM5_P03_OUTPUT_ENABLE;//使能PWM5,通过P03引脚输出
PWM4_P01_OUTPUT_ENABLE;
clr_PWMTYP;//边沿对齐模式
clr_PWMMOD0;//设置为独立输出模式
clr_PWMMOD1;
PWM_CLOCK_DIV_8;//8分频模式
PWMPH = 0x07;//1999(Dec)
PWMPL = 0xCF;
/**********************************************************************
PWM frequency = Fpwm/((PWMPH,PWMPL) + 1) <Fpwm = Fsys/PWM_CLOCK_DIV>
= (16MHz/8)/(0x7CF + 1)
= 1KHz (1ms)
PWMDT=(PDTCNT+1)/Fpwm =10/2Mhz=0.005ms
***********************************************************************/
set_SFRPAGE;//PWM4 and PWM5 duty seting is in SFP page 1
PWM4H = 0x01;//500(Dec)
PWM4L = 0xf4;
PWM5H = 0x01;//500(Dec)
PWM5L = 0xf4;
clr_SFRPAGE;
set_LOAD;//载入周期和占空比
set_PWMRUN;//开始输出PWM
while(1)
{
//构建你的代码
}
}
void PWMISR() interrupt 13
{
if(PWMF)//检测到中断标志位
{
clr_LOAD;//关闭载入之前的值
clr_PWMF;//清楚PWM中断标志位 Timer0_Delay1ms(1)
set_SFRPAGE;//PWM4 and PWM5 duty seting is in SFP page 1
PWM5L-=30;
clr_SFRPAGE;
set_LOAD;//设定完成,开始载入
}
}
|