zoukankan      html  css  js  c++  java
  • 标准库GPIO初始化并使用

    由于中文乱码原因就插入一张截图作为参考

    #include "stm32f10x_it.h" #include "stm32f10x_gpio.h" #include "stm32f10x.h" #include "Led.h" #define GPIO_PB5_On GPIO_ResetBits(GPIOB,GPIO_Pin_5);//ÉèÖÃPB5ΪµÍµçƽ #define GPIO_PB5_Off GPIO_SetBits(GPIOB,GPIO_Pin_5);//ÉèÖÃPB5Ϊ¸ßµçƽ void gpio_init(); void delay(int i); void Led_All_Off(){ GPIO_SetBits(GPIOB,GPIO_Pin_5);//ÉèÖÃPB5Ϊ¸ßµçƽ GPIO_SetBits(GPIOB,GPIO_Pin_0);//ÉèÖÃPB5Ϊ¸ßµçƽ GPIO_SetBits(GPIOB,GPIO_Pin_1);//ÉèÖÃPB5Ϊ¸ßµçƽ } void Led_All_On(){ GPIO_ResetBits(GPIOB,GPIO_Pin_5);//ÉèÖÃPB5Ϊ¸ßµçƽ GPIO_ResetBits(GPIOB,GPIO_Pin_0);//ÉèÖÃPB5Ϊ¸ßµçƽ GPIO_ResetBits(GPIOB,GPIO_Pin_1);//ÉèÖÃPB5Ϊ¸ßµçƽ } void Led_Red_On(){ Led_All_Off(); GPIO_PB5_On; } //ºìµÆÏ¨Ãð void Led_Red_Off(){ Led_All_Off(); GPIO_PB5_Off; } //ºìµÆÉÁËõ void Triggle_Red(){ Led_All_Off(); while(1){ GPIO_PB5_On; delay(10000000); GPIO_PB5_Off; delay(10000000); } } void gpio_init(){ //ÅäÖÃʱÖÓ 72/36 MHz RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE); GPIO_InitTypeDef gpio_structer;//¶¨Òå½á¹¹Ìå gpio_structer.GPIO_Speed = GPIO_Speed_50MHz;//ÉèÖÃÒý½ÅµÃË¢ÐÂËÙ¶È gpio_structer.GPIO_Mode = GPIO_Mode_Out_PP; //ÍÆÍìÊä³ö gpio_structer.GPIO_Pin = GPIO_Pin_5; GPIO_Init(GPIOB,&gpio_structer);//³õʼ»¯GPIOB gpio_structer.GPIO_Mode = GPIO_Mode_Out_PP; //ÍÆÍìÊä³ö gpio_structer.GPIO_Pin = GPIO_Pin_0; GPIO_Init(GPIOB,&gpio_structer);//³õʼ»¯GPIOB gpio_structer.GPIO_Mode = GPIO_Mode_Out_PP; //ÍÆÍìÊä³ö gpio_structer.GPIO_Pin = GPIO_Pin_1; GPIO_Init(GPIOB,&gpio_structer);//³õʼ»¯GPIOB gpio_structer.GPIO_Pin = GPIO_Pin_0; gpio_structer.GPIO_Mode = GPIO_Mode_IN_FLOATING;//¸¡¿ÕÊäÈë GPIO_Init(GPIOA,&gpio_structer);//³õʼ»¯GPIOB } void delay(int i){//ÑÓʱº¯Êý while(i--); }

     主函数入口

    #include "stm32f10x_it.h"
    #include "stm32f10x_gpio.h"
    #include "stm32f10x.h"
    #include "Led.h"
    #include "Button.h"
    #include "Uart.h"
    int main(){
        gpio_init();
        Triggle_Red();//此处是闪烁函数
    
        while(1);
        return 0;
    }

    现象

     

    哪里有误请指正谢谢

    归去来兮
  • 相关阅读:
    POJ 3126 Prime Path
    POJ 2429 GCD & LCM Inverse
    POJ 2395 Out of Hay
    【Codeforces 105D】 Bag of mice
    【POJ 3071】 Football
    【POJ 2096】 Collecting Bugs
    【CQOI 2009】 余数之和
    【Codeforces 258E】 Devu and Flowers
    【SDOI 2010】 古代猪文
    【BZOJ 2982】 combination
  • 原文地址:https://www.cnblogs.com/zoute/p/9314413.html
Copyright © 2011-2022 走看看