#include "gpio.h"
//========================================================================
// 函数: void gpio_enable(Pin_IO pin, GPIO_mode mode)
// 描述: GPIO引脚使能。
// 参数: Pin_IO pin : GPIO端口.
// 参数: GPIO_mode mode : GPIO端口模式.
// 返回: 无.
// 版本: V1.0, 2024-8-9
//========================================================================
void gpio_enable(Pin_IO pin, GPIO_mode mode){
if(pin/8 == 0){
if(mode == 0) P0M1 &= ~(0x01<<(pin%8)), P0M0 &= ~(0x01<<(pin%8)); //上拉准双向口
if(mode == 1) P0M1 |= (0x01<<(pin%8)), P0M0 &= ~(0x01<<(pin%8)); //浮空输入
if(mode == 2) P0M1 |= (0x01<<(pin%8)), P0M0 |= (0x01<<(pin%8)); //开漏输出
if(mode == 3) P0M1 &= ~(0x01<<(pin%8)), P0M0 |= (0x01<<(pin%8)); //推挽输出
}
if(pin/8 == 1){
if(mode == 0) P1M1 &= ~(0x01<<(pin%8)), P1M0 &= ~(0x01<<(pin%8)); //上拉准双向口
if(mode == 1) P1M1 |= (0x01<<(pin%8)), P1M0 &= ~(0x01<<(pin%8)); //浮空输入
if(mode == 2) P1M1 |= (0x01<<(pin%8)), P1M0 |= (0x01<<(pin%8)); //开漏输出
if(mode == 3) P1M1 &= ~(0x01<<(pin%8)), P1M0 |= (0x01<<(pin%8)); //推挽输出
}
if(pin/8 == 2){
if(mode == 0) P2M1 &= ~(0x01<<(pin%8)), P2M0 &= ~(0x01<<(pin%8)); //上拉准双向口
if(mode == 1) P2M1 |= (0x01<<(pin%8)), P2M0 &= ~(0x01<<(pin%8)); //浮空输入
if(mode == 2) P2M1 |= (0x01<<(pin%8)), P2M0 |= (0x01<<(pin%8)); //开漏输出
if(mode == 3) P2M1 &= ~(0x01<<(pin%8)), P2M0 |= (0x01<<(pin%8)); //推挽输出
}
if(pin/8 == 3){
if(mode == 0) P3M1 &= ~(0x01<<(pin%8)), P3M0 &= ~(0x01<<(pin%8)); //上拉准双向口
if(mode == 1) P3M1 |= (0x01<<(pin%8)), P3M0 &= ~(0x01<<(pin%8)); //浮空输入
if(mode == 2) P3M1 |= (0x01<<(pin%8)), P3M0 |= (0x01<<(pin%8)); //开漏输出
if(mode == 3) P3M1 &= ~(0x01<<(pin%8)), P3M0 |= (0x01<<(pin%8)); //推挽输出
}
if(pin/8 == 4){
if(mode == 0) P4M1 &= ~(0x01<<(pin%8)), P4M0 &= ~(0x01<<(pin%8)); //上拉准双向口
if(mode == 1) P4M1 |= (0x01<<(pin%8)), P4M0 &= ~(0x01<<(pin%8)); //浮空输入
if(mode == 2) P4M1 |= (0x01<<(pin%8)), P4M0 |= (0x01<<(pin%8)); //开漏输出
if(mode == 3) P4M1 &= ~(0x01<<(pin%8)), P4M0 |= (0x01<<(pin%8)); //推挽输出
}
if(pin/8 == 5){
if(mode == 0) P5M1 &= ~(0x01<<(pin%8)), P5M0 &= ~(0x01<<(pin%8)); //上拉准双向口
if(mode == 1) P5M1 |= (0x01<<(pin%8)), P5M0 &= ~(0x01<<(pin%8)); //浮空输入
if(mode == 2) P5M1 |= (0x01<<(pin%8)), P5M0 |= (0x01<<(pin%8)); //开漏输出
if(mode == 3) P5M1 &= ~(0x01<<(pin%8)), P5M0 |= (0x01<<(pin%8)); //推挽输出
}
if(pin/8 == 6){
if(mode == 0) P6M1 &= ~(0x01<<(pin%8)), P6M0 &= ~(0x01<<(pin%8)); //上拉准双向口
if(mode == 1) P6M1 |= (0x01<<(pin%8)), P6M0 &= ~(0x01<<(pin%8)); //浮空输入
if(mode == 2) P6M1 |= (0x01<<(pin%8)), P6M0 |= (0x01<<(pin%8)); //开漏输出
if(mode == 3) P6M1 &= ~(0x01<<(pin%8)), P6M0 |= (0x01<<(pin%8)); //推挽输出
}
}
#if m==1
//========================================================================
// 函数: void gpio_write(Pin_IO pin, unsigned int dat)
// 描述: GPIO状态写入。
// 参数: Pin_IO pin : GPIO端口.
// 参数: unsigned int dat : GPIO状态.
// 返回: 无.
// 版本: V1.0, 2024-8-9
//========================================================================
void gpio_write(Pin_IO pin, unsigned int dat){
if(pin/8 == 0){
if(dat)P0 |= (0x01<<(pin%8));
else P0 &= ~(0x01<<(pin%8));
}
if(pin/8 == 1){
if(dat)P1 |= (0x01<<(pin%8));
else P1 &= ~(0x01<<(pin%8));
}
if(pin/8 == 2){
if(dat)P2 |= (0x01<<(pin%8));
else P2 &= ~(0x01<<(pin%8));
}
if(pin/8 == 3){
if(dat)P3 |= (0x01<<(pin%8));
else P3 &= ~(0x01<<(pin%8));
}
if(pin/8 == 4){
if(dat)P4 |= (0x01<<(pin%8));
else P4 &= ~(0x01<<(pin%8));
}
if(pin/8 == 5){
if(dat)P5 |= (0x01<<(pin%8));
else P5 &= ~(0x01<<(pin%8));
}
if(pin/8 == 6){
if(dat)P6 |= (0x01<<(pin%8));
else P6 &= ~(0x01<<(pin%8));
}
}
//========================================================================
// 函数: void gpio_toggle(Pin_IO pin)
// 描述: GPIO状态翻转。
// 参数: Pin_IO pin : GPIO端口.
// 返回: 无.
// 版本: V1.0, 2024-8-9
//========================================================================
void gpio_toggle(Pin_IO pin){
if(pin/8 == 0)P0 ^= (0x01<<(pin%8));
if(pin/8 == 1)P1 ^= (0x01<<(pin%8));
if(pin/8 == 2)P2 ^= (0x01<<(pin%8));
if(pin/8 == 3)P3 ^= (0x01<<(pin%8));
if(pin/8 == 4)P4 ^= (0x01<<(pin%8));
if(pin/8 == 5)P5 ^= (0x01<<(pin%8));
if(pin/8 == 6)P6 ^= (0x01<<(pin%8));
}
//========================================================================
// 函数: void gpio_read(Pin_IO pin)
// 描述: GPIO状态读取。
// 参数: Pin_IO pin : GPIO端口.
// 返回: 无.
// 版本: V1.0, 2024-8-9
//========================================================================
unsigned int gpio_read(Pin_IO pin){
unsigned int dat;
if(pin/8 == 0)dat = (P0 & (0x01<<(pin%8))) ? 1 : 0;
if(pin/8 == 1)dat = (P1 & (0x01<<(pin%8))) ? 1 : 0;
if(pin/8 == 2)dat = (P2 & (0x01<<(pin%8))) ? 1 : 0;
if(pin/8 == 3)dat = (P3 & (0x01<<(pin%8))) ? 1 : 0;
if(pin/8 == 4)dat = (P4 & (0x01<<(pin%8))) ? 1 : 0;
if(pin/8 == 5)dat = (P5 & (0x01<<(pin%8))) ? 1 : 0;
if(pin/8 == 6)dat = (P6 & (0x01<<(pin%8))) ? 1 : 0;
return dat;
}
#endif
没有合适的资源?快使用搜索试试~ 我知道了~
stc32跑马灯Keil例程
共35个文件
obj:5个
crf:5个
lst:5个
需积分: 0 0 下载量 84 浏览量
2024-08-11
00:57:08
上传
评论
收藏 102KB ZIP 举报
温馨提示
自己看
资源推荐
资源详情
资源评论
收起资源包目录
demo.zip (35个子文件)
demo
led.uvproj 13KB
Objects
gpio_kuo.__i 128B
led.build_log.htm 1KB
led.obj 3KB
gpio_kuo.obj 5KB
led.hex 6KB
delay.__i 119B
mian.crf 51KB
gpio.obj 7KB
led.crf 55KB
delay.crf 51KB
led 12KB
delay.obj 3KB
mian.obj 3KB
gpio.crf 58KB
led.lnp 199B
gpio.__i 116B
led.__i 113B
gpio_kuo.crf 56KB
led.uvgui.admin 88KB
Library
gpio.h 1KB
led.h 120B
config.h 277B
delay.h 189B
delay.c 1KB
led.c 705B
gpio.c 5KB
Listings
led.map 29KB
gpio_kuo.lst 5KB
gpio.lst 9KB
delay.lst 3KB
mian.lst 2KB
led.lst 2KB
mian.c 640B
led.uvopt 6KB
共 35 条
- 1
资源评论
海绵宝宝爱喝奶茶
- 粉丝: 125
- 资源: 21
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功