读取与显示
Burst模式连续读取到DS1302数组,存放顺序是 秒、分、时、日、月、周、年。
void main(void)
{
char cnt=0;
unsigned char disp[16];
WDTCTL = WDTPW + WDTHOLD;
P1DIR = 0xFF;
P1SEL = 0;
P2DIR = 0xFF;
P2SEL = 0;
P2OUT = 0x00;
P1OUT = 0x00;
delay_ms(200);
LCD_init();
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(使用前将#替换为@)