這個不是大家都喜歡,但我喜歡這種設(shè)置,在多IO初始化定以后對 IO的操作可讀性高了很多,接近于C51的風(fēng)格.
//例輸入代碼" 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
查看: 4036
回復(fù): 0
分享自定義CH32V系列MCU簡潔GPIO操作
熱門產(chǎn)品 :
CH32V317: 互聯(lián)型青稞RISC-V MCU
請勿發(fā)布廣告和違法內(nèi)容, 代碼可以選擇編輯器代碼語言格式, 更易他人閱讀幫助您, 或者留下聯(lián)系方式,以便更好更快服務(wù)您
只有登錄才能回復(fù),可以選擇微信賬號登錄