[通用8051核FLASH系列]

【芯圣SDK-HC89F0541测评】DS1302 RTC计时

[复制链接]
921|11
手机看帖
扫描二维码
随时随地手机跟帖
jinglixixi|  楼主 | 2020-7-8 23:48 | 显示全部楼层 |阅读模式
本帖最后由 芯圣电子官方QQ 于 2023-7-24 14:18 编辑

DS1302计时模块是一种小巧的带后备电池的功能模块,可在掉电的情况下一直维持着计时器的运行。
DS1302SDK-HC89F0541开发板的连接关系为:
RST  --- P3_5
IO    --- P3_4
SCK  --- P3_3

为便于观察计时结果,还使用串行通讯口来输出计时内容。其中,TXD P16,而RXD P17,整体的连接构成如图所示。
1.png
RTC计时构成图

串口发送字节的函数为:
void SendByte(uchar dat)
{
           IE &=~ 0x10;
           SBUF = dat;         
           while(!(SCON & 0x02));
           SCON &=~ 0x02;
           IE |= 0x10;
}

串口发送计时值得函数为:
void RTC_xs(void)
{
  SendByte(readtime[0]+'0');
  SendByte(readtime[1]+'0');   
  SendByte(readtime[2]+'0');
  SendByte(readtime[3]+'0');   
  SendByte('-');
  SendByte(readtime[4]+'0');
  SendByte(readtime[5]+'0');
  SendByte('-');
  SendByte(readtime[6]+'0');
  SendByte(readtime[7]+'0');
  SendByte(' ');      
  SendByte(readtime[8]+'0');
  SendByte(readtime[9]+'0');
  SendByte(':');
  SendByte(readtime[10]+'0');//s
  SendByte(readtime[11]+'0');
  SendByte(':');
  SendByte(readtime[12]+'0');//s
  SendByte(readtime[13]+'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[1]=0x20;
         time_buf[2]=0x07;
         time_buf[3]=0x07;
         time_buf[4]=0x14;
         time_buf[5]=0x01;
         time_buf[6]=0x30;
         time_buf[7]=0x02;

        ds1302_write_time();
        while(1)
        {     
             ds1302_read_time();
             readtime[0]=(time_buf[0]>>4);  
             readtime[1]=(time_buf[0]&0x0F);
             readtime[2]=(time_buf[1]>>4);  
             readtime[3]=(time_buf[1]&0x0F);
             readtime[4]=(time_buf[2]>>4);
             readtime[5]=(time_buf[2]&0x0F);
             readtime[6]=(time_buf[3]>>4);  
             readtime[7]=(time_buf[3]&0x0F);
             readtime[8]=(time_buf[4]>>4);  
             readtime[9]=(time_buf[4]&0x0F);
             readtime[10]=(time_buf[5]>>4);  
             readtime[11]=(time_buf[5]&0x0F);
             readtime[12]=(time_buf[6]>>4);  
             readtime[13]=(time_buf[6]&0x0F);
             if(readtime[13]!=sec_buf)        
            {
                 sec_flag=0;   
                 sec_buf=readtime[13];   
                 RTC_xs(); ;
            }
      }
}

2.png
计时效果图

使用特权

评论回复
比神乐| | 2020-7-9 19:17 | 显示全部楼层
模块真不少

使用特权

评论回复
jinglixixi|  楼主 | 2020-7-10 07:59 | 显示全部楼层

你的HT1621也很不错呀!

使用特权

评论回复
WENHX| | 2020-7-11 09:48 | 显示全部楼层
也有这模块,找出来试试

使用特权

评论回复
jinglixixi|  楼主 | 2020-7-11 18:16 | 显示全部楼层
WENHX 发表于 2020-7-11 09:48
也有这模块,找出来试试

这个模块还是比较好用的。

使用特权

评论回复
wowu| | 2020-8-7 13:50 | 显示全部楼层
楼主辛苦了

使用特权

评论回复
xiaoqizi| | 2020-8-7 13:51 | 显示全部楼层
感谢楼主分享

使用特权

评论回复
木木guainv| | 2020-8-7 13:52 | 显示全部楼层
这是一个外接模块吗

使用特权

评论回复
磨砂| | 2020-8-7 13:53 | 显示全部楼层
代码很详细

使用特权

评论回复
晓伍| | 2020-8-7 13:54 | 显示全部楼层
真的很不错

使用特权

评论回复
jinglixixi|  楼主 | 2020-8-7 15:54 | 显示全部楼层

感谢支持!

使用特权

评论回复
jinglixixi|  楼主 | 2020-8-7 15:55 | 显示全部楼层
木木guainv 发表于 2020-8-7 13:52
这是一个外接模块吗

YES   

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

446

主题

2675

帖子

36

粉丝