中级会员
 
- 积分
- 253
- 金钱
- 253
- 注册时间
- 2015-4-29
- 在线时间
- 38 小时
|

楼主 |
发表于 2015-5-22 09:02:39
|
显示全部楼层
回复【2楼】hechao3225:
---------------------------------
麻烦大神帮我看看哪不对?
void timer_init()
{
RCC->AHB1ENR|=1<<5;
GPIO_Set(GPIOF,PIN9|PIN10,GPIO_MODE_OUT,GPIO_OTYPE_PP,GPIO_SPEED_100M,GPIO_PUPD_PU);
RCC->AHB1ENR|=1<<0;
GPIO_Set(GPIOA,PIN1,GPIO_MODE_AF,0,0,GPIO_PUPD_NONE);
GPIO_AF_Set(GPIOA,1,1);
// RCC->AHB1ENR&=~(1<<0);
led0=1;
led1=1;
void TIM2_IRQHandler(void)
{
if(TIM2->SR&0x0001)
{
led1=~led1;
}
TIM2->SR&=~(1<<0);
}
void TIM2_Int_Init(u32 arr,u32 psc)
{
RCC->APB1ENR|=1<<0;
TIM2->CCMR1&=~(1<<9);
TIM2->CCMR1|=1<<8;
TIM2->CCMR1&=0x0fff;
TIM2->CCER&=~(1<<5);
TIM2->CCER&=~(1<<7);
TIM2->SMCR|=1<<0;
TIM2->SMCR|=1<<1;
TIM2->SMCR|=1<<2;
TIM2->SMCR&=~(1<<4);
TIM2->SMCR|=1<<5;
TIM2->SMCR|=1<<6;
TIM2->ARR=arr;
TIM2-> SC=psc;
TIM2->DIER|=1<<0;
TIM2->DIER|=1<<6;
TIM2->CR1|=1<<0;
MY_NVIC_Init(1,2,TIM2_IRQn,2);
}
int main(void)
{
Stm32_Clock_Init(336,8,2,7);
delay_init(168);
timer_init();
uart_init(84,115200);
TIM2_Int_Init(5000000-1,0);
while(1)
{
printf("OK\r\n");
led0=!led0;
delay_ms(200);
}
} |
|