找回密码
 注册会员
更新自动建库工具PCB Footprint Expert 2024.04 Pro / Library Expert 破解版

ds1302的问题

[复制链接]
admin 发表于 2012-9-2 11:16:52 | 显示全部楼层 |阅读模式

本文包含原理图、PCB、源代码、封装库、中英文PDF等资源

您需要 登录 才可以下载或查看,没有账号?注册会员

×
我是个菜鸟,刚学单片机没多久。麻烦高手看看程序中哪边有问题。小弟感谢万分!
#include <reg51.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
sbit sck=P1^0;
sbit io=P1^1;
sbit rst=P1^2;
uchar cout;
uchar duanxuan[11]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf};
uchar weixuan[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
uchar huancun[8];
uchar time[7]={10,4,3,15,12,56,45};
uchar write_add[7]={0x8c,0x8a,0x88,0x86,0x84,0x82,0x80};
uchar read_add[7]={0x8d,0x8b,0x89,0x87,0x85,0x83,0x81};
void delay(uchar i)
{
do
{
huancun[0]=time[0]%16;
huancun[1]=time[1]/16;
huancun[2]=10;
huancun[3]=time[2]%16;
huancun[4]=time[3]/16;
huancun[5]=10;
huancun[6]=time[4]%16;
huancun[7]=time[5]/16;
}while(i--);
}
void write_ds1302_bety(uchar dat)
{
uchar i;
for(i=0;i<8;i++)
{
sck=0;
io=dat&0x01;
dat>>=1;
sck=1;
}
}
void write_ds1302(uchar add,uchar dat)
{
rst=0;
_nop_();
sck=0;
_nop_();
rst=1;
_nop_();
write_ds1302_bety(add);
write_ds1302_bety(dat);
rst=0;
_nop_();
sck=1;
_nop_();
io=1;
}
uchar read_ds1302(uchar add)
{
uchar i,value;
rst=0;
_nop_();
sck=0;
_nop_();
rst=1;
_nop_();
write_ds1302_bety(add);
value=0;
for(i=0;i<8;i++)
{
value>>=1;
if(io)
{
value=value|0x80;

}
sck=1;
}
rst=0;
_nop_();
sck=0;
_nop_();
sck=1;
io=1;
return value;

}
void set_rtc()
{
uchar i;
for(i=0;i<7;i++)
{
time[i]=time[i]/10*16+time[i]%10;
}
write_ds1302(0x8e,0x00);
for(i=0;i<7;i++)
{
write_ds1302(write_add[i],time[i]);
}
write_ds1302(0x8e,0x80);

}
void read_rct()
{
uchar i;
for(i=0;i<7;i++)
{
time[i]=read_ds1302[read_add[i]];
}
}
void display()
{
uchar i;
for(i=0;i<8;i++)
{
P2=weixuan[i];
P0=duanxuan[huancun[i]];
delay(100);
}

}

void main()
{
set_rtc();
while(1)
{
read_rtc();
delay(1);
display();

}

}
*滑块验证:
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

QQ|手机版|MCU资讯论坛 ( 京ICP备18035221号-2 )|网站地图

GMT+8, 2024-11-28 13:50 , Processed in 0.050419 second(s), 9 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表