#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit rw=P3^6;
sbit rs=P3^5;
sbit lcden=P3^4;
sbit s1=P3^0;
sbit s2=P3^1;
sbit s3=P3^2;
sbit rd=P3^7;
sbit ce=P2^5;
sbit sclk=P2^6;
sbit io=P2^7;
sbit B1=B^0;
sbit ACC7 = ACC^7;
uchar count,s1num;
char miao,shi,fen,k;
uchar code table[]=" 20 - - W: ";
uchar code table1[]=" 00:00:00";
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void write_com(uchar com)
{
rs=0;
lcden=0;
P0=com;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void write_date(uchar date)
{
rs=1;
lcden=0;
P0=date;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void init()
{
uchar num;
rw=0;
lcden=0;
// fen=59;
// miao=53;
// shi=23;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
write_com(0x80);
for(num=0;num<16;num++)
{
write_date(table[num]);
delay(5);
}
write_com(0x80+0x40);
for(num=0;num<12;num++)
{
write_date(table1[num]);
delay(5);
}
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
}
void write_sfm(uchar add,uchar date)
{
uchar shi,ge;
shi=date/10;
ge=date%10;
write_com(0x80+0x40+add);
write_date(0x30+shi);
write_date(0x30+ge);
}
void write_nyr(uchar add,uchar date)
{
uchar shi,ge;
shi=date/10;
ge=date%10;
write_com(0x80+add);
write_date(0x30+shi);
write_date(0x30+ge);
}
/*uchar write1302_byte(uchar com2)
{
ce=0;
sclk=0;
_nop_();
ce=1;
} */
uchar read1302(uchar com1)
{
uchar shu,j,shu1;
ce=0;
// delay(5);
sclk=0;
// delay(5);
ce=1;
B=com1;
for(shu=0;shu<8;shu++)
{
io=B1;
B=B>>1;
sclk=1;
sclk=0;
}
delay(5);
for(shu1=8; shu1>0; shu1--)
{
ACC = ACC >>1; //相当于汇编中的 RRC
ACC7 = io; //????????
sclk = 1;
sclk = 0;
}
return(ACC);
}
void main()
{
init();
while(1)
{
uint u,u1,u2;
// keyscan();
u=read1302(0x81);
// miao = ((u&0x70)>>4)*10 + (u&0x0F);
miao=((u&0x70)>>4)*10 + (u&0x0F);
write_sfm(10,miao);
write_com(0x80+0x40+10);
// delay(10);
u1 = read1302(0x83); //从分寄存器读
fen=((u1&0x70)>>4)*10 + (u1&0x0F); //将读出数据转化
write_sfm(7,fen);
write_com(0x80+0x40+7);
// delay(10);
u2=read1302(0x85);
shi=((u2&0x70)>>4)*10 + (u2&0x0F);
write_sfm(4,shi);
write_com(0x80+0x40+4);
// delay(20); */
u2=read1302(0x8d); //年
shi=((u2&0x70)>>4)*10 + (u2&0x0F);
write_nyr(3,shi);
write_com(0x80+4);
u2=read1302(0x89);// 月
shi=((u2&0x70)>>4)*10 + (u2&0x0F);
write_nyr(6,shi);
write_com(0x80+7);
u2=read1302(0x87); //日
shi=((u2&0x70)>>4)*10 + (u2&0x0F);
write_nyr(9,shi);
write_com(0x80+10);
u2=read1302(0x8b); //星期
shi=((u2&0x70)>>4)*10 + (u2&0x0F);
write_nyr(14,shi);
write_com(0x80+14);
}
// while(1);
}