}
void write_ds(uchar add,uchar date)
{
dscs=0;
dsas=1;
dsds=1;
dsrw=1;
P0=add; //先写地址
dsas=0;
dsrw=0;
P0=date; //再写数据
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; //再读数据
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; //时钟芯片的显示标志
init(); //时钟芯片的初始化
while(1)
{
keyscan();
if(flag1==1)//闹钟设置
{
didi();
delay(100);
didi();
delay(500);
}
if(flag==0)//flag显示标志位 0为显示
{
keyscan();
miao=read_ds(0);//读12C887数据
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);
}