#include "stm32f10x.h"
#include "hardware.h"
#include "stm32f10x_tim.h"
#include "misc.h"
ITStatus EXTIStatus;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
u16 a=0xffff;
void GPIO_config(void);
void Timer_config(void);
void NVIC_config(void);
void delay(u32 count)
{
for(;count!=0;count--);
}
static unsigned int state=0;
int main()
{
SystemInit();
GPIO_config();
Timer_config();
NVIC_config();
GPIO_Write(GPIOA,a);
while(1)
{};
}
void GPIO_config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_AFIO,ENABLE);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_Init(GPIOA,&GPIO_InitStructure);
}
void Timer_config(void)
{
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE);
TIM_DeInit(TIM2);
TIM_TimeBaseStructure.TIM_Period=2000;
TIM_TimeBaseStructure.TIM_Prescaler=35999;
TIM_TimeBaseStructure.TIM_ClockDivision=0;
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2 ,&TIM_TimeBaseStructure);
TIM_ClearFlag(TIM2,TIM_FLAG_Update);
TIM_ITConfig(TIM2,TIM_IT_Update,ENABLE);
TIM_Cmd(TIM2,ENABLE);
}
void NVIC_config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
#ifdef VECT_TAB_RAM //如果程序在ram中调试那么定义中断向量表在Ram中否则在Flash中
/* Set the Vector Table base location at 0x20000000 */
NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
#else /* VECT_TAB_FLASH */
/* Set the Vector Table base location at 0x08000000 */
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
#endif
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority=0;
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
#ifdef USE_FULL-ASSERT
void assert_failed(uint8_t* file,uint32_t line)
{
while(1)
{}
}
#endif
**************************************************************
void TIM2_IRQHandler(void)
{
if ( TIM_GetITStatus(TIM2 , TIM_IT_Update) != RESET ) {
TIM_ClearITPendingBit(TIM2 , TIM_FLAG_Update);
GPIO_Write(GPIOA,num);
num=num>>1;
if (num==0xff)
{num=0xff7f;}
}
}
评论0