📄 zlg7289a.c
字号:
#include <REG52.H>
#include <main.h>
#include <zlg7289A.h>
//键值号 输入键 ENTER | 测量键 MEASURE | 右移键 -> | 减少键 - | 增加键 + | 设置键 OPTION
// 7 15 23 31 39 47
//数码管位地址 通道号 数据(千位) 数据(百位) 数据(十位) 数据(个位) 四个发光管
// 7 6 5 4 3 2
// 按方式0译码时:对应显示0-9数字和"-,E,H,L,P,空(无显示)"
// 按方式1译码时:对应显示0-9数字和A-F字符
//键值变量
uchar symble=0xFF; //初始态设为无键值按下的返回值
//延时子程序 参数×10us=延时数
//参数:10us的倍数
void delayus(uchar us)
{
uchar i;
us=us*3;
for(i=0;i<us;i++);
}
//纯指令操作函数
//参数:纯指令关键字
void SingleCommand(uchar command)
{
uchar i;
CS_ZLG7289A=LOW;
CLK_ZLG7289A=0;
delayus(3);
for(i=8;i>=1;i--) //发送八位数据
{
DIO_ZLG7289A=command&0x08;
command=command<<1;
CLK_ZLG7289A=HIGH;
delayus(1);
CLK_ZLG7289A=LOW;
delayus(1);
}
CS_ZLG7289A=HIGH;
delayus(1);
}
//带参数指令操作函数
//参数:带参数指令关键字command; 数码管位置position(如无位置参数则设为0); 参数data_8bit
void BiCommand(uchar command,uchar positoin,uchar data_8bit)
{
uchar i;
command=command+positoin;
CS_ZLG7289A=LOW;
CLK_ZLG7289A=0;
delayus(3);
for(i=8;i>=1;i--) //发送八位数据
{
DIO_ZLG7289A=command&0x08;
command=command<<1;
CLK_ZLG7289A=HIGH;
delayus(1);
CLK_ZLG7289A=LOW;
delayus(1);
}
delayus(2);
for(i=8;i>=1;i--) //发送八位数据
{
DIO_ZLG7289A=data_8bit&0x08;
data_8bit=data_8bit<<1;
CLK_ZLG7289A=HIGH;
delayus(1);
CLK_ZLG7289A=LOW;
delayus(1);
}
CS_ZLG7289A=HIGH;
delayus(1);
}
//读键盘操作函数
//参数:无
//返回值:键值
uchar ReadKey()
{
uchar i;
uchar data_in=0; //接收数据存储单元
uchar command=ReadKeyCom; //读键盘命令
CS_ZLG7289A=LOW;
CLK_ZLG7289A=0;
delayus(3);
for(i=8;i>=1;i--) //发送八位数据
{
DIO_ZLG7289A=command&0x08;
command=command<<1;
CLK_ZLG7289A=HIGH;
delayus(1);
CLK_ZLG7289A=LOW;
delayus(1);
}
DIO_ZLG7289A=HIGH; //端口置为接收状态
delayus(2);
for(i=8;i>=1;i--) //接收八位数据
{
CLK_ZLG7289A=HIGH;
delayus(1);
data_in=data_in<<1;
data_in=DIO_ZLG7289A|data_in;
CLK_ZLG7289A=LOW;
delayus(1);
}
CS_ZLG7289A=HIGH;
delayus(1);
return(data_in);
}
//数码管显示
//参数:数码管位置地址 position 显示方式:dfuction (DownDataCom_0; DownDataCom_1; DownDataCom等)
//
//显示数据:ddata
void LedShow(uchar position,uchar dfuction,uchar ddata,uchar dp)
{
uchar data_high,data_low;
if(dfuction==DownDataCom_0||dfuction==DownDataCom_1||DownDataCom) //下载数据
{
data_high=position+2;
data_low=ddata+dp;
BiCommand(dfuction,data_high,data_low);
}
if(dfuction==TwinkleCom) //闪烁控制
{
data_high=position+2;
BiCommand(dfuction,data_high,0);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -