编写置位/复位函数
#ifndef __STM32F4XX_GPIO_H
#define __STM32F4XX_GPIO_H
#include "stm32f4xx.h"
#define GPIO_Pin_0 (1<<0)
#define GPIO_Pin_1 (1<<1)
#define GPIO_Pin_2 (1<<2)
#define GPIO_Pin_3 (1<<3)
#define GPIO_Pin_4 (1<<4)
#define GPIO_Pin_5 (1<<5)
#define GPIO_Pin_6 (1<<6)
#define GPIO_Pin_7 (1<<7)
#define GPIO_Pin_8 (1<<8)
#define GPIO_Pin_9 (1<<9)
#define GPIO_Pin_10 (1<<10)
#define GPIO_Pin_11 (1<<11)
#define GPIO_Pin_12 (1<<12)
#define GPIO_Pin_13 (1<<13)
#define GPIO_Pin_14 (1<<14)
#define GPIO_Pin_15 (1<<15)
void GPIO_SetBits( GPIO_TypeDef * GPIOx , uint16_t GPIO_Pin );
void GPIO_ResetBits( GPIO_TypeDef * GPIOx , uint16_t GPIO_Pin );
#endif /* __STM32F4XX_GPIO_H */
#include "stm32f4xx_gpio.h"
void GPIO_SetBits( GPIO_TypeDef * GPIOx , uint16_t GPIO_Pin ){
GPIOx->BSRRL = GPIO_Pin;
}
void GPIO_ResetBits( GPIO_TypeDef * GPIOx , uint16_t GPIO_Pin ){
GPIOx->BSRRH = GPIO_Pin;
}
#include "stm32f4xx.h"
#include "stm32f4xx_gpio.h"
int main(void){
/* 打开GPIOE的时钟 */
RCC_AHB1ENR |= (1<<4); //写入1
/* GPIOE配置为输出 */
GPIOE->MODER &= ~(0X03<<(2*3)); //清0
GPIOE->MODER |= (0X01<<(2*3)); //写入1
/* PE3输出低电平 */
GPIO_ResetBits(GPIOE, GPIO_Pin_3);
}
void SystemInit(void){
}
置位/复位函数实际上与操作ODR寄存器相似,置位写1,复位写0