专注电子技术学习与研究
当前位置:单片机教程网 >> STM32 >> 浏览文章

STM32库函数滴答定时器

作者:佚名   来源:本站原创   点击数:  更新时间:2014年08月17日   【字体:
程序:
#include "stm32f10x.h"
static __IO uint32_t TimingDelay;
void RCC_Configuration(void);
void Delay(__IO uint32_t nTime);
/****************************************************************************
* 名    称:void LED_Config(void)
* 功    能:LED 控制初始化函数
* 入口参数:无
* 出口参数:无
* 说    明:
* 调用方法:无 
****************************************************************************/ 
void LED_Config(void){
  GPIO_InitTypeDef GPIO_InitStructure;  
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;     //LED1  V6  配置为通用推挽输出  
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //口线翻转速度为50MHz
  GPIO_Init(GPIOB, &GPIO_InitStructure);
  
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;      //LCD背光控制
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_Init(GPIOD, &GPIO_InitStructure);
  GPIO_ResetBits(GPIOD, GPIO_Pin_13);                  //LCD背光关闭
}
/****************************************************************************
* 名    称:int main(void)
* 功    能:主函数
* 入口参数:无
* 出口参数:无
* 说    明:
* 调用方法:无 
****************************************************************************/ 
int main(void)
{
   RCC_Configuration();           //系统时钟设置及各外设时钟使能
   LED_Config();                   //LED控制初始化  
   if (SysTick_Config(72000))    //时钟节拍中断时1ms一次  用于定时 core_cm3.h
   { 
    /* Capture error */ 
     while (1);
   }
   while (1)
   {
      GPIO_SetBits(GPIOB, GPIO_Pin_5); //LED1 亮 
      Delay(500); //延时500ms
      GPIO_ResetBits(GPIOB, GPIO_Pin_5); //LED1 灭 
      Delay(500); //延时500ms
   }
}
 
/****************************************************************************
* 名    称:void RCC_Configuration(void)
* 功    能:系统时钟配置为72MHZ, 外设时钟配置
* 入口参数:无
* 出口参数:无
* 说    明:
* 调用方法:无 
****************************************************************************/ 
void RCC_Configuration(void){
 
  SystemInit();   
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC 
  | RCC_APB2Periph_GPIOD| RCC_APB2Periph_GPIOE , ENABLE);
}
/****************************************************************************
* 名    称:void Delay(__IO uint32_t nTime)
* 功    能:定时延时程序 1ms为单位
* 入口参数:无
* 出口参数:无
* 说    明:
* 调用方法:无 
****************************************************************************/  
void Delay(__IO uint32_t nTime)
  TimingDelay = nTime;
 
  while(TimingDelay != 0);
}
/****************************************************************************
* 名    称:void TimingDelay_Decrement(void)
* 功    能:获取节拍程序
* 入口参数:无
* 出口参数:无
* 说    明:
* 调用方法:无 
****************************************************************************/  
void TimingDelay_Decrement(void)
{
  if (TimingDelay != 0x00)
  { 
    TimingDelay--;
  }
}
关闭窗口