void TIM1_Init(void)
{
TIM1_IER=0X00;
TIM1_EGR=0X00;
TIM1_PSCRH=0X3E;//15999分频,记数周期为1ms
TIM1_PSCRL=0X7F;
TIM1_ARRH=0X01;//自动重载寄存器为500,每计数500次产生一次中断
TIM1_ARRL=0XF4;
TIM1_CNTRH=0X00;
TIM1_CNTRL=0X00;
TIM1_CR1=0X81;
TIM1_IER=0X01;
}
#pragma vector=TIM1_OVR_UIF_vector
__interrupt void TIM1_OVR_UIF(void)
{
i++;
TIM1_SR1=0X00;
if(i==10)
{PWMOFF();}
}
编译环境为IAR,目的是10s后pwm输出关闭,硬件测试进不去中断 |