#include "sys.h"
#include "delay.h"
#include "led.h"
#include "timer.h"
int main()
{
STM32_Clock_Init(9);
delay_init(72);
tim3_init(4999,7199); //频率10K,计数5k,500ms
led_init();
while(1)
{
PC1=!PC1; //LED1翻转
delay_ms(500);
}
}
#include "timer.h"
#include "sys.h"
#include "led.h"
void tim3_init(u16 arr,u16 psc)
{
RCC->APB1ENR|=1<<1; //使能时钟
TIM3->PSC|=psc; //分频 频率10K
TIM3->ARR|=arr; //计数器自动转载值 计数5k次
TIM3->DIER|=1<<0; //允许跟新中断
MY_NVIC_Init(2,0,TIM3_IRQn,2);//中断分组配置
TIM3->CR1|=1<<0; //使能定时器
}
void TIM3_IRQHandler(void)
{
if(TIM3->SR&0X0001)//溢出中断
{
PC0=!PC0;//LED0翻转
}
TIM3->SR&=~(1<<0);
}
|