//初始化的方式:先定义初始化机构体、再打开时钟使能、在对每一组GPIO口进行初始化。
GPIO_InitTypeDef LED_GPIO; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB |RCC_APB2Periph_GPIOD, ENABLE); //ê1?üPB,PD???úê±?ó LED_GPIO.GPIO_Pin = GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6; //???¨òy?? PD3,4,5,6 LED_GPIO.GPIO_Mode = GPIO_Mode_Out_PP; //í?íìê?3? LED_GPIO.GPIO_Speed = GPIO_Speed_50MHz; //IO?ú?ù?è?a50MHz GPIO_Init(GPIOD, &LED_GPIO); //?ù?Yéè?¨2?êy3?ê??ˉ //---------- PB8 ---------------------------- LED_GPIO.GPIO_Pin = GPIO_Pin_8; //???¨òy?? PB8 LED_GPIO.GPIO_Mode = GPIO_Mode_Out_PP; //í?íìê?3? LED_GPIO.GPIO_Speed = GPIO_Speed_50MHz; //IO?ú?ù?è?a50MHz GPIO_Init(GPIOB, &LED_GPIO); //?ù?Yéè?¨2?êy3?ê??ˉ
GPIO_SetBits(GPIOD, GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6);
GPIO_SetBits(GPIOB,GPIO_Pin_8);
或者用宏定义
#define LED_light(x) ( GPIOD_BSRR |= 0x0001<<x ) #define LED_Close(x) ( GPIOD_BRR |= 0x0001<<x ) #define LED_ALL_light ( GPIO_ODR |= 0x0078 ) #define LED_ALL_close ( GPIO_ODR &= 0xff87 )
原文:https://www.cnblogs.com/dadidelearning/p/10018257.html