if(s4==0)//鬧鐘設(shè)置鍵
{
delay(5);
if(s4==0)
{
s4num++;
flag=1; //
while(!s4);
didi();
if(s4num==1)
{
write_com(0x80);
write_date( );
write_date( );
write_date(S);
write_date(E);
write_date(T);
write_date( );
write_date( );
write_date(A);
write_date(L);
write_date(A);
write_date(R);
write_date(M);
write_com(0x80+0x40);
write_date( );
write_date(0);
write_date(0);
write_date(:);
write_date(0);
write_date(0);
write_date(:);
write_date(0);
write_date(0);
write_com(0x80+0x40+8);
write_com(0x0f);
}
if(s4num==2)
write_com(0x80+0x40+5);
if(s4num==3)
write_com(0x80+0x40+2);
if(s4num==4)
{
s4num=0;
write_com(0x0c);
flag=0;
write_com(0x80+2);
write_date(-);
write_com(0x80+5);
write_date(-);
write_com(0x80+8);
write_date( );
write_ds(0,miao);
write_ds(1,amiao);
write_ds(2,fen);
write_ds(3,afen);
write_ds(4,shi);
write_ds(5,ashi);
write_ds(6,week);
write_ds(7,ri);
write_ds(8,yue);
write_ds(9,nian);
}
}
}
if(s4num!=0)
{
if(s2==0)//加1
{
delay(5);
if(s2==0)
{
delay(5);
while(!s2);
didi();
if(s4num==1)
{
amiao++;
if(amiao==60)
amiao=0;
write_sfm(7,amiao);
write_com(0x80+0x40+8);
}
if(s4num==2)
{
afen++;
if(afen==60)
afen=0;
write_sfm(4,afen);
write_com(0x80+0x40+5);
}
if(s4num==3)
{
ashi++;
if(ashi==24)
ashi=0;
write_sfm(1,ashi);
write_com(0x80+0x40+2);
}
}
}
if(s3==0)//減1
{
delay(5);
if(s3==0)
{
delay(5);
while(!s3);
didi();
if(s4num==1)
{
amiao--;
if(amiao==-1)
amiao=59;
write_sfm(7,amiao);
write_com(0x80+0x40+8);
}
if(s4num==2)
{
afen--;
if(afen==-1)
afen=59;
write_sfm(4,afen);
write_com(0x80+0x40+5);
}
if(s4num==3)
{
ashi--;
if(ashi==-1)
ashi=23;
write_sfm(1,ashi);
write_com(0x80+0x40+2);
}
}
}
}本文引用地址:http://m.butianyuan.cn/article/201611/321018.htm}
void write_ds(uchar add,uchar date)
{
dscs=0;
dsas=1;
dsds=1;
dsrw=1;
P0=add; //先寫地址
dsas=0;
dsrw=0;
P0=date; //再寫數(shù)據(jù)
dsrw=1;
dsas=1;
dscs=1;
}
uchar read_ds(uchar add)
{
uchar ds_date;
dsas=1;
dsds=1;
dsrw=1;
dscs=0;
P0=add; //先寫地址
dsas=0;
dsds=0;
P0=0xff;
ds_date=P0; //再讀數(shù)據(jù)
dsds=1;
dsas=1;
dscs=1;
return ds_date;
}
void read_alarm()
{
amiao=read_ds(1);
afen=read_ds(3);
ashi=read_ds(5);
}
void main()
{
Readtemp(); // 讀溫度
flag=0; //時鐘芯片的顯示標(biāo)志
init(); //時鐘芯片的初始化
while(1)
{
keyscan();
if(flag1==1)//鬧鐘設(shè)置
{
didi();
delay(100);
didi();
delay(500);
}
if(flag==0)//flag顯示標(biāo)志位 0為顯示
{
keyscan();
miao=read_ds(0);//讀12C887數(shù)據(jù)
fen=read_ds(2);
shi=read_ds(4);
week=read_ds(6);
ri =read_ds(7);
yue=read_ds(8);
nian=read_ds(9);
write_sfm(7,miao);//送液晶顯示
write_sfm(4,fen);
write_sfm(1,shi);
write_nyrx(6,ri);
write_nyrx(3,yue);
write_nyrx(0,nian);
write_com(0x80+9);
write_date(table3[week]);
write_date(table4[week]);
write_date(table5[week]);
display(Readtemp());//顯示溫度
}
}
}
void exter() interrupt 2 //鬧鐘中斷
{
uchar c;
flag1=1;
c=read_ds(0x0c);
}
評論