打印

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

[复制链接]
1784|5
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
hw5226349|  楼主 | 2011-8-13 16:53 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#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   
这些文件
沙发
jiaxinhui| | 2011-8-15 17:42 | 只看该作者
可以参看下我这个帖子里的程序:https://bbs.21ic.com/viewthread.php?tid=241607&extra=&page=2

使用特权

评论回复
板凳
sjnh| | 2011-8-16 07:43 | 只看该作者
没有配置中断,TimingDelay_Decrement从来没有执行,怎么实现掩饰
程序一直在while(TimingDelay!=0);处执行

使用特权

评论回复
地板
lxj19901115| | 2011-8-18 21:09 | 只看该作者
貌似问题出现在那个全局变量上面,TimingDelay当然,三楼的说法也是对的,没有设置中断

使用特权

评论回复
5
abin0415| | 2012-3-31 17:52 | 只看该作者
LZ的群满了,加上不。:(请问lz用的哪个版本的库

使用特权

评论回复
6
abin0415| | 2012-3-31 17:57 | 只看该作者
不好意思,发错地方了

使用特权

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

本版积分规则

8

主题

106

帖子

1

粉丝