#include <REGX52.H>
#include <intrins.h>
#define Busy 0x80 //常量定义
#define uchar unsigned char
#define uint unsigned int
#define DATAPORT P0
sbit LCM_RS=P2^0; //引脚定义
sbit LCM_RW=P2^1; //引脚定义
sbit LCM_EN=P2^2;
sbit SCL=P2^3;
sbit SDA=P2^4;
bit ax; //密码正确与否关键标志
bit b1,b2;
uint y3,y4;
uchar n,y1,y2;
uchar js,ss[2];
uchar a1[8]={0,0,0,0,0};
uchar aa[2][8];
uchar code str1[]={"ks1 ks2 ks3"};
uchar code str2[]={"tw1 tw2 tw3"};
uchar code str3[]={"DOT: ON OF "};
uchar code str4[]={" Qing_Shu_Ru "};
uchar code str5[]={"--- Wrong ---- "};
uchar code str6[]={" --- O K ---- "};
uchar code str7[]={"D_S_1:ON OF "};
uchar code str8[]={"D_S_2:ON OF "};
uchar code str9[]={"Shi_Fou_Bao_Cun"};
uchar code str10[]={" Yes No "};
uchar code staa[][34]={"ks1 ks2 ks3 ks4 ks5 ks6 ",
"ks7 ks8 ks9 k11 k12 k13 ",
"y01 y02 y03 y04 y05 y06 ",
"y07 y08 y09 y10 y11 y12 "};
void qie_huan_xian_si();
void mi_ma_ti_shi();
void shijianbijiao();
void jiemian130();
uchar ReadStatusLCM(void) ;
/*----------------------时间结构体---------------------*/
struct ShiJian
{
uchar sec;
uchar min;
uchar hour;
} shijian[5],*p;
/*-----------------------延时K*ms-----------------------*/
void delay(uint k)
{
uint i,j;
for(i=0;i<k;i++)
{
for(j=0;j<120;j++)
{;}
}
}
/*-----------------------------------------------------*/
void WriteCommandLCM(uchar WCLCM, uchar BusyC) /*函数名为WriteCommandLCM 的写指令到LCM子函数。定义WCLCM、BusyC 为无符号字符型变量*/
{ //WriteCommandLCM函数开始
if(BusyC)
ReadStatusLCM(); /*若BusyC为"1",则调用ReadStatusLCM子函数进行忙检测*/
LCM_RS=0; //选中指令寄存器
LCM_RW=0; //写模式
DATAPORT=WCLCM;
LCM_EN=1;
_nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_();
_nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_();
LCM_EN=0; //置LCM_EN端为高电平,写入使能
} // WriteCommandLCM函数结束
/*----------------------------写数据到LCM子函数-------------------------------*/
void WriteDataLCM(uchar WDLCM) /*函数名为WriteDataLCM 的写数据到LCM子函数。定义WDLCM 为无符号字符型变量*/
{ // WriteDataLCM函数开始
ReadStatusLCM(); //调用ReadStatusLCM子函数检测忙信号
LCM_RS=1; //选中数据寄存器
LCM_RW=0; //写模式
DATAPORT=WDLCM;
LCM_EN=1;
_nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_();
_nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); //置LCM_EN端为低电平,延时一会儿
LCM_EN=0;
} // WriteDataLCM函数结束
/*--------------------------------读状态到MCU子函数-----------------------------*/
uchar ReadStatusLCM(void) //函数名为ReadStatusLCM的读状态到MCU子函数
{ //ReadStatusLCM函数开始
uchar i;
i=255;
DATAPORT=0xFF; //置P1口为全1
LCM_EN=1;
LCM_RS=0; //选中指令寄存器
LCM_RW=1; //读模式
while(P1&Busy)
{
i--;
if(i==0)
break;
} /*检测忙信号。当P1口内容与Busy(80H)相与后不为零时,程序原地踏步*/
LCM_EN=0;
return(DATAPORT); //返回P1口的内容
} // ReadStatusLCM函数结束
// ReadStatusLCM函数结束
// ReadStatusLCM函数结束
/*--------------------------LCM初始化子函数----------------------------*/
void InitLcd() //函数名为InitLcd 的LCM初始化子函数
{ // InitLcd函数开始
WriteCommandLCM(0x38,1);//8位数据传送,2行显示,5*7字形,检测忙信号
WriteCommandLCM(0x08,1);//关闭显示,检测忙信号
WriteCommandLCM(0x01,1);//清屏,检测忙信号
WriteCommandLCM(0x06,1);//显示光标右移设置,检测忙信号
WriteCommandLCM(0x0c,1);//显示屏打开,光标不显示、不闪烁,检测忙信号
} // InitLcd函数结束
/*-------------------显示指定座标的一个字符子函数---------------------------*/
void Lcd1602(uchar X,uchar Y,uchar DData)
{
Y&=1;
X&=15;
if(Y)
X|=0x40;
X|=0x80;
WriteCommandLCM(X,0);
WriteDataLCM(DData);
}
/*---------------------------------------------------*/
void Lcd_1602(uchar X,uchar Y,uchar code *DData)
{
uchar i;
i=0;
Y&=1;
X&=15;
if(Y)X|=0x40;
X|=0x80;
WriteCommandLCM(X,0);
while(i<16)
{
WriteDataLCM(*DData);
DData++;
i++;
}
}
/****************************24c01*****开始********************/
void X24c01_start()
{
SDA=1;
SCL=1;
_nop_();_nop_();_nop_();_nop_(); _nop_();_nop_();_nop_();_nop_();
SDA=0;
_nop_();_nop_();_nop_();_nop_(); _nop_();_nop_();_nop_();_nop_();
SCL=0;
}
/****************************24c01停止**********************/
void X24c01_stop()
{
SDA=0;
SCL=1;
_nop_();_nop_();_nop_();_nop_(); _nop_();_nop_();_nop_();_nop_();
SDA=1;
_nop_();_nop_();_nop_();_nop_(); _nop_();_nop_();_nop_();_nop_();
SCL=0;
}
/************************24c01写一字节**********************/
void X24c01_write(uchar x)
{
uchar i;
for (i=8;i>0;i--)
{
if (x&0x80)
SDA=1;
else
SDA=0;
SCL=1;
_nop_();_nop_();_nop_();_nop_(); _nop_();_nop_();_nop_();_nop_();
SCL=0;
x=x<<1;
}
}
/****************************24c01应答*********************/
void X24c01_ack()
{
SDA=0;
SCL=1;
_nop_();_nop_();_nop_();_nop_(); _nop_();_nop_();_nop_();_nop_();
SCL=0;
}
/****************************24c01不应答*********************/
void X24c01_noack()
{
SDA=1;
SCL=1;
_nop_();_nop_();_nop_();_nop_(); _nop_();_nop_();_nop_();_nop_();
SCL=0;
}
/************************24c01读一字节**********************/
uchar X24c01_Ride()
{
uchar i,y;
for (i=8;i>0;i--)
{
SDA=1;
y=y<<1;
SCL=1;
_nop_();_nop_();_nop_();_nop_(); _nop_();_nop_();_nop_();_nop_();
if (SDA)
y++;
SCL=0;
}
return y;
}
/**********************24c01写字节函数*********************/
void C2401_write(uchar x,uchar y)
{
X24c01_start();
X24c01_write(160);
X24c01_ack();
X24c01_write(x);
X24c01_ack();
X24c01_write(y);
X24c01_ack();
X24c01_stop();
}
/**********************24c01读函数**************************/
uchar C2401_read(uchar x)
{
uchar y;
X24c01_start();
X24c01_write(160);
X24c01_ack();
X24c01_write(x);
X24c01_ack();
X24c01_start();
X24c01_write(161);
X24c01_ack();
y=X24c01_Ride();
X24c01_noack();
X24c01_stop();
return y;
}
/*---------------------------------------------------*/
bit jian_pan()
{
bit a1;
uchar i,t1,t2;
P1=0xf0;
t1=0;
t2=0;
if(P1!=0xf0)
{
delay(20);
if(P1!=0xf0)
{
for(i=0x01;i!=0x10;i=i<<1)
{
P1=~i;
if(P1_4==0)
{
t1=0;
break;
}
if(P1_5==0)
{
t1=4;
break;
}
if(P1_6==0)
{
t1=8;
break;
}
if(P1_7==0)
{
t1=12;
break;
}
t2++;
}
while(P1!=~i)
{
shijianbijiao();
}
js=t1+t2;
a1=1;
y4=0; //全局变量,有键按下清楚10秒自动回位标志
return a1;
}
}
a1=0;
return a1;
}
/*---------------------------------------------------*/
void qing_shu_ju()
{
uchar i;
for(i=n;i>0;i--)
{
a1[i]=0;
}
a1[0]=0;
}
/*-------