专家
公告
财富商城
电子网
旗下网站
首页
问题库
专栏
标签库
话题
专家
NEW
门户
发布
提问题
发文章
51单片机
现在正在做的设计的一部分-------------用S52和1602液晶做的可进行设置的多级菜单
2020-01-27 11:29
发布
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
站内问答
/
51单片机
8228
39
39
原理图:
点击此处下载ourdev_222975.rar(文件大小:5K)
程序由于是系统的一部分,就直接贴出来了
实物图:
1
硬件是我做的89S52的单片机系统,然后把连线改成跟上附的原理图一样。
效果图:顺序对应下面程序里的 工作流程的 1~6级子菜单
1
2
3
4
5
6
友情提示:
此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
39条回答
shrlyq
2020-01-27 16:53
下面附上程序,,程序中的串行通信部分是把菜单的设置传到被设置部分用的。
主文件:
#include<at89x52.h>
#include<absacc.h>
#include<memory.h>
#include<lcm.h>
#define Retry 0x80
unsigned char table[]={'0','1','2','3','4','5','6','7','8','9'};
unsigned char code DataSeclete[]={ //在发送数据前先发此,用来选择模式的代号
0x81, //0 停止用的包头代号
0x82, //1 查询用的包头代号
0x83 //2 设置用的包头代号
};
unsigned char DataBase[]={ //向下设置的数值
0x46, //0 地址(密码)
0xff, //1 总开关(0x00为关,0xff为开)
0x00, //2 分钟
0x01, //3 小时(最大99)
0x1a, //4 时间修正值(修正值是计数器溢出次数24-33,默认值是29,分10个档,设置时对应为0~9,设置值+24=修正值)
0xB2, //5 温度上限,默认是50度(最高位为正负号,1为正,0为负,后面7位为温度值,范围为-9~+99)
0x80, //6 温度下限,默认是0度(最高位为正负号,1为正,0为负,后面7位为温度值,范围为-9~+99)
0x14, //7 震动灵敏度(灵敏度是25毫秒内震动的次数2-20,设置时对应为0~9,设置值*2+2=灵敏度)
};
unsigned char DataReceive[]={ //向上读取的数值,把地址改为是否已经报警
0x00, //0 是否已经报警(1不报警,0报警)
0x00, //1 工作状态0x00为不工作,0xff为工作
0x00, //2 分钟
0x00, //3 小时(最大99)
};
sbit KeyA=P1^0;
sbit KeyB=P1^1;
sbit KeyC=P1^2;
sbit KeyD=P1^3;
sbit HzOut=P3^3;
unsigned char KEYA = 1,//按键A被按下为0,未按为零,,下同
KEYB = 1,
KEYC = 1,
KEYD = 1;
unsigned char LiuCheng1 = 1, //停止流程,1未开始,0开始,下同
LiuCheng1_1 = 1,//工作子流程-设置对应的地址 DispSetAddress(unsigned char HH,HL,sign)//输入被控板的地址,输入数值,位置
LiuCheng1_password[8], //流程1的地址暂存数组
LiuCheng1_1_Sign = 8, //焦点位置
//LiuCheng1_password[0]地址8位
//LiuCheng1_password[1]地址7位
//LiuCheng1_password[2]地址6位
//LiuCheng1_password[3]地址5位
//LiuCheng1_password[4]地址4位
//LiuCheng1_password[5]地址3位
//LiuCheng1_password[6]地址2位
//LiuCheng1_password[7]地址1位
LiuCheng2 = 1, //查询流程
LiuCheng3 = 1, //工作流程
LiuCheng3_1 = 1,//工作子流程-设时间
LiuCheng3_1_HH, //小时十位
LiuCheng3_1_HL, //小时个位
LiuCheng3_1_LH, //小时十位
LiuCheng3_1_LL, //小时个位
LiuCheng3_1_Sign = 4, //焦点位置
LiuCheng3_2 = 1,//工作子流程-时间修正值
LiuCheng3_2_Num, //修正值
LiuCheng3_3 = 1,//工作子流程-温度上限
LiuCheng3_3_HH, //温度十位
LiuCheng3_3_HL, //温度个位
LiuCheng3_3_Sign, //温度正负号
LiuCheng3_3_WeiZhi = 3,//焦点位置
LiuCheng3_4 = 1,//工作子流程-温度下限
LiuCheng3_4_HH, //温度十位
LiuCheng3_4_HL, //温度个位
LiuCheng3_4_Sign, //温度正负号
LiuCheng3_4_WeiZhi = 3,//焦点位置
LiuCheng3_5 = 1,//工作子流程-震动灵敏度
LiuCheng3_5_Num = 0, //灵敏度
LiuCheng3_6 = 1,//工作子流程-设置对应的地址 DispSetAddress(unsigned char HH,HL,sign)//输入被控板的地址,输入数值,位置
LiuCheng3_password[8],//流程3的地址暂存数组
//LiuCheng3_password[0]地址8位
//LiuCheng3_password[1]地址7位
//LiuCheng3_password[2]地址6位
//LiuCheng3_password[3]地址5位
//LiuCheng3_password[4]地址4位
//LiuCheng3_password[5]地址3位
//LiuCheng3_password[6]地址2位
//LiuCheng3_password[7]地址1位
LiuCheng3_6_Sign = 8; //焦点位置
unsigned char LiuCheng1Enable = 1,//停止流程使能
LiuCheng2Enable = 1,//查询流程使能
LiuCheng3Enable = 1;//工作流程使能
////////////////////////////////////////////////////////////////////////////////////////////////////////////菜单显示函数
void DispPasswordError(void)
{
/****************
Password Wrong.
Please Retry!
****************/
printx(0,0,"Password Wrong. ");
printx(0,1,"Please Retry! ");
}
void DispSetTime(unsigned char HH,HL,LH,LL,weizhi)//设置时间,输入小时十位,小时个位,分钟十位,分钟个位,焦点相对位置
{
/****************
(hour:min) 00:00
set time: ^
****************/
printx(0,0,"(hour:min) : ");
DispOneChar(11,0,table[HH]);
DispOneChar(12,0,table[HL]);
DispOneChar(14,0,table[LH]);
DispOneChar(15,0,table[LL]);
if(weizhi == 1)
{
printx(0,1,"set time: ^ ");
}
if(weizhi == 2)
{
printx(0,1,"set time: ^ ");
}
if(weizhi == 3)
{
printx(0,1,"set time: ^ ");
}
if(weizhi == 4)
{
printx(0,1,"set time: ^");
}
}
void DispSetRevise(unsigned char num)//设置时间修正值,输入数值
{
/****************
( 0 - 9 ) 0
Xiu Zheng : ^
****************/
printx(0,0,"( 0 - 9 ) ");
printx(0,1,"Xiu Zheng : ^ ");
DispOneChar(14,0,table[num]);
}
void DispTemUp(unsigned char HH,HL,sign,weizhi)//设置温度上限十位,上限个位,输入符号(0为负,1为正),数值,位置
{
/****************
(-9 - +99) x00
Tem up : ^
****************/
printx(0,0,"(-9 - +99) ");
if(sign == 0)
{
DispOneChar(12,0,'-');
}
else
{
DispOneChar(12,0,'+');
}
DispOneChar(13,0,table[HH]);
DispOneChar(14,0,table[HL]);
if(weizhi == 1)
{
printx(0,1,"Tem up : ^ ");
}
if(weizhi == 2)
{
printx(0,1,"Tem up : ^ ");
}
if(weizhi == 3)
{
printx(0,1,"Tem up : ^ ");
}
}
void DispTemDown(unsigned char HH,HL,sign,weizhi)//设置温度下限十位,上限个位,输入符号(0为负,1为正),数值,位置
{
/****************
(-9 - +99) x00
Tem down: ^
****************/
printx(0,0,"(-9 - +99) ");
if(sign == 0)
{
DispOneChar(12,0,'-');
}
else
{
DispOneChar(12,0,'+');
}
DispOneChar(13,0,table[HH]);
DispOneChar(14,0,table[HL]);
if(weizhi == 1)
{
printx(0,1,"Tem down: ^ ");
}
if(weizhi == 2)
{
printx(0,1,"Tem down: ^ ");
}
if(weizhi == 3)
{
printx(0,1,"Tem down: ^ ");
}
}
void DispShake(unsigned char num)//震动灵敏度,输入数值0 ~ 9
{
/****************
( 0 - 9 ) 0
Shake: ^
****************/
printx(0,0,"( 0 - 9 ) ");
printx(0,1,"Shake: ^ ");
DispOneChar(13,0,table[num]);
}
void DispConnect(void)//正在传输中
{
/****************
Now Connecting..
Please Wait.....
****************/
printx(0,0,"Now Connecting..");
printx(0,1,"Please Wait.....");
}
void DispOver(void)//传输完毕
{
/****************
Deliver is over.
Please Wait.....
****************/
printx(0,0,"Deliver is over.");
printx(0,1,"Please Wait.....");
}
void DispStoping(void)//停止中
{
/****************
Now Stoping.....
Please Wait.....
****************/
printx(0,0,"Now Stoping.....");
printx(0,1,"Please Wait.....");
}
void DispSearch(void)//查看功能板的状态
{
/****************
Now Searching...
Please Wait.....
****************/
printx(0,0,"Now Searching...");
printx(0,1,"Please Wait.....");
}
void DispFindNow(unsigned char HH,HL,LH,LL,num,sign)//功能板的状态显示,输入小时十位,小时个位,分钟十位,分钟个位,报警状态,工作状态(1工作,0不工作)
{
/****************
ALARM time:00:00
working? YES/NO
****************/
printx(0,0," time: : ");
DispOneChar(11,0,table[HH]);
DispOneChar(12,0,table[HL]);
DispOneChar(14,0,table[LH]);
DispOneChar(15,0,table[LL]);
if(num == 0)//1不报警,0报警
{
DispOneChar(0,0,'A');
DispOneChar(1,0,'L');
DispOneChar(2,0,'A');
DispOneChar(3,0,'R');
DispOneChar(4,0,'M');
}
else
{
DispOneChar(0,0,'S');
DispOneChar(1,0,'A');
DispOneChar(2,0,'F');
DispOneChar(3,0,'T');
DispOneChar(4,0,'Y');
}
if(sign == 0xff)
{
printx(0,1,"working? YES ");
}
else
{
printx(0,1,"working? NO ");
}
}
void DispWelcome(void)//显示开机画面
{
/****************
System Work Now!
Designed By LYQ!
****************/
printx(0,0,"System Work Now!");
printx(0,1,"Designed By LYQ!");
}
void DispSetAddress(unsigned char *arrays,unsigned char sign)//输入被控板的地址,输入位置
{
/****************
Pass 00000000
word: ^
****************/
printx(0,0,"Pass ");
DispOneChar(8,0,table[arrays[0]]);
DispOneChar(9,0,table[arrays[1]]);
DispOneChar(10,0,table[arrays[2]]);
DispOneChar(11,0,table[arrays[3]]);
DispOneChar(12,0,table[arrays[4]]);
DispOneChar(13,0,table[arrays[5]]);
DispOneChar(14,0,table[arrays[6]]);
DispOneChar(15,0,table[arrays[7]]);
switch(sign)
{
case 1:
printx(0,1,"word: ^ ");
break;
case 2:
printx(0,1,"word: ^ ");
break;
case 3:
printx(0,1,"word: ^ ");
break;
case 4:
printx(0,1,"word: ^ ");
break;
case 5:
printx(0,1,"word: ^ ");
break;
case 6:
printx(0,1,"word: ^ ");
break;
case 7:
printx(0,1,"word: ^ ");
break;
case 8:
printx(0,1,"word: ^");
break;
default:
break;
}
}
unsigned char GetBaiwei(unsigned char temp)//从整数中取百位数
{
temp = temp/100;
return temp;
}
unsigned char GetShiwei(unsigned char temp)//从整数中取十位数
{
if(temp > 99)
{
temp = temp - GetBaiwei(temp)*100;
}
temp = temp/10;
return temp;
}
unsigned char GetGewei(unsigned char temp)//从整数中取个位数
{
temp = temp%10;
return temp;
}
void DispPassWord(unsigned char x1,x2,x3,y,num)//输入显示的x1,x2,x3,y,数值(5.6.7.1.DataBase[0])
{
DispOneChar(x1,y,table[GetBaiwei(num)]);
DispOneChar(x2,y,table[GetShiwei(num)]);
DispOneChar(x3,y,table[GetGewei(num)]);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////其他功能函数
void putchar(unsigned char a)//从串口发送一个字节
{
TI=0;
SBUF=a;
while(!TI);
TI=0;
}
unsigned char getchar(void)//从串口接收一个字节
{
unsigned char a;
RI = 0;
while(RI == 0);
a = SBUF;
RI = 0;
return a;
}
void PutAll(unsigned char * arrays)//从串口发送一个8数据数组
{
unsigned char i;
for(i=0;i<8;i++)//发8数据数组
{
putchar(arrays
);
}
}
void GetAll(unsigned char * arrays)//从串口接收一个4数据数组,参数是待接收的数组名,DataReceive[]或DataSbuffer[]
{
unsigned char i;
for(i=0;i<4;i++)//收4数据数组
{
arrays
= getchar();
}
}
void CalculatePassword(unsigned char * arrays,unsigned char ADDR)//把数组计算成设置
{
unsigned char temp,i;
temp = ADDR;
for(i=0;i<8;i++)
{
temp = ADDR<<i;
arrays
= temp>>7;
}
}
void ReCalculatePassword(unsigned char * arrays)//把设置还原成数组
{
DataBase[0] = arrays[0]*128+arrays[1]*64+arrays[2]*32+arrays[3]*16+arrays[4]*8+arrays[5]*4+arrays[6]*2+arrays[7];
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////中断函数
void Key(void) interrupt 0
{
unsigned char temp;
EA = 0;
Delay5Ms();
Delay5Ms();
/*读取按键*/
if(KeyA == 0)
{
KEYA = 0;
}
if(KeyB == 0)
{
KEYB = 0;
}
if(KeyC == 0)
{
KEYC = 0;
}
if(KeyD == 0)
{
KEYD = 0;
}
/*菜单判断*/
//停止流程
if((LiuCheng1 == 1)&&(LiuCheng1Enable == 1))
{
if(KEYA == 0)//按了“停止/返回”键
{
LiuCheng1 = 0;
LiuCheng1_1 = 0;
LiuCheng2Enable = 0;
LiuCheng3Enable = 0;
//读取下一个
CalculatePassword(LiuCheng1_password,DataBase[0]);
//显示
DispSetAddress(LiuCheng1_password,LiuCheng1_1_Sign);
DispPassWord(5,6,7,1,DataBase[0]);//输入显示的x1,x2,x3,y,数值(5.6.7.1.DataBase[0])
Delay400Ms();Delay400Ms();
}
}
else
{
if(LiuCheng1_1 == 0)
{
LiuCheng2Enable = 0;
LiuCheng3Enable = 0;
if(KEYB == 0)//按了“上翻/查询”键
{
//上翻
LiuCheng1_password[LiuCheng1_1_Sign -1] ++;
if(LiuCheng1_password[LiuCheng1_1_Sign-1] > 1)
{
LiuCheng1_password[LiuCheng1_1_Sign-1] -= 2;
}
//保存
ReCalculatePassword(LiuCheng1_password);//把结果统计进数组
DispSetAddress(LiuCheng1_password,LiuCheng1_1_Sign);
DispPassWord(5,6,7,1,DataBase[0]);//输入显示的x1,x2,x3,y,数值(5.6.7.1.DataBase[0])
Delay400Ms();
}
if(KEYC == 0)//按了“左翻”键
{
//左翻
LiuCheng1_1_Sign --;
if(LiuCheng1_1_Sign == 0)
{
LiuCheng1_1_Sign = 8;
}
//保存
ReCalculatePassword(LiuCheng1_password);//把结果统计进数组
DispSetAddress(LiuCheng1_password,LiuCheng1_1_Sign);
DispPassWord(5,6,7,1,DataBase[0]);//输入显示的x1,x2,x3,y,数值(5.6.7.1.DataBase[0])
Delay400Ms();
}
if(KEYA == 0)//按了“停止/返回”键
{
DispStoping(); //做下一个的显示
putchar(0xaa);//发开始码
putchar(DataBase[0]);//发密码
temp = getchar();//接收密码回馈
if(temp == Retry)//判断密码
{
DispPasswordError();
Delay400Ms();Delay400Ms();Delay400Ms();Delay400Ms();
Delay400Ms();Delay400Ms();Delay400Ms();Delay400Ms();
Delay400Ms();Delay400Ms();Delay400Ms();Delay400Ms();
Delay400Ms();Delay400Ms();Delay400Ms();Delay400Ms();
Delay400Ms();Delay400Ms();Delay400Ms();Delay400Ms();
}
else
{
putchar(DataSeclete[0]);//发功能号
DispOver();
Delay400Ms();Delay400Ms();Delay400Ms();Delay400Ms();
}
LiuCheng1 = 1;
LiuCheng1_1 = 1;
LiuCheng2Enable = 1;
LiuCheng3Enable = 1;
DispWelcome();
}
}
}
//查询流程
if((LiuCheng2 == 1)&&(LiuCheng2Enable == 1))
{
if(KEYB == 0)//按了“上翻/查询”键
{
LiuCheng2 = 0;
LiuCheng1Enable = 0;
LiuCheng3Enable = 0;
DispSearch();
putchar(0xaa);//发开始码
putchar(DataBase[0]);//发密码
temp = getchar(); //接收密码回馈
if(temp == Retry)//判断密码
{
DispPasswordError();
Delay400Ms();Delay400Ms();Delay400Ms();Delay400Ms();
Delay400Ms();Delay400Ms();Delay400Ms();Delay400Ms();
Delay400Ms();Delay400Ms();Delay400Ms();Delay400Ms();
Delay400Ms();Delay400Ms();Delay400Ms();Delay400Ms();
Delay400Ms();Delay400Ms();Delay400Ms();Delay400Ms();
}
else
{
putchar(DataSeclete[1]);//发功能号
GetAll(DataReceive);//接收查询结果
DispFindNow(GetShiwei(DataReceive[3]),GetGewei(DataReceive[3]),GetShiwei(DataReceive[2]),GetGewei(DataReceive[2]),DataReceive[0],DataReceive[1]);//显示查询结果
Delay400Ms();Delay400Ms();Delay400Ms();Delay400Ms();
Delay400Ms();Delay400Ms();Delay400Ms();Delay400Ms();
Delay400Ms();Delay400Ms();Delay400Ms();Delay400Ms();
Delay400Ms();Delay400Ms();Delay400Ms();Delay400Ms();
Delay400Ms();Delay400Ms();Delay400Ms();Delay400Ms();
}
LiuCheng2 = 1;
LiuCheng1Enable = 1;
LiuCheng3Enable = 1;
DispWelcome();
}
}
//工作流程
if((LiuCheng3 == 1)&&(LiuCheng3Enable == 1))
{
if(LiuCheng3_1 == 1)
{
if(KEYD == 0)//按了“确定/下一步”键
{
LiuCheng3 = 0;
LiuCheng3_1 = 0;
LiuCheng1Enable = 0;
LiuCheng2Enable = 0;
DispSetTime(GetShiwei(DataBase[3]),GetGewei(DataBase[3]),GetShiwei(DataBase[2]),GetGewei(DataBase[2]),LiuCheng3_1_Sign);
Delay400Ms();Delay400Ms();
}
}
}
else
{
//第一个子目录 设置时间
if(LiuCheng3_1 == 0)
{
LiuCheng1Enable = 0;
LiuCheng2Enable = 0;
LiuCheng3_1_HH = GetShiwei(DataBase[3]);//小时十位
LiuCheng3_1_HL = GetGewei(DataBase[3]);//小时个位
LiuCheng3_1_LH = GetShiwei(DataBase[2]);//分钟十位
LiuCheng3_1_LL = GetGewei(DataBase[2]);//分钟个位
if(KEYB == 0)//按了“上翻/查询”键
{
if(LiuCheng3_1_Sign == 1)
{
LiuCheng3_1_HH ++;
if(LiuCheng3_1_HH > 9)
{
LiuCheng3_1_HH -= 10;
}
}
else if(LiuCheng3_1_Sign == 2)
{
LiuCheng3_1_HL ++;
if(LiuCheng3_1_HL > 9)
{
LiuCheng3_1_HL -= 10;
}
}
else if(LiuCheng3_1_Sign == 3)
{
LiuCheng3_1_LH ++;
if(LiuCheng3_1_LH > 5)
{
LiuCheng3_1_LH -= 6;
}
}
else if(LiuCheng3_1_Sign == 4)
{
LiuCheng3_1_LL ++;
if(LiuCheng3_1_LL > 9)
{
LiuCheng3_1_LL -= 10;
}
}
DataBase[3] = LiuCheng3_1_HH*10+LiuCheng3_1_HL; //把结果统计进数组
DataBase[2] = LiuCheng3_1_LH*10+LiuCheng3_1_LL;
DispSetTime(LiuCheng3_1_HH,LiuCheng3_1_HL,LiuCheng3_1_LH,LiuCheng3_1_LL,LiuCheng3_1_Sign);
Delay400Ms();
}
if(KEYC == 0)//按了“左翻”键
{
LiuCheng3_1_Sign --;
if(LiuCheng3_1_Sign == 0)
{
LiuCheng3_1_Sign = 4;
}
DataBase[3] = LiuCheng3_1_HH*10+LiuCheng3_1_HL; //把结果统计进数组
DataBase[2] = LiuCheng3_1_LH*10+LiuCheng3_1_LL;
DispSetTime(LiuCheng3_1_HH,LiuCheng3_1_HL,LiuCheng3_1_LH,LiuCheng3_1_LL,LiuCheng3_1_Sign);
Delay400Ms();
}
if(KEYD == 0)//按了“确定/下一步”键
{
LiuCheng3_1 = 1;
LiuCheng3_2 = 0;
DispSetRevise(DataBase[4]-24);
Delay400Ms();Delay400Ms();
}
}
//第二个子目录 设置时间修正值
else if(LiuCheng3_2 == 0)
{
LiuCheng1Enable = 0;
LiuCheng2Enable = 0;
LiuCheng3_2_Num = DataBase[4]-24;
if(KEYB == 0)//按了“上翻/查询”键
{
LiuCheng3_2_Num ++;
if(LiuCheng3_2_Num > 9)
{
LiuCheng3_2_Num -= 10;
}
DataBase[4] = LiuCheng3_2_Num + 24; //把结果统计进数组
DispSetRevise(LiuCheng3_2_Num);
Delay400Ms();
}
if(KEYD == 0)//按了“确定/下一步”键
{
LiuCheng3_2 = 1;
LiuCheng3_3 = 0;
//读取下一个
if(DataBase[5] < 0x80)//为负时
{
LiuCheng3_3_Sign = 0;
LiuCheng3_3_HH = 0;
LiuCheng3_3_HL = GetGewei(DataBase[5]);
}
else//为正时
{
LiuCheng3_3_Sign = 1;
LiuCheng3_3_HH = GetShiwei(DataBase[5] - 0x80);
LiuCheng3_3_HL = GetGewei(DataBase[5] - 0x80);
}
//显示下一个
DispTemUp(LiuCheng3_3_HH,LiuCheng3_3_HL,LiuCheng3_3_Sign,LiuCheng3_3_WeiZhi);
Delay400Ms();Delay400Ms();
}
}
//第三个子目录 设置温度上限
else if(LiuCheng3_3 == 0)
{
LiuCheng1Enable = 0;
LiuCheng2Enable = 0;
//判断按键
if(KEYB == 0)//按了“上翻/查询”键
{
//改变数值
if(LiuCheng3_3_WeiZhi == 1)
{
if(LiuCheng3_3_Sign == 1)//为正
{
LiuCheng3_3_Sign = 0;//变成负以后
LiuCheng3_3_HH = 0;
}
else//为负
{
LiuCheng3_3_Sign = 1;//变成正以后
}
}
else if(LiuCheng3_3_WeiZhi == 2)
{
if(LiuCheng3_3_Sign == 1)//符号为正时,取模的最大值为9
{
LiuCheng3_3_HH ++;
if(LiuCheng3_3_HH > 9)
{
LiuCheng3_3_HH -= 10;
}
}
else if(LiuCheng3_3_Sign == 0)//符号为负时,取模的最大值为1
{
LiuCheng3_3_Sign = 0;
}
}
else if(LiuCheng3_3_WeiZhi == 3)
{
LiuCheng3_3_HL ++;
if(LiuCheng3_3_HL > 9)
{
LiuCheng3_3_HL -= 10;
}
}
//保存
if(LiuCheng3_3_Sign == 0)
{
DataBase[5] = LiuCheng3_3_HH*10+LiuCheng3_3_HL; //把结果统计进数组
if(DataBase[5] == 0x00)
{
DataBase[5] = 0x80;
}
}
else if(LiuCheng3_3_Sign == 1)
{
DataBase[5] = LiuCheng3_3_HH*10+LiuCheng3_3_HL+0x80; //把结果统计进数组
}
//显示
DispTemUp(LiuCheng3_3_HH,LiuCheng3_3_HL,LiuCheng3_3_Sign,LiuCheng3_3_WeiZhi);
Delay400Ms();
}
if(KEYC == 0)//按了“左翻”键
{
//移动焦点
LiuCheng3_3_WeiZhi --;
if(LiuCheng3_3_WeiZhi == 0)
{
LiuCheng3_3_WeiZhi = 3;
}
//保存
if(LiuCheng3_3_Sign == 0)
{
DataBase[5] = LiuCheng3_3_HH*10+LiuCheng3_3_HL; //把结果统计进数组
if(DataBase[5] == 0x00)
{
DataBase[5] = 0x80;
}
}
else if(LiuCheng3_3_Sign == 1)
{
DataBase[5] = LiuCheng3_3_HH*10+LiuCheng3_3_HL+0x80; //把结果统计进数组
}
//显示
DispTemUp(LiuCheng3_3_HH,LiuCheng3_3_HL,LiuCheng3_3_Sign,LiuCheng3_3_WeiZhi);
Delay400Ms();
}
if(KEYD == 0)//按了“确定/下一步”键
{
LiuCheng3_3 = 1;
LiuCheng3_4 = 0;
//显示下一个
if(DataBase[6] < 0x80)//为负时
{
LiuCheng3_4_Sign = 0;
LiuCheng3_4_HH = 0;
LiuCheng3_4_HL = GetGewei(DataBase[6]);
}
else//为正时
{
LiuCheng3_4_Sign = 1;
LiuCheng3_4_HH = GetShiwei(DataBase[6] - 0x80);
LiuCheng3_4_HL = GetGewei(DataBase[6] - 0x80);
}
DispTemDown(LiuCheng3_4_HH,LiuCheng3_4_HL,LiuCheng3_4_Sign,LiuCheng3_4_WeiZhi);
Delay400Ms();Delay400Ms();
//DataBase[2]分钟,[3]小时,[4]时间修正,[5]温度上限,[6]温度下限,[7]震动灵敏度
}
}
//第四个子目录 设置温度下限
else if(LiuCheng3_4 == 0)
{
LiuCheng1Enable = 0;
LiuCheng2Enable = 0;
//判断按键
if(KEYB == 0)//按了“上翻/查询”键
{
//改变数值
if(LiuCheng3_4_WeiZhi == 1)
{
if(LiuCheng3_4_Sign == 1)//为正
{
LiuCheng3_4_Sign = 0;//变成负以后
LiuCheng3_4_HH = 0;
}
else//为负
{
LiuCheng3_4_Sign = 1;//变成正以后
}
}
else if(LiuCheng3_4_WeiZhi == 2)
{
if(LiuCheng3_4_Sign == 1)//符号为正时,取模的最大值为9
{
LiuCheng3_4_HH ++;
if(LiuCheng3_4_HH > 9)
{
LiuCheng3_4_HH -= 10;
}
}
else if(LiuCheng3_4_Sign == 0)//符号为负时,取模的最大值为1
{
LiuCheng3_4_Sign = 0;
}
}
else if(LiuCheng3_4_WeiZhi == 3)
{
LiuCheng3_4_HL ++;
if(LiuCheng3_4_HL > 9)
{
LiuCheng3_4_HL -= 10;
}
}
//保存
if(LiuCheng3_4_Sign == 0)
{
DataBase[6] = LiuCheng3_4_HH*10+LiuCheng3_4_HL; //把结果统计进数组
if(DataBase[6] == 0x00)
{
DataBase[6] = 0x80;
}
}
else if(LiuCheng3_4_Sign == 1)
{
DataBase[6] = LiuCheng3_4_HH*10+LiuCheng3_4_HL+0x80; //把结果统计进数组
}
//显示
DispTemDown(LiuCheng3_4_HH,LiuCheng3_4_HL,LiuCheng3_4_Sign,LiuCheng3_4_WeiZhi);
Delay400Ms();
}
if(KEYC == 0)//按了“左翻”键
{
//移动焦点
LiuCheng3_4_WeiZhi --;
if(LiuCheng3_4_WeiZhi == 0)
{
LiuCheng3_4_WeiZhi = 3;
}
//保存
if(LiuCheng3_4_Sign == 0)
{
DataBase[6] = LiuCheng3_4_HH*10+LiuCheng3_4_HL; //把结果统计进数组
if(DataBase[6] == 0x00)
{
DataBase[6] = 0x80;
}
}
else if(LiuCheng3_4_Sign == 1)
{
DataBase[6] = LiuCheng3_4_HH*10+LiuCheng3_4_HL+0x80; //把结果统计进数组
}
//显示
DispTemDown(LiuCheng3_4_HH,LiuCheng3_4_HL,LiuCheng3_4_Sign,LiuCheng3_4_WeiZhi);
Delay400Ms();
}
if(KEYD == 0)//按了“确定/下一步”键
{
LiuCheng3_4 = 1;
LiuCheng3_5 = 0;
//显示下一个
LiuCheng3_5_Num = (DataBase[7]-2)/2;
DispShake(LiuCheng3_5_Num);//震动灵敏度,输入数值0 ~ 9 。灵敏度是25毫秒内震动的次数2-20,设置时对应为0~9,设置值*2+2=灵敏度
Delay400Ms();Delay400Ms();
}
}
//第五个子目录 设置时间修正值
else if(LiuCheng3_5 == 0)
{
LiuCheng1Enable = 0;
LiuCheng2Enable = 0;
if(KEYB == 0)//按了“上翻/查询”键
{
LiuCheng3_5_Num ++;
if(LiuCheng3_5_Num > 9)
{
LiuCheng3_5_Num -= 10;
}
DataBase[7] = LiuCheng3_5_Num * 2 + 2; //把结果统计进数组
DispShake(LiuCheng3_5_Num);
Delay400Ms();
}
if(KEYD == 0)//按了“确定/下一步”键
{
LiuCheng3_5 = 1;
LiuCheng3_6 = 0;
//读取下一个
CalculatePassword(LiuCheng3_password,DataBase[0]);
//显示
DispSetAddress(LiuCheng3_password,LiuCheng3_6_Sign);
DispPassWord(5,6,7,1,DataBase[0]);//输入显示的x1,x2,x3,y,数值(5.6.7.1.DataBase[0])
Delay400Ms();Delay400Ms();
}
}
//第六个子目录 设置密码
else if(LiuCheng3_6 == 0)
{
LiuCheng1Enable = 0;
LiuCheng2Enable = 0;
if(KEYB == 0)//按了“上翻/查询”键
{
//上翻
LiuCheng3_password[LiuCheng3_6_Sign -1] ++;
if(LiuCheng3_password[LiuCheng3_6_Sign-1] > 1)
{
LiuCheng3_password[LiuCheng3_6_Sign-1] -= 2;
}
//保存
ReCalculatePassword(LiuCheng3_password);//把结果统计进数组
DispSetAddress(LiuCheng3_password,LiuCheng3_6_Sign);
DispPassWord(5,6,7,1,DataBase[0]);//输入显示的x1,x2,x3,y,数值(5.6.7.1.DataBase[0])
Delay400Ms();
}
if(KEYC == 0)//按了“左翻”键
{
//左翻
LiuCheng3_6_Sign --;
if(LiuCheng3_6_Sign == 0)
{
LiuCheng3_6_Sign = 8;
}
//保存
ReCalculatePassword(LiuCheng3_password);//把结果统计进数组
DispSetAddress(LiuCheng3_password,LiuCheng3_6_Sign);
DispPassWord(5,6,7,1,DataBase[0]);//输入显示的x1,x2,x3,y,数值(5.6.7.1.DataBase[0])
Delay400Ms();
}
if(KEYD == 0)//按了“确定/下一步”键
{
DispConnect();
putchar(0xaa);//发开始码
putchar(DataBase[0]);//发密码
temp = getchar();//接收密码回馈
if(temp == Retry)//判断密码
{
DispPasswordError();
Delay400Ms();Delay400Ms();Delay400Ms();Delay400Ms();
Delay400Ms();Delay400Ms();Delay400Ms();Delay400Ms();
Delay400Ms();Delay400Ms();Delay400Ms();Delay400Ms();
Delay400Ms();Delay400Ms();Delay400Ms();Delay400Ms();
Delay400Ms();Delay400Ms();Delay400Ms();Delay400Ms();
}
else
{
putchar(DataSeclete[2]);//发功能号
PutAll(DataBase);//从串口发送一个8位数组(第一个为密码)
DispOver();
Delay400Ms();Delay400Ms();Delay400Ms();Delay400Ms();
}
LiuCheng3 = 1;
LiuCheng3_6 = 1;
LiuCheng1Enable = 1;
LiuCheng2Enable = 1;
DispWelcome();
}
}
}
KEYA = 1;//释放按键
KEYB = 1;
KEYC = 1;
KEYD = 1;
EA = 1;
}
///////////////////////////////////////////////////////////////////////////////////////////////////硬件初始化和主函数
void UART_INIT(void)//串口初始化,不要中断
{
TMOD = 0x20;
TL1 = 0x00; //300拨特率
TH1 = 0x00;
TR1 = 1;
SCON = 0x50; //方式1,允许接收
PCON = 0x00;
}
void main(void)
{
Delay400Ms(); //等待lcm进入工作状态
LcdReset(); //工作初始化
UART_INIT();
EX0 = 1; //允许外部中断
P0 = 0xff;
P1 = 0xff;
P2 = 0xff;
P3 = 0xff;
EA = 1;
DispWelcome();
while(1);
}
加载中...
查看其它39个回答
一周热门
更多
>
相关问题
【东软载波ESF0654 PDS开发板活动】开箱
1 个回答
东软载波ESF0654 PDS开发板外部中断
1 个回答
东软载波ESF0654 PDS开发板高级控制定时器AD16C4T
1 个回答
用串口调试助手为什么只能在hex模式接收发送而在文本模式不行
9 个回答
触摸芯片SC02B/SC04B在地砖灯的设计方案
1 个回答
相关文章
51单片机与蓝牙模块连接
0个评论
51单片机的硬件结构
0个评论
基于51单片机的无线遥控器制作
0个评论
51单片机 AD转换
0个评论
51单片机数码管递增显示
0个评论
如何实现对单片机寄存器的访问
0个评论
基于51单片机的指纹密码锁
0个评论
×
关闭
采纳回答
向帮助了您的知道网友说句感谢的话吧!
非常感谢!
确 认
×
关闭
编辑标签
最多设置5个标签!
51单片机
保存
关闭
×
关闭
举报内容
检举类型
检举内容
检举用户
检举原因
广告推广
恶意灌水
回答内容与提问无关
抄袭答案
其他
检举说明(必填)
提交
关闭
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
×
付费偷看金额在0.1-10元之间
确定
×
关闭
您已邀请
0
人回答
查看邀请
擅长该话题的人
回答过该话题的人
我关注的人
主文件:
#include<at89x52.h>
#include<absacc.h>
#include<memory.h>
#include<lcm.h>
#define Retry 0x80
unsigned char table[]={'0','1','2','3','4','5','6','7','8','9'};
unsigned char code DataSeclete[]={ //在发送数据前先发此,用来选择模式的代号
0x81, //0 停止用的包头代号
0x82, //1 查询用的包头代号
0x83 //2 设置用的包头代号
};
unsigned char DataBase[]={ //向下设置的数值
0x46, //0 地址(密码)
0xff, //1 总开关(0x00为关,0xff为开)
0x00, //2 分钟
0x01, //3 小时(最大99)
0x1a, //4 时间修正值(修正值是计数器溢出次数24-33,默认值是29,分10个档,设置时对应为0~9,设置值+24=修正值)
0xB2, //5 温度上限,默认是50度(最高位为正负号,1为正,0为负,后面7位为温度值,范围为-9~+99)
0x80, //6 温度下限,默认是0度(最高位为正负号,1为正,0为负,后面7位为温度值,范围为-9~+99)
0x14, //7 震动灵敏度(灵敏度是25毫秒内震动的次数2-20,设置时对应为0~9,设置值*2+2=灵敏度)
};
unsigned char DataReceive[]={ //向上读取的数值,把地址改为是否已经报警
0x00, //0 是否已经报警(1不报警,0报警)
0x00, //1 工作状态0x00为不工作,0xff为工作
0x00, //2 分钟
0x00, //3 小时(最大99)
};
sbit KeyA=P1^0;
sbit KeyB=P1^1;
sbit KeyC=P1^2;
sbit KeyD=P1^3;
sbit HzOut=P3^3;
unsigned char KEYA = 1,//按键A被按下为0,未按为零,,下同
KEYB = 1,
KEYC = 1,
KEYD = 1;
unsigned char LiuCheng1 = 1, //停止流程,1未开始,0开始,下同
LiuCheng1_1 = 1,//工作子流程-设置对应的地址 DispSetAddress(unsigned char HH,HL,sign)//输入被控板的地址,输入数值,位置
LiuCheng1_password[8], //流程1的地址暂存数组
LiuCheng1_1_Sign = 8, //焦点位置
//LiuCheng1_password[0]地址8位
//LiuCheng1_password[1]地址7位
//LiuCheng1_password[2]地址6位
//LiuCheng1_password[3]地址5位
//LiuCheng1_password[4]地址4位
//LiuCheng1_password[5]地址3位
//LiuCheng1_password[6]地址2位
//LiuCheng1_password[7]地址1位
LiuCheng2 = 1, //查询流程
LiuCheng3 = 1, //工作流程
LiuCheng3_1 = 1,//工作子流程-设时间
LiuCheng3_1_HH, //小时十位
LiuCheng3_1_HL, //小时个位
LiuCheng3_1_LH, //小时十位
LiuCheng3_1_LL, //小时个位
LiuCheng3_1_Sign = 4, //焦点位置
LiuCheng3_2 = 1,//工作子流程-时间修正值
LiuCheng3_2_Num, //修正值
LiuCheng3_3 = 1,//工作子流程-温度上限
LiuCheng3_3_HH, //温度十位
LiuCheng3_3_HL, //温度个位
LiuCheng3_3_Sign, //温度正负号
LiuCheng3_3_WeiZhi = 3,//焦点位置
LiuCheng3_4 = 1,//工作子流程-温度下限
LiuCheng3_4_HH, //温度十位
LiuCheng3_4_HL, //温度个位
LiuCheng3_4_Sign, //温度正负号
LiuCheng3_4_WeiZhi = 3,//焦点位置
LiuCheng3_5 = 1,//工作子流程-震动灵敏度
LiuCheng3_5_Num = 0, //灵敏度
LiuCheng3_6 = 1,//工作子流程-设置对应的地址 DispSetAddress(unsigned char HH,HL,sign)//输入被控板的地址,输入数值,位置
LiuCheng3_password[8],//流程3的地址暂存数组
//LiuCheng3_password[0]地址8位
//LiuCheng3_password[1]地址7位
//LiuCheng3_password[2]地址6位
//LiuCheng3_password[3]地址5位
//LiuCheng3_password[4]地址4位
//LiuCheng3_password[5]地址3位
//LiuCheng3_password[6]地址2位
//LiuCheng3_password[7]地址1位
LiuCheng3_6_Sign = 8; //焦点位置
unsigned char LiuCheng1Enable = 1,//停止流程使能
LiuCheng2Enable = 1,//查询流程使能
LiuCheng3Enable = 1;//工作流程使能
////////////////////////////////////////////////////////////////////////////////////////////////////////////菜单显示函数
void DispPasswordError(void)
{
/****************
Password Wrong.
Please Retry!
****************/
printx(0,0,"Password Wrong. ");
printx(0,1,"Please Retry! ");
}
void DispSetTime(unsigned char HH,HL,LH,LL,weizhi)//设置时间,输入小时十位,小时个位,分钟十位,分钟个位,焦点相对位置
{
/****************
(hour:min) 00:00
set time: ^
****************/
printx(0,0,"(hour:min) : ");
DispOneChar(11,0,table[HH]);
DispOneChar(12,0,table[HL]);
DispOneChar(14,0,table[LH]);
DispOneChar(15,0,table[LL]);
if(weizhi == 1)
{
printx(0,1,"set time: ^ ");
}
if(weizhi == 2)
{
printx(0,1,"set time: ^ ");
}
if(weizhi == 3)
{
printx(0,1,"set time: ^ ");
}
if(weizhi == 4)
{
printx(0,1,"set time: ^");
}
}
void DispSetRevise(unsigned char num)//设置时间修正值,输入数值
{
/****************
( 0 - 9 ) 0
Xiu Zheng : ^
****************/
printx(0,0,"( 0 - 9 ) ");
printx(0,1,"Xiu Zheng : ^ ");
DispOneChar(14,0,table[num]);
}
void DispTemUp(unsigned char HH,HL,sign,weizhi)//设置温度上限十位,上限个位,输入符号(0为负,1为正),数值,位置
{
/****************
(-9 - +99) x00
Tem up : ^
****************/
printx(0,0,"(-9 - +99) ");
if(sign == 0)
{
DispOneChar(12,0,'-');
}
else
{
DispOneChar(12,0,'+');
}
DispOneChar(13,0,table[HH]);
DispOneChar(14,0,table[HL]);
if(weizhi == 1)
{
printx(0,1,"Tem up : ^ ");
}
if(weizhi == 2)
{
printx(0,1,"Tem up : ^ ");
}
if(weizhi == 3)
{
printx(0,1,"Tem up : ^ ");
}
}
void DispTemDown(unsigned char HH,HL,sign,weizhi)//设置温度下限十位,上限个位,输入符号(0为负,1为正),数值,位置
{
/****************
(-9 - +99) x00
Tem down: ^
****************/
printx(0,0,"(-9 - +99) ");
if(sign == 0)
{
DispOneChar(12,0,'-');
}
else
{
DispOneChar(12,0,'+');
}
DispOneChar(13,0,table[HH]);
DispOneChar(14,0,table[HL]);
if(weizhi == 1)
{
printx(0,1,"Tem down: ^ ");
}
if(weizhi == 2)
{
printx(0,1,"Tem down: ^ ");
}
if(weizhi == 3)
{
printx(0,1,"Tem down: ^ ");
}
}
void DispShake(unsigned char num)//震动灵敏度,输入数值0 ~ 9
{
/****************
( 0 - 9 ) 0
Shake: ^
****************/
printx(0,0,"( 0 - 9 ) ");
printx(0,1,"Shake: ^ ");
DispOneChar(13,0,table[num]);
}
void DispConnect(void)//正在传输中
{
/****************
Now Connecting..
Please Wait.....
****************/
printx(0,0,"Now Connecting..");
printx(0,1,"Please Wait.....");
}
void DispOver(void)//传输完毕
{
/****************
Deliver is over.
Please Wait.....
****************/
printx(0,0,"Deliver is over.");
printx(0,1,"Please Wait.....");
}
void DispStoping(void)//停止中
{
/****************
Now Stoping.....
Please Wait.....
****************/
printx(0,0,"Now Stoping.....");
printx(0,1,"Please Wait.....");
}
void DispSearch(void)//查看功能板的状态
{
/****************
Now Searching...
Please Wait.....
****************/
printx(0,0,"Now Searching...");
printx(0,1,"Please Wait.....");
}
void DispFindNow(unsigned char HH,HL,LH,LL,num,sign)//功能板的状态显示,输入小时十位,小时个位,分钟十位,分钟个位,报警状态,工作状态(1工作,0不工作)
{
/****************
ALARM time:00:00
working? YES/NO
****************/
printx(0,0," time: : ");
DispOneChar(11,0,table[HH]);
DispOneChar(12,0,table[HL]);
DispOneChar(14,0,table[LH]);
DispOneChar(15,0,table[LL]);
if(num == 0)//1不报警,0报警
{
DispOneChar(0,0,'A');
DispOneChar(1,0,'L');
DispOneChar(2,0,'A');
DispOneChar(3,0,'R');
DispOneChar(4,0,'M');
}
else
{
DispOneChar(0,0,'S');
DispOneChar(1,0,'A');
DispOneChar(2,0,'F');
DispOneChar(3,0,'T');
DispOneChar(4,0,'Y');
}
if(sign == 0xff)
{
printx(0,1,"working? YES ");
}
else
{
printx(0,1,"working? NO ");
}
}
void DispWelcome(void)//显示开机画面
{
/****************
System Work Now!
Designed By LYQ!
****************/
printx(0,0,"System Work Now!");
printx(0,1,"Designed By LYQ!");
}
void DispSetAddress(unsigned char *arrays,unsigned char sign)//输入被控板的地址,输入位置
{
/****************
Pass 00000000
word: ^
****************/
printx(0,0,"Pass ");
DispOneChar(8,0,table[arrays[0]]);
DispOneChar(9,0,table[arrays[1]]);
DispOneChar(10,0,table[arrays[2]]);
DispOneChar(11,0,table[arrays[3]]);
DispOneChar(12,0,table[arrays[4]]);
DispOneChar(13,0,table[arrays[5]]);
DispOneChar(14,0,table[arrays[6]]);
DispOneChar(15,0,table[arrays[7]]);
switch(sign)
{
case 1:
printx(0,1,"word: ^ ");
break;
case 2:
printx(0,1,"word: ^ ");
break;
case 3:
printx(0,1,"word: ^ ");
break;
case 4:
printx(0,1,"word: ^ ");
break;
case 5:
printx(0,1,"word: ^ ");
break;
case 6:
printx(0,1,"word: ^ ");
break;
case 7:
printx(0,1,"word: ^ ");
break;
case 8:
printx(0,1,"word: ^");
break;
default:
break;
}
}
unsigned char GetBaiwei(unsigned char temp)//从整数中取百位数
{
temp = temp/100;
return temp;
}
unsigned char GetShiwei(unsigned char temp)//从整数中取十位数
{
if(temp > 99)
{
temp = temp - GetBaiwei(temp)*100;
}
temp = temp/10;
return temp;
}
unsigned char GetGewei(unsigned char temp)//从整数中取个位数
{
temp = temp%10;
return temp;
}
void DispPassWord(unsigned char x1,x2,x3,y,num)//输入显示的x1,x2,x3,y,数值(5.6.7.1.DataBase[0])
{
DispOneChar(x1,y,table[GetBaiwei(num)]);
DispOneChar(x2,y,table[GetShiwei(num)]);
DispOneChar(x3,y,table[GetGewei(num)]);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////其他功能函数
void putchar(unsigned char a)//从串口发送一个字节
{
TI=0;
SBUF=a;
while(!TI);
TI=0;
}
unsigned char getchar(void)//从串口接收一个字节
{
unsigned char a;
RI = 0;
while(RI == 0);
a = SBUF;
RI = 0;
return a;
}
void PutAll(unsigned char * arrays)//从串口发送一个8数据数组
{
unsigned char i;
for(i=0;i<8;i++)//发8数据数组
{
putchar(arrays);
}
}
void GetAll(unsigned char * arrays)//从串口接收一个4数据数组,参数是待接收的数组名,DataReceive[]或DataSbuffer[]
{
unsigned char i;
for(i=0;i<4;i++)//收4数据数组
{
arrays = getchar();
}
}
void CalculatePassword(unsigned char * arrays,unsigned char ADDR)//把数组计算成设置
{
unsigned char temp,i;
temp = ADDR;
for(i=0;i<8;i++)
{
temp = ADDR<<i;
arrays = temp>>7;
}
}
void ReCalculatePassword(unsigned char * arrays)//把设置还原成数组
{
DataBase[0] = arrays[0]*128+arrays[1]*64+arrays[2]*32+arrays[3]*16+arrays[4]*8+arrays[5]*4+arrays[6]*2+arrays[7];
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////中断函数
void Key(void) interrupt 0
{
unsigned char temp;
EA = 0;
Delay5Ms();
Delay5Ms();
/*读取按键*/
if(KeyA == 0)
{
KEYA = 0;
}
if(KeyB == 0)
{
KEYB = 0;
}
if(KeyC == 0)
{
KEYC = 0;
}
if(KeyD == 0)
{
KEYD = 0;
}
/*菜单判断*/
//停止流程
if((LiuCheng1 == 1)&&(LiuCheng1Enable == 1))
{
if(KEYA == 0)//按了“停止/返回”键
{
LiuCheng1 = 0;
LiuCheng1_1 = 0;
LiuCheng2Enable = 0;
LiuCheng3Enable = 0;
//读取下一个
CalculatePassword(LiuCheng1_password,DataBase[0]);
//显示
DispSetAddress(LiuCheng1_password,LiuCheng1_1_Sign);
DispPassWord(5,6,7,1,DataBase[0]);//输入显示的x1,x2,x3,y,数值(5.6.7.1.DataBase[0])
Delay400Ms();Delay400Ms();
}
}
else
{
if(LiuCheng1_1 == 0)
{
LiuCheng2Enable = 0;
LiuCheng3Enable = 0;
if(KEYB == 0)//按了“上翻/查询”键
{
//上翻
LiuCheng1_password[LiuCheng1_1_Sign -1] ++;
if(LiuCheng1_password[LiuCheng1_1_Sign-1] > 1)
{
LiuCheng1_password[LiuCheng1_1_Sign-1] -= 2;
}
//保存
ReCalculatePassword(LiuCheng1_password);//把结果统计进数组
DispSetAddress(LiuCheng1_password,LiuCheng1_1_Sign);
DispPassWord(5,6,7,1,DataBase[0]);//输入显示的x1,x2,x3,y,数值(5.6.7.1.DataBase[0])
Delay400Ms();
}
if(KEYC == 0)//按了“左翻”键
{
//左翻
LiuCheng1_1_Sign --;
if(LiuCheng1_1_Sign == 0)
{
LiuCheng1_1_Sign = 8;
}
//保存
ReCalculatePassword(LiuCheng1_password);//把结果统计进数组
DispSetAddress(LiuCheng1_password,LiuCheng1_1_Sign);
DispPassWord(5,6,7,1,DataBase[0]);//输入显示的x1,x2,x3,y,数值(5.6.7.1.DataBase[0])
Delay400Ms();
}
if(KEYA == 0)//按了“停止/返回”键
{
DispStoping(); //做下一个的显示
putchar(0xaa);//发开始码
putchar(DataBase[0]);//发密码
temp = getchar();//接收密码回馈
if(temp == Retry)//判断密码
{
DispPasswordError();
Delay400Ms();Delay400Ms();Delay400Ms();Delay400Ms();
Delay400Ms();Delay400Ms();Delay400Ms();Delay400Ms();
Delay400Ms();Delay400Ms();Delay400Ms();Delay400Ms();
Delay400Ms();Delay400Ms();Delay400Ms();Delay400Ms();
Delay400Ms();Delay400Ms();Delay400Ms();Delay400Ms();
}
else
{
putchar(DataSeclete[0]);//发功能号
DispOver();
Delay400Ms();Delay400Ms();Delay400Ms();Delay400Ms();
}
LiuCheng1 = 1;
LiuCheng1_1 = 1;
LiuCheng2Enable = 1;
LiuCheng3Enable = 1;
DispWelcome();
}
}
}
//查询流程
if((LiuCheng2 == 1)&&(LiuCheng2Enable == 1))
{
if(KEYB == 0)//按了“上翻/查询”键
{
LiuCheng2 = 0;
LiuCheng1Enable = 0;
LiuCheng3Enable = 0;
DispSearch();
putchar(0xaa);//发开始码
putchar(DataBase[0]);//发密码
temp = getchar(); //接收密码回馈
if(temp == Retry)//判断密码
{
DispPasswordError();
Delay400Ms();Delay400Ms();Delay400Ms();Delay400Ms();
Delay400Ms();Delay400Ms();Delay400Ms();Delay400Ms();
Delay400Ms();Delay400Ms();Delay400Ms();Delay400Ms();
Delay400Ms();Delay400Ms();Delay400Ms();Delay400Ms();
Delay400Ms();Delay400Ms();Delay400Ms();Delay400Ms();
}
else
{
putchar(DataSeclete[1]);//发功能号
GetAll(DataReceive);//接收查询结果
DispFindNow(GetShiwei(DataReceive[3]),GetGewei(DataReceive[3]),GetShiwei(DataReceive[2]),GetGewei(DataReceive[2]),DataReceive[0],DataReceive[1]);//显示查询结果
Delay400Ms();Delay400Ms();Delay400Ms();Delay400Ms();
Delay400Ms();Delay400Ms();Delay400Ms();Delay400Ms();
Delay400Ms();Delay400Ms();Delay400Ms();Delay400Ms();
Delay400Ms();Delay400Ms();Delay400Ms();Delay400Ms();
Delay400Ms();Delay400Ms();Delay400Ms();Delay400Ms();
}
LiuCheng2 = 1;
LiuCheng1Enable = 1;
LiuCheng3Enable = 1;
DispWelcome();
}
}
//工作流程
if((LiuCheng3 == 1)&&(LiuCheng3Enable == 1))
{
if(LiuCheng3_1 == 1)
{
if(KEYD == 0)//按了“确定/下一步”键
{
LiuCheng3 = 0;
LiuCheng3_1 = 0;
LiuCheng1Enable = 0;
LiuCheng2Enable = 0;
DispSetTime(GetShiwei(DataBase[3]),GetGewei(DataBase[3]),GetShiwei(DataBase[2]),GetGewei(DataBase[2]),LiuCheng3_1_Sign);
Delay400Ms();Delay400Ms();
}
}
}
else
{
//第一个子目录 设置时间
if(LiuCheng3_1 == 0)
{
LiuCheng1Enable = 0;
LiuCheng2Enable = 0;
LiuCheng3_1_HH = GetShiwei(DataBase[3]);//小时十位
LiuCheng3_1_HL = GetGewei(DataBase[3]);//小时个位
LiuCheng3_1_LH = GetShiwei(DataBase[2]);//分钟十位
LiuCheng3_1_LL = GetGewei(DataBase[2]);//分钟个位
if(KEYB == 0)//按了“上翻/查询”键
{
if(LiuCheng3_1_Sign == 1)
{
LiuCheng3_1_HH ++;
if(LiuCheng3_1_HH > 9)
{
LiuCheng3_1_HH -= 10;
}
}
else if(LiuCheng3_1_Sign == 2)
{
LiuCheng3_1_HL ++;
if(LiuCheng3_1_HL > 9)
{
LiuCheng3_1_HL -= 10;
}
}
else if(LiuCheng3_1_Sign == 3)
{
LiuCheng3_1_LH ++;
if(LiuCheng3_1_LH > 5)
{
LiuCheng3_1_LH -= 6;
}
}
else if(LiuCheng3_1_Sign == 4)
{
LiuCheng3_1_LL ++;
if(LiuCheng3_1_LL > 9)
{
LiuCheng3_1_LL -= 10;
}
}
DataBase[3] = LiuCheng3_1_HH*10+LiuCheng3_1_HL; //把结果统计进数组
DataBase[2] = LiuCheng3_1_LH*10+LiuCheng3_1_LL;
DispSetTime(LiuCheng3_1_HH,LiuCheng3_1_HL,LiuCheng3_1_LH,LiuCheng3_1_LL,LiuCheng3_1_Sign);
Delay400Ms();
}
if(KEYC == 0)//按了“左翻”键
{
LiuCheng3_1_Sign --;
if(LiuCheng3_1_Sign == 0)
{
LiuCheng3_1_Sign = 4;
}
DataBase[3] = LiuCheng3_1_HH*10+LiuCheng3_1_HL; //把结果统计进数组
DataBase[2] = LiuCheng3_1_LH*10+LiuCheng3_1_LL;
DispSetTime(LiuCheng3_1_HH,LiuCheng3_1_HL,LiuCheng3_1_LH,LiuCheng3_1_LL,LiuCheng3_1_Sign);
Delay400Ms();
}
if(KEYD == 0)//按了“确定/下一步”键
{
LiuCheng3_1 = 1;
LiuCheng3_2 = 0;
DispSetRevise(DataBase[4]-24);
Delay400Ms();Delay400Ms();
}
}
//第二个子目录 设置时间修正值
else if(LiuCheng3_2 == 0)
{
LiuCheng1Enable = 0;
LiuCheng2Enable = 0;
LiuCheng3_2_Num = DataBase[4]-24;
if(KEYB == 0)//按了“上翻/查询”键
{
LiuCheng3_2_Num ++;
if(LiuCheng3_2_Num > 9)
{
LiuCheng3_2_Num -= 10;
}
DataBase[4] = LiuCheng3_2_Num + 24; //把结果统计进数组
DispSetRevise(LiuCheng3_2_Num);
Delay400Ms();
}
if(KEYD == 0)//按了“确定/下一步”键
{
LiuCheng3_2 = 1;
LiuCheng3_3 = 0;
//读取下一个
if(DataBase[5] < 0x80)//为负时
{
LiuCheng3_3_Sign = 0;
LiuCheng3_3_HH = 0;
LiuCheng3_3_HL = GetGewei(DataBase[5]);
}
else//为正时
{
LiuCheng3_3_Sign = 1;
LiuCheng3_3_HH = GetShiwei(DataBase[5] - 0x80);
LiuCheng3_3_HL = GetGewei(DataBase[5] - 0x80);
}
//显示下一个
DispTemUp(LiuCheng3_3_HH,LiuCheng3_3_HL,LiuCheng3_3_Sign,LiuCheng3_3_WeiZhi);
Delay400Ms();Delay400Ms();
}
}
//第三个子目录 设置温度上限
else if(LiuCheng3_3 == 0)
{
LiuCheng1Enable = 0;
LiuCheng2Enable = 0;
//判断按键
if(KEYB == 0)//按了“上翻/查询”键
{
//改变数值
if(LiuCheng3_3_WeiZhi == 1)
{
if(LiuCheng3_3_Sign == 1)//为正
{
LiuCheng3_3_Sign = 0;//变成负以后
LiuCheng3_3_HH = 0;
}
else//为负
{
LiuCheng3_3_Sign = 1;//变成正以后
}
}
else if(LiuCheng3_3_WeiZhi == 2)
{
if(LiuCheng3_3_Sign == 1)//符号为正时,取模的最大值为9
{
LiuCheng3_3_HH ++;
if(LiuCheng3_3_HH > 9)
{
LiuCheng3_3_HH -= 10;
}
}
else if(LiuCheng3_3_Sign == 0)//符号为负时,取模的最大值为1
{
LiuCheng3_3_Sign = 0;
}
}
else if(LiuCheng3_3_WeiZhi == 3)
{
LiuCheng3_3_HL ++;
if(LiuCheng3_3_HL > 9)
{
LiuCheng3_3_HL -= 10;
}
}
//保存
if(LiuCheng3_3_Sign == 0)
{
DataBase[5] = LiuCheng3_3_HH*10+LiuCheng3_3_HL; //把结果统计进数组
if(DataBase[5] == 0x00)
{
DataBase[5] = 0x80;
}
}
else if(LiuCheng3_3_Sign == 1)
{
DataBase[5] = LiuCheng3_3_HH*10+LiuCheng3_3_HL+0x80; //把结果统计进数组
}
//显示
DispTemUp(LiuCheng3_3_HH,LiuCheng3_3_HL,LiuCheng3_3_Sign,LiuCheng3_3_WeiZhi);
Delay400Ms();
}
if(KEYC == 0)//按了“左翻”键
{
//移动焦点
LiuCheng3_3_WeiZhi --;
if(LiuCheng3_3_WeiZhi == 0)
{
LiuCheng3_3_WeiZhi = 3;
}
//保存
if(LiuCheng3_3_Sign == 0)
{
DataBase[5] = LiuCheng3_3_HH*10+LiuCheng3_3_HL; //把结果统计进数组
if(DataBase[5] == 0x00)
{
DataBase[5] = 0x80;
}
}
else if(LiuCheng3_3_Sign == 1)
{
DataBase[5] = LiuCheng3_3_HH*10+LiuCheng3_3_HL+0x80; //把结果统计进数组
}
//显示
DispTemUp(LiuCheng3_3_HH,LiuCheng3_3_HL,LiuCheng3_3_Sign,LiuCheng3_3_WeiZhi);
Delay400Ms();
}
if(KEYD == 0)//按了“确定/下一步”键
{
LiuCheng3_3 = 1;
LiuCheng3_4 = 0;
//显示下一个
if(DataBase[6] < 0x80)//为负时
{
LiuCheng3_4_Sign = 0;
LiuCheng3_4_HH = 0;
LiuCheng3_4_HL = GetGewei(DataBase[6]);
}
else//为正时
{
LiuCheng3_4_Sign = 1;
LiuCheng3_4_HH = GetShiwei(DataBase[6] - 0x80);
LiuCheng3_4_HL = GetGewei(DataBase[6] - 0x80);
}
DispTemDown(LiuCheng3_4_HH,LiuCheng3_4_HL,LiuCheng3_4_Sign,LiuCheng3_4_WeiZhi);
Delay400Ms();Delay400Ms();
//DataBase[2]分钟,[3]小时,[4]时间修正,[5]温度上限,[6]温度下限,[7]震动灵敏度
}
}
//第四个子目录 设置温度下限
else if(LiuCheng3_4 == 0)
{
LiuCheng1Enable = 0;
LiuCheng2Enable = 0;
//判断按键
if(KEYB == 0)//按了“上翻/查询”键
{
//改变数值
if(LiuCheng3_4_WeiZhi == 1)
{
if(LiuCheng3_4_Sign == 1)//为正
{
LiuCheng3_4_Sign = 0;//变成负以后
LiuCheng3_4_HH = 0;
}
else//为负
{
LiuCheng3_4_Sign = 1;//变成正以后
}
}
else if(LiuCheng3_4_WeiZhi == 2)
{
if(LiuCheng3_4_Sign == 1)//符号为正时,取模的最大值为9
{
LiuCheng3_4_HH ++;
if(LiuCheng3_4_HH > 9)
{
LiuCheng3_4_HH -= 10;
}
}
else if(LiuCheng3_4_Sign == 0)//符号为负时,取模的最大值为1
{
LiuCheng3_4_Sign = 0;
}
}
else if(LiuCheng3_4_WeiZhi == 3)
{
LiuCheng3_4_HL ++;
if(LiuCheng3_4_HL > 9)
{
LiuCheng3_4_HL -= 10;
}
}
//保存
if(LiuCheng3_4_Sign == 0)
{
DataBase[6] = LiuCheng3_4_HH*10+LiuCheng3_4_HL; //把结果统计进数组
if(DataBase[6] == 0x00)
{
DataBase[6] = 0x80;
}
}
else if(LiuCheng3_4_Sign == 1)
{
DataBase[6] = LiuCheng3_4_HH*10+LiuCheng3_4_HL+0x80; //把结果统计进数组
}
//显示
DispTemDown(LiuCheng3_4_HH,LiuCheng3_4_HL,LiuCheng3_4_Sign,LiuCheng3_4_WeiZhi);
Delay400Ms();
}
if(KEYC == 0)//按了“左翻”键
{
//移动焦点
LiuCheng3_4_WeiZhi --;
if(LiuCheng3_4_WeiZhi == 0)
{
LiuCheng3_4_WeiZhi = 3;
}
//保存
if(LiuCheng3_4_Sign == 0)
{
DataBase[6] = LiuCheng3_4_HH*10+LiuCheng3_4_HL; //把结果统计进数组
if(DataBase[6] == 0x00)
{
DataBase[6] = 0x80;
}
}
else if(LiuCheng3_4_Sign == 1)
{
DataBase[6] = LiuCheng3_4_HH*10+LiuCheng3_4_HL+0x80; //把结果统计进数组
}
//显示
DispTemDown(LiuCheng3_4_HH,LiuCheng3_4_HL,LiuCheng3_4_Sign,LiuCheng3_4_WeiZhi);
Delay400Ms();
}
if(KEYD == 0)//按了“确定/下一步”键
{
LiuCheng3_4 = 1;
LiuCheng3_5 = 0;
//显示下一个
LiuCheng3_5_Num = (DataBase[7]-2)/2;
DispShake(LiuCheng3_5_Num);//震动灵敏度,输入数值0 ~ 9 。灵敏度是25毫秒内震动的次数2-20,设置时对应为0~9,设置值*2+2=灵敏度
Delay400Ms();Delay400Ms();
}
}
//第五个子目录 设置时间修正值
else if(LiuCheng3_5 == 0)
{
LiuCheng1Enable = 0;
LiuCheng2Enable = 0;
if(KEYB == 0)//按了“上翻/查询”键
{
LiuCheng3_5_Num ++;
if(LiuCheng3_5_Num > 9)
{
LiuCheng3_5_Num -= 10;
}
DataBase[7] = LiuCheng3_5_Num * 2 + 2; //把结果统计进数组
DispShake(LiuCheng3_5_Num);
Delay400Ms();
}
if(KEYD == 0)//按了“确定/下一步”键
{
LiuCheng3_5 = 1;
LiuCheng3_6 = 0;
//读取下一个
CalculatePassword(LiuCheng3_password,DataBase[0]);
//显示
DispSetAddress(LiuCheng3_password,LiuCheng3_6_Sign);
DispPassWord(5,6,7,1,DataBase[0]);//输入显示的x1,x2,x3,y,数值(5.6.7.1.DataBase[0])
Delay400Ms();Delay400Ms();
}
}
//第六个子目录 设置密码
else if(LiuCheng3_6 == 0)
{
LiuCheng1Enable = 0;
LiuCheng2Enable = 0;
if(KEYB == 0)//按了“上翻/查询”键
{
//上翻
LiuCheng3_password[LiuCheng3_6_Sign -1] ++;
if(LiuCheng3_password[LiuCheng3_6_Sign-1] > 1)
{
LiuCheng3_password[LiuCheng3_6_Sign-1] -= 2;
}
//保存
ReCalculatePassword(LiuCheng3_password);//把结果统计进数组
DispSetAddress(LiuCheng3_password,LiuCheng3_6_Sign);
DispPassWord(5,6,7,1,DataBase[0]);//输入显示的x1,x2,x3,y,数值(5.6.7.1.DataBase[0])
Delay400Ms();
}
if(KEYC == 0)//按了“左翻”键
{
//左翻
LiuCheng3_6_Sign --;
if(LiuCheng3_6_Sign == 0)
{
LiuCheng3_6_Sign = 8;
}
//保存
ReCalculatePassword(LiuCheng3_password);//把结果统计进数组
DispSetAddress(LiuCheng3_password,LiuCheng3_6_Sign);
DispPassWord(5,6,7,1,DataBase[0]);//输入显示的x1,x2,x3,y,数值(5.6.7.1.DataBase[0])
Delay400Ms();
}
if(KEYD == 0)//按了“确定/下一步”键
{
DispConnect();
putchar(0xaa);//发开始码
putchar(DataBase[0]);//发密码
temp = getchar();//接收密码回馈
if(temp == Retry)//判断密码
{
DispPasswordError();
Delay400Ms();Delay400Ms();Delay400Ms();Delay400Ms();
Delay400Ms();Delay400Ms();Delay400Ms();Delay400Ms();
Delay400Ms();Delay400Ms();Delay400Ms();Delay400Ms();
Delay400Ms();Delay400Ms();Delay400Ms();Delay400Ms();
Delay400Ms();Delay400Ms();Delay400Ms();Delay400Ms();
}
else
{
putchar(DataSeclete[2]);//发功能号
PutAll(DataBase);//从串口发送一个8位数组(第一个为密码)
DispOver();
Delay400Ms();Delay400Ms();Delay400Ms();Delay400Ms();
}
LiuCheng3 = 1;
LiuCheng3_6 = 1;
LiuCheng1Enable = 1;
LiuCheng2Enable = 1;
DispWelcome();
}
}
}
KEYA = 1;//释放按键
KEYB = 1;
KEYC = 1;
KEYD = 1;
EA = 1;
}
///////////////////////////////////////////////////////////////////////////////////////////////////硬件初始化和主函数
void UART_INIT(void)//串口初始化,不要中断
{
TMOD = 0x20;
TL1 = 0x00; //300拨特率
TH1 = 0x00;
TR1 = 1;
SCON = 0x50; //方式1,允许接收
PCON = 0x00;
}
void main(void)
{
Delay400Ms(); //等待lcm进入工作状态
LcdReset(); //工作初始化
UART_INIT();
EX0 = 1; //允许外部中断
P0 = 0xff;
P1 = 0xff;
P2 = 0xff;
P3 = 0xff;
EA = 1;
DispWelcome();
while(1);
}
一周热门 更多>