野火STM32学习(6)

编写置位/复位函数

#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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值