#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
#define lcd_data P0
#define RxBuf_N 17
sbit lcd_rs=P3^4;
sbit lcd_rw=P3^5;
sbit lcd_en=P3^6;
sbit lcd_psb=P3^7;
uchar code tab[]={"欢迎使用"};
uchar code erro[]={"输入错误"};
uchar code *tab0[2]={"1.输入手机号","2.节点信息查询"};
uchar code *tab1[4]={"1:","2:","3:","4:"};
uchar code tab3[]={"节点"};
uchar code *tab4[4]={"地址: ","温度: ","浓度: ","电压: "};
uchar idata phone[4][11]={0},RxBuf[18]={0};
uchar idata buffer[8][17];
uchar table,a,b,RxPoint,gsmflag,recflag;
uchar count=0;
char page;
void delay(uint z) //1ms
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void write_cmd(uchar cmd) //lcd写命令
{
lcd_rs=0;
lcd_rw=0;
lcd_en=0;
P0=cmd;
delay(5);
lcd_en=1;
delay(5);
lcd_en=0;
}
void write_dat(uchar dat) //lcd写数据
{
lcd_rs=1;
lcd_rw=0;
lcd_en=0;
P0=dat;
delay(5);
lcd_en=1;
delay(5);
lcd_en=0;
}
void lcd_pos(uchar X,uchar Y) //液晶定位
{
uchar pos;
if(X==0)
{X=0x80;}
else if(X==1)
{X=0x90;}
else if(X==2)
{X=0x88;}
else if(X==3)
{X=0x98;}
pos=X+Y;
write_cmd(pos);
}
void lcd_init() //液晶初始化
{
lcd_psb=1;
write_cmd(0x30);
delay(5);
write_cmd(0x0c);
delay(5);
write_cmd(0x01);
delay(5);
}
void disnum(uchar number)
{
uchar shi,ge;
shi=number/10;
ge=number%10;
write_dat(shi+0x30);
delay(5);
write_dat(ge+0x30);
delay(5);
}
void distab0()
{
uchar i,j;
lcd_init();
j=0;
while(j!=2)
{
lcd_pos(j,0);
i=0;
while(tab0[j][i]!='\0')
{
write_dat(tab0[j][i]);
i++;
}
j++;
}
}
void distab1()
{
uchar i,j,k;
lcd_init();
j=k=0;
while(j!=4)
{
lcd_pos(j,0);
i=0;
while(tab1[j][i]!='\0')
{
write_dat(tab1[j][i]);
i++;
}
for(k=0;(k<11)&&(!phone[j][k]);k++);
if(k<11)
{
for(k=0;k<11;k++)
write_dat(phone[j][k]+0x30);
}
j++;
}
}
void distab2() //////////////////////////
{
uchar k;
write_cmd(0x0f);
delay(5);
lcd_pos(a,1);
for(k=0;k<b+1;k++)
write_dat(phone[a][k]+0x30);
}
void distab3()
{
uchar i,j;
lcd_init();
j=0;
while(j!=4)
{
lcd_pos(j,0);
disnum(4*page+j+1);
lcd_pos(j,2);
i=0;
while(tab3[i]!='\0')
{
write_dat(tab3[i]);
i++;
}
disnum(4*page+j+1);
j++;
}
}
void disdata(uchar js)
{
uchar i;
lcd_pos(0,6); //显示地址
disnum(buffer[js][0]);
delay(5);
lcd_pos(1,3); //显示温度
i=2;
while(i<7)
{
write_dat(buffer[js][i]);
i++;
}
write_dat('C');
delay(5);
lcd_pos(2,3); //显示浓度
i=7;
while(i<12)
{
write_dat(buffer[js][i]);
i++;
}
write_dat('P');
write_dat('P');
write_dat('M');
delay(5);
lcd_pos(3,3); //显示电压
i=12;
while(i<17)
{
write_dat(buffer[js][i]);
i++;
}
write_dat('V');
delay(5);
}
void distab4(uchar jn)
{
uchar i,j;
lcd_init();
i=0;
while(tab3[i]!='\0')
{
write_dat(tab3[i]);
i++;
}
disnum(jn);
i=0;
while(tab4[0][i]!='\0')
{
write_dat(tab4[0][i]);
i++;
}
j=1;
while(j!=4)
{
lcd_pos(j,0);
i=0;
while(tab4[j][i]!='\0')
{
write_dat(tab4[j][i]);
i++;
}
/////////////////////////shuju
j++;
}
disdata(jn-1);
}
void diserro()
{
uchar i,j;
lcd_init();
lcd_pos(1,2);
i=0;
while(erro[i]!='\0')
{
write_dat(erro[i]);
i++;
}
for(j=0;j<11;j++)
phone[a][j]=0;
b=0;
delay(1500);
distab1();
distab2();
}
void init() // 主程序初始化
{
uchar i,j;
table=0;
page=0;
a=b=0;
RxPoint=gsmflag=recflag=0;
for(i=0;i<8;i++)
{
buffer[i][0]=0;
for(j=1;j<17;j++)
buffer[i][j]='0';
}
TMOD = 0x20;
TH1 = 0xfd; //9600赫兹
TL1 = 0xfd;
TR1 = 1; //开启时间中断
SCON = 0x50;//方式2
SM2 = 1; //可以向cpu请求中断
EA = 1; //开总中断
ES = 1; //开串口中断
lcd_init();
lcd_pos(1,2);
i=0;
while(tab[i]!='\0')
{
write_dat(tab[i]);
i++;
}
delay(3000);
distab0();
}
void shifan()
{
uchar temp;
temp=P2;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P2;
temp=temp&0xf0;
}
}
void keyscan() //键盘扫描
{
uchar temp,key,r;
P2=0xfe; //按键1,2,3,4
temp=P2;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(10);
temp=P2;
temp=temp&0xf0;
if(temp!=0xf0)
{
temp=P2;
switch(temp)
{
case 0xee:
key=1;
break;
case 0xde:
key=2;
break;
case 0xbe:
key=3;
break;
case 0x7e:
key=4;
break;
}
shifan();
if(key==1)
{
switch(table)
{
case 0:
table++;
distab1();
break;
case 1:
table++;
a=0;
distab2();/////////
break;
case 2:
if(b<11)
{
phone[a][b]=1;
distab2();/////////
b++;
}
else diserro();
break;
case 3:
table++;
distab4(4*page+1);
break;
}
}
if(key==2)
{
switch(table)
{
case 0:
table=3;
distab3();
break;
case 1:
table++;
a=1;
distab2();/////////
break;
case 2:
if(b<11)
{
phone[a][b]=2;
distab2();/////////
b++;
}
else diserro();
break;
case 3:
table++;
distab4(4*page+2);
break;
}
}
if(key==3)
{
switch(table)
{
case 1:
table++;
a=2;
distab2();/////////
break;
case 2:
if(b<11)
{
phone[a][b]=3;
distab2();/////////
b++;
}
else diserro();
break;
case 3:
table++;
distab4(4*page+3);
break;
}
}
if(key==4)
{
switch(table)
{
case 1:
table++;
a=3;
distab2();/////////
break;
case 2:
if(b<11)
{
phone[a][b]=4;
distab2();/////////
b++;
}
else diserro();
break;
case 3:
table++;
distab4(4*page+4);
break;
}
}
}
}
P2=0xfd; //5,6,7,8
temp=P2;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(10);
temp=P2;
temp=temp&0xf0;
if(temp!=0xf0)
{
temp=P2;
switch(temp)
{
case 0xed:
key=5;
break;
case 0xdd:
key=6;
break;
case 0xbd:
key=7;
break;
case 0x7d:
key=8;
break;
}
shifan();
if(key==5)
{
switch(table)
{
case 2:
if(b<11)
{
phone[a][b]=5;
distab2();/////////
b++;
}
else diserro();
break;
}
}
if(key==6)
{
switch(table)
{
case 2:
if(b<11)
{
phone[a][b]=6;
distab2();/////////
b++;
}
else diserro();
break;
}
}
if(key==7)
{
switch(table)
{
case 2:
if(b<11)
{
phone[a][b]=7;
distab2();/////////
b++;
}
else diserro();
break;
case 3:
page--;
if(page<0)
page=2;
distab3();
break;
}
}
if(key==8)
{
switch(table)
{
case 2:
if
御道御小黑
- 粉丝: 78
- 资源: 1万+
最新资源
- 14-基于LLM+向量库的文档对话 经验面.pdf
- 18-大模型(LLMs)RAG 版面分析——文本分块面.pdf
- 17-大模型(LLMs)RAG 版面分析——表格识别方法篇.pdf
- 16-LLM文档对话 —— pdf解析关键问题.pdf
- 19-大模型外挂知识库优化——如何利用大模型辅助召回?.pdf
- 20-大模型外挂知识库优化——负样本样本挖掘篇.pdf
- 24-大模型(LLMs)RAG 优化策略 —— RAG-Fusion篇.pdf
- 22-检索增强生成(RAG) 优化策略篇.pdf
- 27-适配器微调(Adapter-tuning)篇.pdf
- 25-Graph RAG 面 — 一种 基于知识图谱的大模型检索增强实现策略.pdf
- 26-大模型(LLMs)参数高效微调(PEFT) 面.pdf
- 28-提示学习(Prompting)篇.pdf
- 31-大模型(LLMs)推理面.pdf
- 32-大模型(LLMs)增量预训练篇.pdf
- PCB设计的基础教程与技巧分享笔记
- 35-大模型(LLMs)评测面.pdf
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈