#define PERIPH_BASE ((unsigned int)0x40000000) //定义外围总线基地址
#define APB1PERIPH_BASE (PERIPH_BASE) //APB1总线开始与外围总线基地址
#define APB2PERIPH_BASE (PERIPH_BASE +0x10000) //APB2外围总线偏移0x10000
#define APBPERIPH_BASE (PERIPH_BASE +0x20000) //APB外围总线偏移0x20000
#define RCC_BASE (APBPERIPH_BASE+0x1000) //RCC基地址为APB总线地址偏移0x1000
#define GPIOB_BASE (APB2PERIPH_BASE+0x0C00) //GPIOB_基地址为APB2总线地址偏移
#define RCC_APB2ENR *(unsigned int*)(RCC_BASE+0x18) //强制类型转换+解引用
//#define GPIOB_CRL *(unsigned int*)(GPIOB_BASE) //对应寄存器的配置
//#define GPIOB_CRH *(unsigned int*)(GPIOB_BASE+0x04)
//#define GPIOB_ODR *(unsigned int*)(GPIOB_BASE+0x0C)
typedef struct //定义结构体类型
{
unsigned int CRL;
unsigned int CRH;
unsigned int IDR;
unsigned int ODR;
unsigned int BSRR;
unsigned int BRR;
unsigned int LCKR;
}GPIO_TypeDef;
typedef struct //定义结构体类型
{
unsigned int CR;
unsigned int CFGR;
unsigned int CIR;
unsigned int APB2RSTR;
unsigned int APB1RSTR;
unsigned int AHNEMR;
unsigned int APB2ENR;
unsigned int APB1ENR;
unsigned int BDCR;
unsigned int CSR;
}RCC_TypeDef;
#define GPIOB ((GPIO_TypeDef*)GPIOB_BASE) //GPIOB基地址强制类型转换为GPOIO_TYPEDEF类型的结构体指针,指向GPIOB区地址
#define RCC ((RCC_TypeDef*)RCC_BASE) //RCC基地址强制类型转换
基地址>>寄存器>>结构体指针>>外设封装函数