这个不是大家都喜欢,但我喜欢这种设置,在多IO初始化定以后对 IO的操作可读性高了很多,接近于C51的风格.


//例输入代码" PA O0H ;" ,GPIOA_0位输出高电平
//例输入代码" PA O0L; " ,GPIOA_0位输出低电平

//例输入代码" PA I0 ;"   ,读取GPIOA_0位的电平


#define PA ((GPIO_TypeDef *) ((((uint32_t)0x40000000) + 0x10000) + 0x0800))   //GPIOA定义层PA
#define PB ((GPIO_TypeDef *) ((((uint32_t)0x40000000) + 0x10000) + 0x0C00))   //GPIOB定义层PB
#define PC ((GPIO_TypeDef *) ((((uint32_t)0x40000000) + 0x10000) + 0x1000))   //GPIOC定义层PC
#define PD ((GPIO_TypeDef *) ((((uint32_t)0x40000000) + 0x10000) + 0x1400))   //GPIOD定义层PD
#define PE ((GPIO_TypeDef *) ((((uint32_t)0x40000000) + 0x10000) + 0x1800))   //GPIOE定义层PE


//例" PA O0H "  GPIOA_0位输出高电平
//例" PA O0L "  GPIOA_0位输出低电平
#define O0H ->BSHR=0x0001
#define O0L ->BCR=0x0001
#define O1H ->BSHR=0x0002
#define O1L ->BCR=0x0002
#define O2H ->BSHR=0x0004
#define O2L ->BCR=0x0004
#define O3H ->BSHR=0x0008
#define O3L ->BCR=0x0008
#define O4H ->BSHR=0x0010
#define O4L ->BCR=0x0010
#define O5H ->BSHR=0x0020
#define O5L ->BCR=0x0020
#define O6H ->BSHR=0x0040
#define O6L ->BCR=0x0040
#define O7H ->BSHR=0x0080
#define O7L ->BCR=0x0080
#define O8H ->BSHR=0x0100
#define O8L ->BCR=0x0100
#define O9H ->BSHR=0x0200
#define O9L ->BCR=0x0200
#define O10H ->BSHR=0x0400
#define O10L ->BCR=0x0400
#define O11H ->BSHR=0x0800
#define O11L ->BCR=0x0800
#define O12H ->BSHR=0x1000
#define O12L ->BCR=0x1000
#define O13H ->BSHR=0x2000
#define O13L ->BCR=0x2000
#define O14H ->BSHR=0x4000
#define O14L ->BCR=0x4000
#define O15H ->BSHR=0x8000
#define O15L ->BCR=0x8000


//例" PA I0 "   读取GPIOA_0位的电平
#define I0 ->INDR&0x0001   //读取0位GPIO电平
#define I1 ->INDR&0x0002   //读取1位GPIO电平
#define I2 ->INDR&0x0004
#define I3 ->INDR&0x0008
#define I4 ->INDR&0x0010
#define I5 ->INDR&0x0020
#define I6 ->INDR&0x0040
#define I7 ->INDR&0x0080
#define I8 ->INDR&0x0100
#define I9 ->INDR&0x0200
#define I10 ->INDR&0x0400
#define I11 ->INDR&0x0800
#define I12 ->INDR&0x1000
#define I13 ->INDR&0x2000
#define I14 ->INDR&0x4000
#define I15 ->INDR&0x8000