void TIM3_PWM_Init(u16 arr,u16 psc)
{
//´Ë²¿·ÖÐèÊÖ¶¯ÐÞ¸ÄIO¿ÚÉèÖÃ
RCC->APB1ENR|=1<<1; //TIM3ʱÖÓʹÄÜ
RCC->APB2ENR|=1<<3; //ʹÄÜPORTBʱÖÓ
GPIOB->CRL&=0XFF0FFFFF; //PB5Êä³ö
GPIOB->CRL|=0X00B00000; //¸´Óù¦ÄÜÊä³ö
GPIOB->ODR |=1<<5; //PB5ÉÏÀ
GPIOB->CRL&=0XFFF0FFFF; //PB4Êä³ö
GPIOB->CRL|=0X000B0000; //¸´Óù¦ÄÜÊä³ö
GPIOB->ODR |=1<<4; //PB4ÉÏÀ
RCC->APB2ENR|=1<<0; //¿ªÆô¸¨ÖúʱÖÓ
AFIO->MAPR&=0XFFFFF3FF; //Çå³ýMAPRµÄ[11:10]
AFIO->MAPR|=1<<11; //²¿·ÖÖØÓ³Ïñ,TIM3_CH2->PB5
TIM3->ARR=arr; //É趨¼ÆÊýÆ÷×Ô¶¯ÖØ×°Öµ
TIM3->PSC=psc; //Ô¤·ÖƵÆ÷²»·ÖƵ
TIM3->CCR2=500;//CH2Õ¼¿Õ±È
TIM3->CCR1=500;//CH1Õ¼¿Õ±È
TIM3->CCMR1|=6<<12; //CH2 PWM2ģʽ
TIM3->CCMR1|=1<<11; //CH2ԤװÔØʹÄÜ
TIM3->CCMR1|=6<<4; //CH1 PWM2ģʽ
TIM3->CCMR1|=1<<3; //CH1ԤװÔØʹÄÜ
TIM3->CCER|=1<<4; //OC2 Êä³öʹÄÜ
TIM3->CCER|=1<<0; //OC1 Êä³öʹÄÜ
TIM3->CR1 =0x0080; //ARPEʹÄÜ
TIM3->CR1|=0x01; //ʹÄܶ¨Ê±Æ÷3
} |