大型网站怎么加载图片的苏州市公共交易资源平台
目录
1.管脚
2.时序&官方提供的读写函数
3.如何使用读写函数
4.如何在数码管中显示在DS1302中读取出的数据?
1.管脚

2.时序&官方提供的读写函数
/*	# 	DS1302代码片段说明1. 	本文件夹中提供的驱动代码供参赛选手完成程序设计参考。2. 	参赛选手可以自行编写相关代码或以该代码为基础,根据所选单片机类型、运行速度和试题中对单片机时钟频率的要求,进行代码调试和修改。
*/								//
void Write_Ds1302(unsigned  char temp) 
{unsigned char i;for (i=0;i<8;i++)     	{ SCK = 0;SDA = temp&0x01;temp>>=1; SCK=1;}
}   //
void Write_Ds1302_Byte( unsigned char address,unsigned char dat )     
{RST=0;	_nop_();SCK=0;	_nop_();RST=1; 	_nop_();  Write_Ds1302(address);	Write_Ds1302(dat);		RST=0; 
}//
unsigned char Read_Ds1302_Byte ( unsigned char address )
{unsigned char i,temp=0x00;RST=0;	_nop_();SCK=0;	_nop_();RST=1;	_nop_();Write_Ds1302(address);for (i=0;i<8;i++) 	{		SCK=0;temp>>=1;	if(SDA)temp|=0x80;	SCK=1;} RST=0;	_nop_();SCK=0;	_nop_();SCK=1;	_nop_();SDA=0;	_nop_();SDA=1;	_nop_();return (temp);			
}
 
3.如何使用读写函数
以时分秒为例

在写中

void Set_Rtc(unsigned char* ucRtc)
{Write_Ds1302_Byte(0x8e,0x00);Write_Ds1302_Byte(0x84,ucRtc[0]);Write_Ds1302_Byte(0x82,ucRtc[1]);Write_Ds1302_Byte(0x80,ucRtc[2]);Write_Ds1302_Byte(0x8e,0x80);
}void Read_Rtc(unsigned char)
{unsigned char i;for(i=0;i<3;i++)ucRtc[i] = Read_Ds1302_Byte(0x85-2*i);
} 
记得加入DS1302的驱动中声明函数,并在变量声明中定义数组
unsigned char ucRtc[3] = {0x23,0x59,0x55} //上电显示默认时间 23 59 55
需要在初始化区域中调用Set_Rtc();函数,参数写ucRtc
在信息读取区域中调用Read_Rtc();函数,参数写ucRtc
4.如何在数码管中显示在DS1302中读取出的数据?
因为在DS1302中使用的是BCD码,需要进行处理

需要对十位和个位进行相除和取余,11则是横杠的显示 在共阳极数码管中为
1011 1111,0xbf,在数码管数组中放入第11位
仿真显示效果

在DS1302中均是先写地址,再写数据,先打开保护再对需要操作的RTC进行操作然后再关闭保护保证数据的稳定性(保护只有写的时候需要)
