#include<reg51.h>
#define uint unsigned int
#define uchar unsigned char
sbit sh=P2^0;
sbit ds=P2^1;
sbit st=P2^2;
sbit hc=P1^6;
sbit ds_rst=P3^5;
sbit ds_clk=P3^6;
sbit ds_io=P3^7;
sbit ACC0=ACC^0;
sbit ACC7=ACC^7;
uchar code table[]=
{
0x00,0x38,0x44,0x44,0x44,0x44,0x44,0x38, //0
0x00,0x08,0x18,0x08,0x08,0x08,0x08,0x1C, //1
0x00,0x38,0x44,0x04,0x04,0x78,0x40,0x7C, //2
0x00,0x38,0x44,0x04,0x38,0x04,0x44,0x38, //3
0x00,0x04,0x0C,0x14,0x24,0x7F,0x04,0x04, //4
0x00,0x7C,0x40,0x40,0x78,0x04,0x04,0x78, //5
0x00,0x38,0x40,0x40,0x78,0x44,0x44,0x38, //6
0x00,0x7C,0x04,0x04,0x04,0x04,0x04,0x04, //7
0x00,0x38,0x44,0x44,0x38,0x44,0x44,0x38, //8
0x00,0x38,0x44,0x44,0x3C,0x04,0x04,0x38, //9
0x00,0x10,0x00,0x00,0x00,0x00,0x10,0x00 //:
};
void delay(uint x)
{
uchar t;
while(x--) for(t=0;t<100;t++);
}
void shifter(uchar date)
{
uchar i;
for(i=0;i<8;i++)
{
sh=0;
ds=date&0x01;
sh=1;
date>>=1;
}
st=0;
st=1;
}
void write_dsbyte(uchar date)
{
uchar i;
ACC=date;
for(i=8;i>0;i--)
{
ds_io=ACC0;
ds_clk=1;
ds_clk=0;
ACC=ACC>>1;
}
}
uchar read_dsbyte(void)
{
uchar i;
for(i=0;i<8;i++)
{
ACC=ACC>>1;
ACC7=ds_io;
ds_clk=1;
ds_clk=0;
}
return(ACC);
}
uchar read_ds1302(uchar add)
{
uchar temp;
ds_rst=0;
ds_clk=0;
ds_rst=1;
write_dsbyte(add);
temp=read_dsbyte();
ds_rst=0;
ds_clk=1;
return temp;
}
void main()
{
uchar i;
uchar miao,miao1,miao2;
uchar fen,fen1,fen2;
uchar shi,shi1,shi2;
while(1)
{
miao=read_ds1302(0x81);
miao1=miao&0x0f;
miao2=(miao>>4);
fen=read_ds1302(0x83);
fen1=fen&0x0f;
fen2=(fen>>4);
shi=read_ds1302(0x85);
shi1=shi&0x0f;
shi2=(shi>>4);
for(i=0;i<8;i++)
{
hc=1;
P1=0xf0|i;
shifter(table[miao1*8+i]);
shifter(table[miao2*8+i]);
shifter(table[80+i]);
shifter(table[fen1*8+i]);
shifter(table[fen2*8+i]);
shifter(table[80+i]);
shifter(table[shi1*8+i]);
shifter(table[shi2*8+i]);
hc=0;
delay(6);
}
delay(2);
}
}[img][/img] |