【STM】IO口配置庫函數、寄存器、位操作方式

來源:互聯網
上載者:User

標籤:

庫函數函數:

一個初始化函數:初始化一個或者多個IO口(同一組)的工作模式、輸出類型、速度以及上下拉方式

1 void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct);2 typedef struct3 {4   uint32_t GPIO_Pin//指定要初始化的連接埠5   GPIOMode_TypeDef GPIO_Mode;//連接埠模式6   GPIOSpeed_TypeDef GPIO_Speed;//速度7   GPIOOType_TypeDef GPIO_OType; //輸出類型8   GPIOPuPd_TypeDef GPIO_PuPd;//上拉或者下拉9 }GPIO_InitTypeDef;
 0   GPIO_Init函數初始化範例:   
1  GPIO_InitTypeDef GPIO_InitStructure;
2 3 RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE);//使能GPIOF時鐘 4 5 //GPIOF9,F10初始化設定 6 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10;//LED0和LED1對應IO口 7 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;//普通輸出模式 8 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推挽輸出 9 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100MHz10 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉11 GPIO_Init(GPIOF, &GPIO_InitStructure);//初始化GPIOF9,F10

 兩個讀取輸入電平函數:

  uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);讀取某個GPIO的輸入電平
  uint16_t GPIO_ReadInputData(GPIO_TypeDef* GPIOx);讀取某組GPIO的輸入電平

兩個讀取輸出電平函數:

  uint8_t GPIO_ReadOutputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);讀取某個GPIO的輸出電平
  uint16_t GPIO_ReadOutputData(GPIO_TypeDef* GPIOx);讀取某組GPIO的輸出電平

四個設定輸出電平函數:

  void GPIO_SetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);設定某個IO口輸出高電平
  void GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);設定某個IO口輸出低電平

  下邊兩個不常用
  void GPIO_WriteBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, BitAction BitVal);
  void GPIO_Write(GPIO_TypeDef* GPIOx, uint16_t PortVal);

 

庫函數步驟:

使能IO口時鐘,調用函數RCC_AHB1PeriphClockCmd();
  不同的外設調用的時鐘使能函數可能不一樣
初始化IO口模式,調用函數GPIO_Init();
操作IO口,輸出高低電平。
     GPIO_SetBits();
     GPIO_ResetBits();

【STM】IO口配置庫函數、寄存器、位操作方式

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.