打印

Systick做延时,LED不闪烁,高手来解

[复制链接]
2317|8
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
hw5226349|  楼主 | 2011-8-13 17:19 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
Systick做延时,LED不闪烁,高手来解
#include<stm32f10x_lib.h>
void RCC_Configuration(void);
void NVIC_Configuration(void);
void Delay(vu32 nTime);
GPIO_InitTypeDef GPIO_InitStructure;
static vu32 TimingDelay;
ErrorStatus HSEStartUpStatus;
int main(void)
{
   #ifdef DEBUG
   debug();
   #endif
   RCC_Configuration();
  
   GPIO_InitStructure.GPIO_Pin=GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10; //将PF6~9设置为50M推挽输出
   GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
   GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
   GPIO_Init(GPIOF,&GPIO_InitStructure);
   GPIO_Write(GPIOF,GPIO_Pin_6|GPIO_Pin_8);  //置1:D1.D2,其他为零
     NVIC_Configuration();
   SysTick_SetReload(9000);  //定时1ms
   SysTick_ITConfig(ENABLE);
   while(1)
   {
      GPIO_Write(GPIOF,(u16)~GPIO_ReadOutputData(GPIOF));
      GPIO_ResetBits(GPIOF,GPIO_Pin_10);   //D1D3与D2D4闪烁,D5点亮
   Delay(1000);//延时500MS
   GPIO_Write(GPIOF,(u16)~GPIO_ReadOutputData(GPIOF));
      GPIO_SetBits(GPIOF,GPIO_Pin_10);   //D1D3与D2D4闪烁,D5熄灭
      Delay(1000);
   }
}
/*SysTick做延时*/
void Delay(u32 nTime)
{
   SysTick_CounterCmd(SysTick_Counter_Enable); //使能Systick计数器
   TimingDelay=nTime;
   while(TimingDelay!=0);
   SysTick_CounterCmd(SysTick_Counter_Disable);  //禁用计数器
   SysTick_CounterCmd(SysTick_Counter_Clear);    //清空计数器
}
void RCC_Configuration(void)
{
   RCC_DeInit();
   RCC_HSEConfig(RCC_HSE_ON);   //启动HSE
   HSEStartUpStatus=RCC_WaitForHSEStartUp(); //等待HSE启动
   if(HSEStartUpStatus==SUCCESS)
   {
         /* Enable Prefetch Buffer */
      FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
         /* Flash 2 wait state */
      FLASH_SetLatency(FLASH_Latency_2);
   RCC_HCLKConfig(RCC_SYSCLK_Div1);  //HCLK=系统时钟
   RCC_PCLK2Config(RCC_HCLK_Div1);   //APB2=HCLK
   RCC_PCLK1Config(RCC_HCLK_Div2); //APB1=HCLK/2
   RCC_PLLConfig(RCC_PLLSource_HSE_Div1,RCC_PLLMul_9);   //设置72M为系统时钟
   RCC_PLLCmd(ENABLE);  //使能PLL
   while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY)==RESET){}  //等待PLL准备就绪
   RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);   //将PLL作为SYSCLK
   while(RCC_GetSYSCLKSource()!=0x08){}    //等待PLL成为SYSCLK
   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF, ENABLE); //使能PF时钟
   }
}
/*******************************************************************************
* Function Name  : NVIC_Configuration
* Description    : Configures Vector Table base location.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void NVIC_Configuration(void)
{
   #ifdef  VECT_TAB_RAM  
      /* 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
}
/*可变的时间延时衰减率*/
void TimingDelay_Decrement(void)
{
  if(TimingDelay!=0x00)
  {
     TimingDelay--;
  }
}
  #ifdef  DEBUG
/*******************************************************************************
* Function Name  : assert_failed
* Description    : Reports the name of the source file and the source line number
*                  where the assert_param error has occurred.
* Input          : - file: pointer to the source file name
*                  - line: assert_param error line source number
* Output         : None
* Return         : None
*******************************************************************************/
void assert_failed(u8* file, u32 line)
{
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  /* Infinite loop */
  while (1)
  {
  }
}
#endif

建立工程时+ stm32f10x_lib.c
  + stm32f10x_gpio.c
  + stm32f10x_rcc.c
  + stm32f10x_nvic.c
  + stm32f10x_flash.c
  + stm32f10x_systick.c   
这些文件
沙发
hw5226349|  楼主 | 2011-8-13 17:42 | 只看该作者
不知道怎么一发,就结贴了,问题还没解决。。

使用特权

评论回复
板凳
靠双手奋斗| | 2011-8-14 16:11 | 只看该作者
你用的好像还是2.0的库!!!

使用特权

评论回复
地板
snic_k| | 2011-8-14 18:00 | 只看该作者
GPIO的时钟没有开启。

使用特权

评论回复
5
Chaos_zc| | 2011-8-14 20:47 | 只看该作者
楼上正解。悬赏分为0,所以发帖后系统自动结帖了。

使用特权

评论回复
6
hw5226349|  楼主 | 2011-8-15 16:58 | 只看该作者
哦,这样啊。 初来咋到,不懂。

使用特权

评论回复
7
hw5226349|  楼主 | 2011-8-15 17:00 | 只看该作者
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF, ENABLE); //使能PF时钟
我的好像使能了时钟的啊

使用特权

评论回复
8
hw5226349|  楼主 | 2011-8-15 17:01 | 只看该作者
我的好像使能了时钟的啊RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF, ENABLE); //使能PF时钟

使用特权

评论回复
9
aixuezheli| | 2013-3-23 15:30 | 只看该作者
程序没有问题,你的stm32启动文件加没有比如:cortex3_macro.s stm32f10x_vector.s  要不就是你的库函数有问题要不就是硬件问题了

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

8

主题

106

帖子

1

粉丝