1:仅通过指针进行封装 :编译可能出错,这个地方只是表示思路
//在基地址基础上加上偏移地址
#define GPIOF_BASE (0x40021400)
#define GPIOF_BASE (0x40021400)
#define GPIOF_BASE (0x40021400)
#define GPIOF_BASE (0x40021400)
#define GPIOF_BASE (0x40021400)
#define GPIOF_BASE (0x40021400)
#define GPIOF_MODER *(unsigned int *)(GPIOF_BASE+0x40021400)
#define GPIOF_OTYPER *(unsigned int *)(GPIOF_BASE+0x40021400)
#define GPIOF_OSPEEDR *(unsigned int *)(GPIOF_BASE+0x40021400)
#define GPIOF_PUPDR *(unsigned int *)(GPIOF_BASE+0x40021400)
#define GPIOF_IDR *(unsigned int *)(GPIOF_BASE+0x40021400)
#define GPIOF_ODR *(unsigned int *)(GPIOF_BASE+0x40021400)
#define GPIOF_BSRR *(unsigned int *)(GPIOF_BASE+0x40021400)
#define GPIOF_LCKR *(unsigned int *)(GPIOF_BASE+0x40021400)
#define GPIOF_AFRL *(unsigned int *)(GPIOF_BASE+0x40021400)
#define GPIOF_AFRH *(unsigned int *)(GPIOF_BASE+0x40021400)
2:通过指针和结构体进行封装
//a---f定义非常多
//每个寄存器都占用4个字节,32位,连续的
//定义结构体
typedef unsigned int uint32_t;
typedef unsigned short int uint16_t;
typedef struct
{
uint32_t MODER;
uint32_t OTYPER;
uint32_t OSPEEDR;
uint32_t PUPDR;
uint32_t IDR;
uint32_t ODR;
uint32_t BSSR;
uint32_t LCKR;
uint16_t AFRL;
uint16_t AFRH;
}GPIO_TypeDef;
#define GPIOA_BASE (0x40020000)
#define GPIOB_BASE (0x40020400)
#define GPIOC_BASE (0x40020800)
#define GPIOD_BASE (0x40020C00)
#define GPIOE_BASE (0x40021000)
#define GPIOF_BASE (0x40021400)
#define GPIOA (GPIO_TyoeDef *)GPIOA_BASE
#define GPIOB (GPIO_TyoeDef *)GPIOB_BASE
#define GPIOC (GPIO_TyoeDef *)GPIOC_BASE
#define GPIOD (GPIO_TyoeDef *)GPIOD_BASE
#define GPIOE (GPIO_TyoeDef *)GPIOE_BASE
#define GPIOF (GPIO_TyoeDef *)GPIOF_BASE
GPIOF->ODR=0xFFFF;//操作寄存器,
3.在51单片机里面的操作
4.在stm32里面的操作
之所以在最前面加*是因为,不加*为地址 ,地址不能直接赋值;加上为指针,指针可以直接赋值。