完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
在lcd1602液晶上显示DS1302的时间信息,先上程序 先上main.c #include ***it DS1302_CE = P3^5; ***it DS1302_CK = P3^6; ***it DS1302_IO = P3^4; bit flag200ms = 0; //200ms定时标志 unsigned char T0RH = 0; //T0重载值的高字节 unsigned char T0RL = 0; //T0重载值的低字节 void Configtimer0(unsigned int ms); void InitDS1302(); void DS1302BurstRead(unsigned char *dat); extern void InitLcd1602(); extern void LcdShowStr(unsigned char x, unsigned char y, unsigned char *str); void main() { unsigned char psec=0xAA; //秒备份,初值AA确保首次读取时间后会刷新显示 unsigned char time[8]; //当前时间数组 unsigned char str[12]; //字符串转换缓冲区 EA = 1; //开总中断 ConfigTimer0(1); //T0定时1ms InitDS1302(); //初始化实时时钟 InitLcd1602(); //初始化液晶 while (1) { if (flag200ms) //每200ms读取依次时间 { flag200ms = 0; DS1302BurstRead(time); //读取DS1302当前时间 if (psec != time[0]) //检测到时间有变化时刷新显示 { str[0] = '2'; //添加年份的高2位:20 str[1] = '0'; str[2] = (time[6] >> 4) + '0'; //“年”高位数字转换为ASCII码 str[3] = (time[6]&0x0F) + '0'; //“年”低位数字转换为ASCII码 str[4] = '-'; //添加日期分隔符 str[5] = (time[4] >> 4) + '0'; //“月” str[6] = (time[4]&0x0F) + '0'; str[7] = '-'; str[8] = (time[3] >> 4) + '0'; //“日” str[9] = (time[3]&0x0F) + '0'; str[10] = ' |