我找着pdf资料写的 怎么不对呢??高手帮帮忙呀!!!急。。。。
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit SCLK = P3^6;
sbit IO = P3^4;
sbit RST = P3^5;
struct
{
uint second;
uint minute;
uint hour;
uint day;
uint month;
uint week;
uint year;
}current;
void write(uint con)
{
uchar i;
for(i=8;i>0;i--)
{
if(con&0x01)
{
IO=1;
}
else
{
IO=0;
}
con>>=1;
SCLK=1;
SCLK=0;
}
}
uint read()
{
uint i,readv;
IO=1;
for(i=8;i>0;i--)
{
readv>>=1;
if(IO)
{
readv|=0x80;
}
else
{
readv&=0x7f;
}
return readv;
}
}
void write_byte(uint address,uint con)
{
RST=0;
SCLK=0;
RST=1;
write(address);
write(con);
RST=0;
SCLK=1;
}
uint read_byte(uint address)
{
uint readv;
RST=0;
SCLK=0;
RST=1;
write(address);
readv=read();
RST=0;
SCLK=1;
return readv;
}
void clockinit()
{
if(read_byte(0xc1)!=0xf0)
{
write_byte(0x8e,0x00);
write_byte(0x80,0x00);
write_byte(0x82,0x08);
write_byte(0x84,0x08);
write_byte(0x86,0x08);
write_byte(0x88,0x08);
write_byte(0x8a,0x08);
write_byte(0x8c,0x08);
write_byte(0x90,0xa5);
write_byte(0xc0,0xf0);
write_byte(0x8e,0x80);
}
}
void clockup()
{
current.second=read_byte(0x81);
current.minute=read_byte(0x83);
current.hour=read_byte(0x85);
current.day=read_byte(0x87);
current.month=read_byte(0x89);
current.week=read_byte(0x8b);
current.year=read_byte(0x8d);
} |