#include "stm32f10x.h"
#define digitalToggle(p,i) {p->ODR ^= i;}
#define led_Toggle digitalToggle(GPIOC,GPIO_Pin_13)
uint32_t time = 0;
void LED_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_13;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_SetBits(GPIOC,GPIO_Pin_13 );
}
void NVIC_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); //?D??×é?a0
NVIC_InitStructure.NVIC_IRQChannel=TIM2_IRQn; //?D???'
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0; //?à??ó??è??
NVIC_InitStructure.NVIC_IRQChannelSubPriority=3; //?ìó|ó??è??
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE; //ê1?ü?D??
NVIC_Init(&NVIC_InitStructure); //3?ê??ˉ?D??
}
void Timer_Config(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); //?¨ê±?÷ê±?ó
TIM_TimeBaseStructure.TIM_Period=999;//??×°???ü?ú
TIM_TimeBaseStructure.TIM_Prescaler=71; //ó?·??μ±è
TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1; //ê±?ó·??μòò×ó
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up; //?òé???êy?÷??ê?
TIM_TimeBaseStructure.TIM_RepetitionCounter=0;
TIM_TimeBaseInit(TIM2,&TIM_TimeBaseStructure); //3?ê??ˉ?¨ê±?÷
TIM_ClearFlag(TIM2,TIM_FLAG_Update); //??3t?D??±ê??
TIM_ITConfig(TIM2,TIM_IT_Update,ENABLE); //?a???D??
TIM_Cmd(TIM2,ENABLE); //ê1?ü?¨ê±?÷
}
int main(void)
{
LED_Config();
NVIC_Config();
Timer_Config();
while(1)
{
if(time==1000)
{
time = 0;
led_Toggle;
}
}
} |