#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
#define MAIN_Fosc 11059200UL
sbit dula=P2^6;
sbit wela=P2^7;
sbit lcden=P3^4;
sbit lcdwr=P3^6;
sbit lcdrs=P3^5;
sbit sda=P1^1;
sbit rst=P1^2;
sbit sck=P1^0;
sbit s1=P3^0;
sbit s2=P3^1;
sbit s3=P3^2;
sbit s4=P3^3;
sbit ACC0=ACC^0;
sbit ACC7=ACC^7;
sbit BELL=P2^3;
char fen,shi,miao,ri,yue,nian,zhou,s1num,s2num,s4num,flag1,flag2,lshi,lfen;
uchar code table[]={" 2017- - "};
uchar code table1[]={" : : : "};
uchar code table2[]={"HOLLE EVERYONE! "};
uchar code table3[]={"THE TEAM IS NG! "};
/*******************************************************************************/
void delay(uint z)
{
uint i;
do{
i = MAIN_Fosc / 96000;
while(--i);
}while(--z);
}
/*******************************************************************************/
void didi()
{
uchar i;
for(i=0;i<60;i++)
{
BELL = 0;
delay(1);
BELL = 1;
delay(1);
}
}
/*******************************************************************************/
void write_com(uchar com)
{
lcdwr=0;
lcdrs=0;
P0=com;
delay(1);
lcden=1;
delay(1);
lcden=0;
}
/*******************************************************************************/
void write_data(uchar date)
{
lcdrs=1;
P0=date;
delay(1);
lcden=1;
delay(1);
lcden=0;
}
/*******************************************************************************/
void init_1602()
{
lcdwr=0;
lcden=0;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
}
/*******************************************************************************/
void displaystar()
{
uchar i;
write_com(0x80);
for(i=0;i<16;i++)
write_data(table2[i]);
write_com(0x80+0x40);
for(i=0;i<16;i++)
write_data(table3[i]);
}
void time_1602()
{
uchar num;
write_com(0x80);
for(num=0;num<16;num++)
write_data(table[num]);
write_com(0x80+0x40);
for(num=0;num<16;num++)
write_data(table1[num]);
}
/*******************************************************************************/
void write_sfm(uchar add,uchar time)
{
uchar shiwei,gewei;
shiwei=time/16;
gewei=time%16;
write_com(add+0x80);
write_data(0x30+shiwei);
write_data(0x30+gewei);
}
/*******************************************************************************/
void write_zhou(uchar time1)
{
uchar gewei;
gewei=time1%16;
write_com(0x80+13);
write_data(0x30+gewei);
}
/*******************************************************************************/
void Input_1byte(uchar TD)
{
uchar i;
ACC=TD;
for(i=8;i>0;i--)
{
sda=ACC0;
sck=1;
sck=0;
ACC=ACC>>1;
}
}
/*******************************************************************************/
uchar Output_1byte(void)
{
uchar i;
for(i=8;i>0;i--)
{
ACC=ACC>>1;
ACC7=sda;
sck=1;
sck=0;
}
return(ACC);
}
/*******************************************************************************/
void write_1302(uchar DS_ADD,uchar DS_DAT)
{
rst=0;
sck=0;
rst=1;
Input_1byte(DS_ADD);
Input_1byte(DS_DAT);
sck=1;
rst=0;
}
/*******************************************************************************/
uchar read_1302(uchar DS_ADD)
{
uchar DS_INF;
rst=0;
sck=0;
rst=1;
Input_1byte(DS_ADD);
DS_INF=Output_1byte();
sck=1;
rst=0;
return(DS_INF);
}
/*******************************************************************************/
void inital_1302()
{
write_1302(0x8e,0x00);
write_1302(0x90,0xaa);
write_1302(0x80,0x56);
write_1302(0x84,0x13);
write_1302(0x82,0x44);
write_1302(0x8c,0x17);
write_1302(0x88,0x04);
write_1302(0x86,0x28);
write_1302(0x8a,0x05);
write_1302(0xc0,0x08);
write_1302(0xfc,0x00);
write_1302(0x8e,0x80);
}
/********************************************************************************
********************************************************************************/
void keyscan()
{
if(s1==0&&s4num==0)
{
delay(1);
if(s1==0&&s4num==0)
{
flag1=1;
s1num++;
while(!s1);didi();
if(s1num==1)
{
write_com(0x80+0x40+8);
write_com(0x0f);
}
if(s1num==2)
{
write_1302(0x8e,0x00);
write_1302(0x80,miao);
write_1302(0x8e,0x80);
write_com(0x80+0x40+5);
}
if(s1num==3)
{
write_1302(0x8e,0x00);
write_1302(0x82,fen);
write_1302(0x8e,0x80);
write_com(0x80+0x40+2);
}
if(s1num==4)
{
write_1302(0x8e,0x00);
write_1302(0x88,yue);
write_1302(0x8e,0x80);
write_com(0x80+13);
}
if(s1num==5)
{
write_1302(0x8e,0x00);
write_1302(0x84,shi);
write_1302(0x8e,0x80);
write_com(0x80+10);
}
if(s1num==6)
{
write_1302(0x8e,0x00);
write_1302(0x86,ri);
write_1302(0x8e,0x80);
write_com(0x80+7);
}
if(s1num==7)
{
write_1302(0x8e,0x00);
write_1302(0x8c,nian);
write_1302(0x8e,0x80);
write_com(0x80+4);
}
if(s1num==8)
{
flag1=0;
s1num=0;
write_1302(0x8e,0x00);
write_1302(0x8a,zhou);
write_1302(0x8e,0x80);
write_com(0x0c);
}
}
}
/*******************************************************************************/
if(s1num!=0&&s4num==0)
{
if(s2==0)
{
delay(1);
if(s2==0)
{
while(!s2);didi();
if(s1num==1)
{
int x1,x2;
x1=miao%16;
x2=miao/16;
x1++;
if(x1==10)
{
x1=0;
x2++;
if(x2>=6)
x2=0;
}
miao=x1+x2*16;
write_sfm(7+0x40,miao);
write_com(0x80+0x40+8);
}
if(s1num==2)
{
int x3,x4;
x3=fen%16;
x4=fen/16;
x3++;
if(x3==10)
{
x3=0;
x4++;
if(x4>=6)
x4=0;
}
fen=x3+x4*16;
write_sfm(4+0x40,fen);
write_com(0x80+0x40+5);
}
if(s1num==3)
{
int x5,x6;
x5=shi%16;
x6=shi/16;
x5++;
if(x6>=2&&x5>=4)
{
x5=0;
x6=0;
}
if(x5==10)
{
x5=0;
x6++;
}
shi=x5+x6*16;
write_sfm(1+0x40,shi);
write_com(0x80+0x40+2);
}
if(s1num==4)
{
zhou++;
if(zhou==8)
zhou=1;
write_zhou(zhou);
write_com(0x80+13);
}
if(s1num==5)
{
int x5,x6;
x5=ri%16;
x6=ri/16;
x5++;
if(x6>=3&&x5>=1)
{
x5=1;
x6=0;
}
if(x5==10)
{
x5=0;
x6++;
}
ri=x5+x6*16;
write_sfm(9,ri);
write_com(0x80+10);
}
if(s1num==6)
{
int x5,x6;
x5=yue%16;
x6=yue/16;
x5++;
if(x6>=1&&x5>=3)
{
x5=1;
x6=0;
}
if(x5==10)
{
x5=0;
x6++;
}
yue=x5+x6*16;
write_sfm(6,yue);
write_com(0x80+7);
}
if(s1num==7)
{
int x5,x6;
x5=nian%16;
x6=nian/16;
x5++;
if(x6>=2&&x5>=1)
{
x5=1;
x6=0;
}
if(x5==10)
{
x5=0;
x6++;
}
nian=x5+x6*16;
write_sfm(3,nian);
write_com(0x80+4);
}
}
}
}
/*******************************************************************************/
if(s1num!=0||s4num!=0)
{
if(s3==0)
{
delay(1);
if(s3==0)
{
if(s1num!=0)
{
whi