【芯圣SDK-HC89F0541测评】DS1302 RTC计时
本帖最后由 芯圣电子官方QQ 于 2023-7-24 14:18 编辑DS1302计时模块是一种小巧的带后备电池的功能模块,可在掉电的情况下一直维持着计时器的运行。DS1302与SDK-HC89F0541开发板的连接关系为:RST--- P3_5IO --- P3_4SCK--- P3_3
为便于观察计时结果,还使用串行通讯口来输出计时内容。其中,TXD为 P16,而RXD 为P17,整体的连接构成如图所示。RTC计时构成图
串口发送字节的函数为:void SendByte(uchar dat)
{
IE &=~ 0x10;
SBUF = dat;
while(!(SCON & 0x02));
SCON &=~ 0x02;
IE |= 0x10;
}
串口发送计时值得函数为:void RTC_xs(void)
{
SendByte(readtime+'0');
SendByte(readtime+'0');
SendByte(readtime+'0');
SendByte(readtime+'0');
SendByte('-');
SendByte(readtime+'0');
SendByte(readtime+'0');
SendByte('-');
SendByte(readtime+'0');
SendByte(readtime+'0');
SendByte(' ');
SendByte(readtime+'0');
SendByte(readtime+'0');
SendByte(':');
SendByte(readtime+'0');//s
SendByte(readtime+'0');
SendByte(':');
SendByte(readtime+'0');//s
SendByte(readtime+'0');
SendByte('\r');
SendByte('\n');
}
使DS1302模块产生图示效果的主程序为:void main(void)
{
WDTCCR = 0x00;
while((CLKCON&0x20)!=0x20);
CLKSWR = 0x51;
while((CLKSWR&0xC0)!=0x40);
CLKDIV = 0x01;
P3M3 = 0xC2;
P3M4 = 0xC2;
P3M5 = 0xC2;
P1M6 = 0xC2;
P1M7 = 0x62;
TXD_MAP = 0x16;
RXD_MAP = 0x17;
T4CON = 0x06;
TH4 = 0xFF;
TL4 = 0x98; // 9600bps
SCON2 = 0x02; // 8bit
SCON = 0x10;
IE |= 0x10;
EA = 1;
ds1302_init();
time_buf=0x20;
time_buf=0x07;
time_buf=0x07;
time_buf=0x14;
time_buf=0x01;
time_buf=0x30;
time_buf=0x02;
ds1302_write_time();
while(1)
{
ds1302_read_time();
readtime=(time_buf>>4);
readtime=(time_buf&0x0F);
readtime=(time_buf>>4);
readtime=(time_buf&0x0F);
readtime=(time_buf>>4);
readtime=(time_buf&0x0F);
readtime=(time_buf>>4);
readtime=(time_buf&0x0F);
readtime=(time_buf>>4);
readtime=(time_buf&0x0F);
readtime=(time_buf>>4);
readtime=(time_buf&0x0F);
readtime=(time_buf>>4);
readtime=(time_buf&0x0F);
if(readtime!=sec_buf)
{
sec_flag=0;
sec_buf=readtime;
RTC_xs(); ;
}
}
}
计时效果图
模块真不少 比神乐 发表于 2020-7-9 19:17
模块真不少
你的HT1621也很不错呀! 也有这模块,找出来试试 WENHX 发表于 2020-7-11 09:48
也有这模块,找出来试试
这个模块还是比较好用的。 楼主辛苦了 感谢楼主分享 这是一个外接模块吗 代码很详细 真的很不错 晓伍 发表于 2020-8-7 13:54
真的很不错
感谢支持! 木木guainv 发表于 2020-8-7 13:52
这是一个外接模块吗
YES
页:
[1]