#include "delay.h"
#include "sys.h"
#include "uart.h"
#include "pwm.h"
#include "LED.h"
//
void tiM2_PWM_Init(u16 arr,u16 psc)
{
RCC->APB1ENR|=RCC_APB1ENR_TIM2EN;
RCC->AHBENR|=0x7<<17;
GPIOA->AFRL&=0x0000;
GPIOA->AFRL=0x2222;
GPIOA->CRL&=0XFFFF0000;
GPIOA->CRL|=GPIO_CRL_MODE3|GPIO_CRL_CNF3_1;
GPIOA->CRL|=GPIO_CRL_MODE2|GPIO_CRL_CNF2_1;
GPIOA->CRL|=GPIO_CRL_MODE1|GPIO_CRL_CNF1_1;
GPIOA->CRL|=GPIO_CRL_MODE0|GPIO_CRL_CNF0_1;
TIM2->ARR=arr;
TIM2->PSC=psc;
TIM2->CCMR1=0X7878;
TIM2->CCMR2=0X7878;
TIM2->CCER|=TIM_CCER_CC1E|TIM_CCER_CC2E|TIM_CCER_CC3E|TIM_CCER_CC4E;
TIM2->CR1=TIM_CR1_ARPE;
TIM2->CR1|=TIM_CR1_CEN;
}
int main(void)
{
u8 dir=1;
u16led0pwmval=0;
delay_init();
//uart_initwBaudRate(115200);
//LED_Init();
RCC->CR|=0x00000003;
RCC->CFGR&=0xFFFFFFF0;
TIM2_PWM_Init(99,0);
TIM2->CCR1=10;
TIM2->CCR2=30;
TIM2->CCR3=60;
TIM2->CCR4=90;
while(1)
{
delay_ms(5);
TIM2->CCR1++;
IF( TIM2->CCR1>=TIM2->ARR)
{TIM2->CCR1=0x01;}
TIM2->CCR2++;
if( TIM2->CCR2>=TIM2->ARR)
{TIM2->CCR2=0x01;}
TIM2->CCR3++;
if( TIM2->CCR3>=TIM2->ARR)
{TIM2->CCR3=0x01;}
TIM2->CCR4++;
if( TIM2->CCR4>=TIM2->ARR)
{TIM2->CCR4=0x01;}
}
}