【TB作品】MSP430单片机 Proteus仿真 DS1302 时钟的设置与显示

2023-05-16

读取与显示

Burst模式连续读取到DS1302数组,存放顺序是 秒、分、时、日、月、周、年。


void main(void)
{
    char cnt=0;
    unsigned char disp[16];

    WDTCTL = WDTPW + WDTHOLD; /* 关闭看门狗 */
    P1DIR = 0xFF; /* 设置方向 */
    P1SEL = 0; /* 设置为普通I/O 口 */

    P2DIR = 0xFF; /* 设置方向 */
    P2SEL = 0; /* 设置为普通I/O 口 */

    P2OUT = 0x00;
    P1OUT = 0x00;
    delay_ms(200);
    LCD_init();
//    LCD_dsp_string(1, 1, "QQ742971636");

    DS1302[0]=58;//秒
    DS1302[1]=59;//分
    DS1302[2]=23;//时

    DS1302[3]=31;//日
    DS1302[4]=1;//月
    DS1302[6]=0;//年

    DS1302[5]=1;//星期
    Init_DS1302();

    while (1)
    {
        Read_DS1302_Burst_Mode();

        cnt=0;
        disp[cnt++]=DS1302[6]/10+'0';
        disp[cnt++]=DS1302[6]%10+'0';
        disp[cnt++]='-';
        disp[cnt++]=DS1302[4]/10+'0';
        disp[cnt++]=DS1302[4]%10+'0';
        disp[cnt++]='-';
        disp[cnt++]=DS1302[3]/10+'0';
        disp[cnt++]=DS1302[3]%10+'0';
        disp[cnt++]=0;
        LCD_dsp_string(0, 1, disp);


        cnt=0;
        disp[cnt++]=DS1302[2]/10+'0';
        disp[cnt++]=DS1302[2]%10+'0';
        disp[cnt++]=':';
        disp[cnt++]=DS1302[1]/10+'0';
        disp[cnt++]=DS1302[1]%10+'0';
        disp[cnt++]=':';
        disp[cnt++]=DS1302[0]/10+'0';
        disp[cnt++]=DS1302[0]%10+'0';
        disp[cnt++]=0;
        LCD_dsp_string(0, 2, disp);

        switch(DS1302[5])
        {
            case 1:  LCD_dsp_string(12, 2, "MON");break;
            case 2:  LCD_dsp_string(12, 2, "TUE");break;
            case 3:  LCD_dsp_string(12, 2, "WED");break;
            case 4:  LCD_dsp_string(12, 2, "THU");break;
            case 5:  LCD_dsp_string(12, 2, "FRI");break;
            case 6:  LCD_dsp_string(12, 2, "SAT");break;
            case 7:  LCD_dsp_string(12, 2, "SUN");break;
        }

        delay_ms(100);
    }
}

仿真图:
在这里插入图片描述

DS1302寄存器介绍

写入0x80到0x8c即可。
在这里插入图片描述

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

【TB作品】MSP430单片机 Proteus仿真 DS1302 时钟的设置与显示 的相关文章

随机推荐