標(biāo)題: stm32f407-LED燈 [打印本頁(yè)]

作者: Crazy·    時(shí)間: 2020-5-14 17:23
標(biāo)題: stm32f407-LED燈
菜鳥(niǎo)新學(xué)的32,望大神指點(diǎn),共進(jìn)步:

#include "bitband.h"

/**********
LED1-->PG9
LED2-->PE4
LED3-->PE3
低電平亮 AHB1
***********/

void led_init(void){
        GPIO_InitTypeDef GpioInitValue;
       
        RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE|RCC_AHB1Periph_GPIOG,ENABLE);
        //GPIO配置
        GpioInitValue.GPIO_Mode = GPIO_Mode_OUT;//輸出
        GpioInitValue.GPIO_OType = GPIO_OType_PP;//推挽
        GpioInitValue.GPIO_Pin = GPIO_Pin_3|GPIO_Pin_4;//引腳
        GpioInitValue.GPIO_PuPd =  GPIO_PuPd_UP;//上拉
        GpioInitValue.GPIO_Speed = GPIO_Speed_50MHz;//速率
        GPIO_Init(GPIOE,&GpioInitValue);
        GpioInitValue.GPIO_Pin = GPIO_Pin_9;
        GPIO_Init(GPIOG,&GpioInitValue);}


void led_switch(int num,int state){
        if(state!=0)
                state = 1;
        switch(num){
                case 0:
                        PGOut(9) = state;
                        break;
                case 1:
                        PGOut(4) = state;
                        break;
                case 2:
                        PGOut(3) = state;
                        break;
                default :break;
        }
}






歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1