#include
#define uint unsigned int
#define uchar unsigned char
sbit lcdrs=P3^0;
sbit lcdrw=P3^1;
sbit lcden=P3^2;
sbit ring=P2^1;
uchar aa,bb,cc,aa1,bb1,cc1,temp;
uchar cnt=20;
uchar cntt=20;
uint ss=0;
uchar table[]="0123456789:";
//uchar jjj=2;
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void write_com(uchar com)
{
lcdrs=0;//写命令
P0=com;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
/*void write_data(uchar shuju)
{
lcdrs=1; //写数据
lcden=0;
P0=shuju;
delay(5);
lcden=1;
delay(5);
lcden=0;
}*/
void write_data(uchar jj)
{
lcdrs=1;//写数据
P0=jj;
delay(5);
lcden=1;//高脉冲激昂数据读走
delay(5);
lcden=0;
}
void display()
{
write_com(0x80);
write_data(table[cc/10]);
write_com(0x81);
write_data(table[cc%10]); //时
write_com(0x82);
write_data(table[10]); //:
write_com(0x83);
write_data(table[bb/10]); //分
write_com(0x84);
write_data(table[bb%10]);
write_com(0x85);
write_data(table[10]);//:
write_com(0x86);
write_data(table[aa/10]); //秒
write_com(0x87);
write_data(table[aa%10]);
if(cnt==0)
{
cnt=20;
aa++;
if(aa>=60)
{
aa=0;
bb++;
if(bb>=60)
{
bb=0;
cc++;
if(cc>=24)
cc=0;
}
}
}
}
void init()
{
aa=45;//秒
bb=56;//分
cc=22;//时
aa1=50;
bb1=56;
cc1=22;
lcdrw=0;
lcden=0;
write_com(0x38);//显示开关及光标设置
write_com(0x0f);// write_com(0x0f);打开光标闪烁
write_com(0x06);//光标指针自动加一
write_com(0x01); //显示清屏数据指针清零
write_com(0x80); //数据指针初始化
// write_com(0x80);//数据指针自动初始化
/*
lcden=0;
lcdrw=0;
write_com(0x38);
delay(5);
write_com(0x0c);
write_com(0x80);
write_com(0x06);
*/
}
void main()
{
EA=1;//开总中断
ET0=1;//开定时器中断零
TR0=1;//定时器零开始计数
TMOD=0x01;
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
init();
write_com(0x81);
//write_date(jjj);
while(1)
{
display();
}
}
/*void ringg()
{
if(aa1==aa&bb1==bb&cc1==cc)
{
temp=cc1;
ring=0;
if(temp==cc+5)
ring=1;
}
*/
/*{
ET1=1;//开定时器中断零
TR1=1;//定时器零开始计数
TMOD=0x01;
TH1=(65535-50000)/256;
TL1=(65535-50000)%256;
cntt--;
if(cntt==0)
{
cntt=20;
ss++;
if(ss==120)
ring=1;
}
}
*/
void timer0() interrupt 1
{
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
cnt--;
/*
write_com(0x80);
write_data(table[cc/10]);
write_com(0x81);
write_data(table[cc%10]);
write_com(0x82);
write_data(table[bb/10]);
write_com(0x83);
write_data(table[bb%10]);
write_data(table[aa/10]);
write_data(table[aa%10]);
*/
/*
write_com(0x80);
write_data(table[cc/10]);
write_com(0x81);
write_data(table[cc%10]); //时
write_com(0x82);
write_data(table[10]); //:
write_com(0x83);
write_data(table[bb/10]); //分
write_com(0x84);
write_data(table[bb%10]);
write_com(0x85);
write_data(table[10]);//:
write_com(0x86);
write_data(table[aa/10]); //秒
write_com(0x87);
write_data(table[aa%10]);
*/
if(cnt==0)
{
cnt=20;
aa++;
if(aa>=60)
{
aa=0;
bb++;
if(bb>=60)
{
bb=0;
cc++;
if(cc>=24)
cc=0;
}
}
}
//ringg();
if(aa1==aa&bb1==bb&cc1==cc)
{
ring=0;
temp=aa1+60;
}
if(temp==aa)
ring=1;
}
阅读(1426) | 评论(0) | 转发(0) |