找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 737|回复: 0
打印 上一主题 下一主题
收起左侧

分享自定义CH32V系列MCU简洁GPIO操作

[复制链接]
跳转到指定楼层
楼主
ID:272119 发表于 2023-6-1 17:02 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
这个不是大家都喜欢,但我喜欢这种设置,在多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






评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表