久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

專注電子技術學習與研究
當前位置:單片機教程網 >> STM32 >> 瀏覽文章

STM32 庫操作GPIO

作者:小強   來源:本站原創   點擊數:  更新時間:2014年04月09日   【字體:

添加安裝目錄下的庫   D:\Keil\ARM\RV31\LIB\STSTM32F10xR.LIB  (我安裝在D盤)
 
實驗效果: PA8 PD2 接的LED 閃爍 顯示。
 
小技巧:
 
 #define GPIO_LED                   GPIOF   //宏定義
 
  /* Enable GPIO_LED clock */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIO_LED, ENABLE);
  GPIO_Init(GPIO_LED, &GPIO_InitStructure);
 
    /* Turn on LD1 打開 */
    GPIO_SetBits(GPIO_LED, GPIO_Pin_6);
 
    /* Turn off LD1 關閉*/
    GPIO_ResetBits(GPIO_LED, GPIO_Pin_6);
 
這樣方便在更改IO時候,快速改動,不用每個GPIOF 端口改變。假如現在LED 接在PA口那么,直接改變宏定義就OK。
 
 
添加個C文件  輸入以下程序:
 
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x_lib.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
GPIO_InitTypeDef GPIO_InitStructure;  //聲明結構體
 
/**********************************************************************
聲明一個結構體,名字是GPIO_InitStructure,結構體原型由GPIO_InitTypeDef 確定,
stm32里面初始化GPIO用的吧。。設置完了GPIO_InitStructure里面的內容后
在GPIO_Init (GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_InitStruct)里面調用,
比如初始化pa口,就是
GPIO_Init (GPIOA, &GPIO_InitStructure),括號里后面那個就是你問題里面聲明的那個結構體
***************************************************************************/
ErrorStatus HSEStartUpStatus;
/* Private function prototypes -----------------------------------------------*/
void RCC_Configuration(void);
void NVIC_Configuration(void);
void Delay(vu32 nCount);
/* Private functions ---------------------------------------------------------*/

void LED_GPIO_init()
{
   //初始化 GPIOA 的時鐘  庫函數208頁
 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOD,ENABLE);
 //初始化GPIO 見庫函數 P125頁    LED 兩只接在 PA8  PD2
 GPIO_InitStructure.GPIO_Pin=GPIO_Pin_8;    //要設置的PIN
 GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP; //推挽輸出
 GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz; //輸出速度
 GPIO_Init(GPIOA,&GPIO_InitStructure); //初始化 IO
 GPIO_InitStructure.GPIO_Pin=GPIO_Pin_2;    //要設置的PIN
 GPIO_Init(GPIOD,&GPIO_InitStructure); //初始化 IO
 GPIO_SetBits(GPIOD,GPIO_Pin_2);   //初始化為高
 GPIO_SetBits(GPIOA,GPIO_Pin_8);   //初始化為高
 
}
/*******************************************************************************
* Function Name  : main
* Description    : Main program.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
int main(void)
{
#ifdef DEBUG
  debug();
#endif
  /* System Clocks Configuration **********************************************/
  RCC_Configuration(); 
  /* NVIC Configuration *******************************************************/
  NVIC_Configuration();
  /* Configure all unused GPIO port pins in Analog Input mode (floating input
     trigger OFF), this will reduce the power consumption and increase the device
     immunity against EMI/EMC *************************************************/
   LED_GPIO_init();  //初始化LED 函數
  while (1)
  {
    GPIO_ResetBits(GPIOD,GPIO_Pin_2);   //置低
 GPIO_ResetBits(GPIOA,GPIO_Pin_8);   //置低
 Delay(0xfffff);
 GPIO_SetBits(GPIOD,GPIO_Pin_2);   //置高
 GPIO_SetBits(GPIOA,GPIO_Pin_8);   //置高
 Delay(0xfffff);

  }
}
/*******************************************************************************
* Function Name  : RCC_Configuration
* Description    : Configures the different system clocks.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void RCC_Configuration(void)

  /* RCC system reset(for debug purpose) */
  RCC_DeInit();
  /* Enable HSE */
  RCC_HSEConfig(RCC_HSE_ON);
  /* Wait till HSE is ready */
  HSEStartUpStatus = RCC_WaitForHSEStartUp();
  if(HSEStartUpStatus == SUCCESS)
  {
    /* Enable Prefetch Buffer */
    FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
    /* Flash 2 wait state */
    FLASH_SetLatency(FLASH_Latency_2);
 
    /* HCLK = SYSCLK */
    RCC_HCLKConfig(RCC_SYSCLK_Div1);
 
    /* PCLK2 = HCLK */
    RCC_PCLK2Config(RCC_HCLK_Div1);
    /* PCLK1 = HCLK/2 */
    RCC_PCLK1Config(RCC_HCLK_Div2);
    /* PLLCLK = 8MHz * 9 = 72 MHz */
    RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
    /* Enable PLL */
    RCC_PLLCmd(ENABLE);
    /* Wait till PLL is ready */
    while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
    {
    }
    /* Select PLL as system clock source */
    RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
    /* Wait till PLL is used as system clock source */
    while(RCC_GetSYSCLKSource() != 0x08)
    {
    }
  }
}
/*******************************************************************************
* 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
}
/*******************************************************************************
* Function Name  : Delay
* Description    : Inserts a delay time.
* Input          : nCount: specifies the delay time length.
* Output         : None
* Return         : None
*******************************************************************************/
void Delay(vu32 nCount)
{
  for(; nCount != 0; nCount--);
}
#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
/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/

關閉窗口

相關文章

主站蜘蛛池模板: 国产精品视频在线播放 | 国产精品福利视频 | 国产 欧美 日韩 一区 | 五月天婷婷综合 | 国产精品久久亚洲7777 | 国产色婷婷| 日韩午夜影院 | 免费a网| 在线观看av网站永久 | 亚洲精品日韩在线 | 黄色成人免费在线观看 | www.操.com | 亚洲天天干 | 999免费观看视频 | 一本一道久久a久久精品综合 | 一本久久a久久精品亚洲 | 日本精品一区二区三区视频 | 久久久久精 | 日韩一区不卡 | 欧美一区二区在线观看 | 日韩成人专区 | 日韩欧美国产一区二区 | 日韩一区二区在线播放 | 精品久久视频 | 亚洲一区二区av在线 | 欧美中文 | 91 中文字幕 | 国产 日韩 欧美 在线 | 超碰男人天堂 | 91亚洲一区 | 欧美精品影院 | 国产精产国品一二三产区视频 | 久久久久久久久久久久一区二区 | 欧美精品一区二区三区蜜臀 | 午夜在线免费观看视频 | 国产成人一区二区三区精 | 人人干在线 | 日韩一区二区在线观看视频 | 天天爽夜夜爽精品视频婷婷 | 亚洲视频精品 | 亚洲国产精品一区二区三区 |