#include<reg51.h>
#include <absacc.h>
#include <intrins.h>
#include <stdio.h>
#define LCDCMD XBYTE[0x4000]
#define LCDDAT XBYTE[0x0000]
sbit P30=P3^0;
sbit P31=P3^1;
sbit P25=P2^4;
sbit P26=P2^5;
sbit P34=P3^4;
sbit P35=P3^5;
sbit KEY1=P1^0;
sbit KEY2=P1^1;
code char buf[]=
{
0x70,0x01,0x43,0x44, 0x41,0x42,0x43,0x44, 0x41,0x42,0x43,0x44, 0x41,0x42,0x43,0x44, 0x41,0x42,0x43,0x44, 0x41,0x42,0x43,0x44, 0x41,0x42,0x43,0x44, 0x41,0x42,0x43,0x44,
0
};
unsigned char f; // 防盗计数供中断判断
unsigned char e=1; //判断按键2是否按下
unsigned char c; //lcd用
unsigned char d; //烟雾报警计数
void keyscan();
void InitLCD();
void LCD();
void display(char *p);
void cmdlcd(char cmd);
void datlcd(char dat);
void passport();
void Delayms(unsigned ms)
{
while(ms)
{
unsigned char i;
for (i=0; i<125; i++);
ms--;
}
}
void INTTO() interrupt 1 //中断中判断警报的开启与解除
{
switch(f)
{
case 0:P34=1; //高电平关警报
break;
case 1:P34=0; //低电平开启警报
break;
case 2:P34=1; //case2定重复了,没改
break;
}
switch(d)
{
case 0:P35=1;
break;
case 1:P35=0;
break;
case 2:P35=1;
break;
}
}
void passport() //LCD显示主函数
{
InitLCD();
while(1)
{
unsigned char x;
LCD();
display(buf);
Delayms(100);
datlcd(x);
datlcd(0x01);
cmdlcd(0x21); //cursor pointer set
keyscan();
x++;
if (x>=16) x=0;
if (KEY1==0)
{
unsigned char x;
LCD();
display(buf);
Delayms(100);
datlcd(x);
datlcd(0x01);
cmdlcd(0x21); //cursor pointer set
cmdlcd(0x90); //display off
break; //跳出LCD部分后没有给f赋值?这里应该跳到passport调用处才对啊?
}
}
}
void datlcd(char dat) //LCD写数据
{
char c;
LCDDAT=dat;
do { c=LCDCMD; } while(c&0x03!=0x03);
}
void cmdlcd(char cmd) //LCD写命令
{
char c;
LCDCMD=cmd;
do { c=LCDCMD; } while(c&0x03!=0x03);
}
void display(char * p) //屏幕显示内容
{
unsigned char c;
datlcd(0x00);
datlcd(0x00);
cmdlcd(0x24); //Address pointer set
cmdlcd(0xb0); //Dataautowriteset
datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);
datlcd('I'); datlcd('N'); datlcd('P'); datlcd('U'); datlcd('T'); datlcd(0x00); datlcd('P'); datlcd('A'); datlcd('S'); datlcd('S'); datlcd('W'); datlcd('O'); datlcd('R'); datlcd('D'); datlcd(0x1A);
cmdlcd(0xb2); //autoreset
if (KEY1==0)
{
datlcd(0x00);
datlcd(0x00);
cmdlcd(0x24);
cmdlcd(0xb0);
datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);
datlcd('K');datlcd('E');datlcd('Y');datlcd(0x11);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);
datlcd('R'); datlcd('I'); datlcd('G'); datlcd('H'); datlcd('T'); datlcd(0x00); datlcd('P'); datlcd('A'); datlcd('S'); datlcd('S'); datlcd('W'); datlcd('O'); datlcd('R'); datlcd('D');
cmdlcd(0xb2);
}
if (e==0)
{
datlcd(0x00);
datlcd(0x00);
cmdlcd(0x24);
cmdlcd(0xb0);
datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);
datlcd('K');datlcd('E');datlcd('Y');datlcd(0x12);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);datlcd(0x00);
datlcd('E'); datlcd('R'); datlcd('R'); datlcd('O'); datlcd('R'); datlcd(0x00); datlcd('R'); datlcd('E'); datlcd('T'); datlcd('R'); datlcd('Y');datlcd(0x00);datlcd(0x00);datlcd(0x00);
cmdlcd(0xb2);
e=1;
keyscan();
}
}
void InitLCD() //初始化LCD
{
cmdlcd(0x93); //cursor on,blink on
cmdlcd(0xa7); //8lines cursor
cmdlcd(0x9f); //Text on,Graphic on
}
void LCD() //测试时用的,没有调用
{
/*
LCDCMD=0x93;
Delayms(100);
LCDCMD=0xA7;
Delayms(100);*/
}
void keyscan() //密码模拟,只用了两个键来模拟密码KEY1为正确
{
while(KEY1)
{
if (KEY2==0)
{e=0;break;}
}
if (e==1)KEY1=0;else KEY1=1;
}
void main()
{ TMOD=0x02; //工作方式
TL0=0xf0; //定时
TH0=0xf0;
TR0=1; //启动
ET0=1; //允许中断
EA=1; //启动中断系统
while(1)
{
if(P25==0) {passport(); f=2;} //解除警报passport执行完应该回到这里才对啊?
if(P30==1&P25!=0) f=1; //警报开启
if(P30==0) f=0; //无警报
if(P26==0) {passport(); d=2;} //解除警报
if(P31==1&P26!=0) d=1; //警报开启
if(P31==0) d=0; //无警报
}
}
仿真的结果是,不管按下KEY1还是KEY2都是报警状态
解警没有实现,但是按下KEY2和KEY1时LCD上确会显示“error”和“Right”
我彻底迷茫了!!! |