各位大神看下 用DS1302做时钟电路,仿真没有问题。但是实物制作不会走。用定时器模拟时钟有用,说明硬件电路没有问题。向DS1302写入时间也可以,就是时钟好像没走。不知怎么解决。请各位大神指教。。。。
附录1; 程序
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=30;y>0;y--);
}
void Write_A_Byte_TO_DS1302(uchar x)
{
uchar i;
for(i=0;i<8;i++)
{
IO=x&0x01;SCLK=1;SCLK=0;x>>=1;
}
}
uchar Get_A_Byte_FROM_DS1302()
{
uchar i,b=0x00;
for(i=0;i<8;i++)
{
b |= _crol_((uchar)IO,i);
SCLK=1;SCLK=0;
}
return b/16*10+b%16;
}
uchar Read_Data(uchar addr)
{
uchar dat;
RST = 0;SCLK=0;RST=1;
Write_A_Byte_TO_DS1302(addr);
dat = Get_A_Byte_FROM_DS1302();
SCLK=1;RST=0;
return dat;
}
uchar Write_DS1302(uchar addr,uchar dat)
{
RST = 0;SCLK=0;RST=1;
Write_A_Byte_TO_DS1302(addr);
Write_A_Byte_TO_DS1302(dat);
SCLK=1;RST=0;
}
void SET_DS1302()
{
Write_DS1302(0X8E,0X00);
Write_DS1302(0X82,(53/10)<<4 | (53%10)); //分
Write_DS1302(0X84,(15/10)<<4 | (15%10)); //时
Write_DS1302(0X8E,0X80);
}
void GetTime()
{
uchar i,addr = 0x81; //从分钟开始取数字
for(i=0;i<3;i++)
{
DateTime[i]=Read_Data(addr);addr+=2;
temp1=DateTime[1]+DateTime[2]*60;
temp2=DateTime[0];
}
}
void ds1302init()//初始化1302
{
RST=0;
SCLK=0;
Write_DS1302(0x8e,0x00);
Write_DS1302(0x90,0x00);
}
void main()
{
TMOD = 0x01;
TH0 = (65535-50000)/256;
TL0 = (65535-50000)%256;
ET0 = 1;
EA = 1;
TR0 = 1;
ds1302init();
// SET_DS1302();
while(1)
{
GetTime();
display(temp1,temp2);
}
}
附录2 :仿真电路图
|