好文档 - 专业文书写作范文服务资料分享网站

基于51单片机的多功能数字时钟系统设计 (附完整程序版)

天下 分享 时间: 加入收藏 我要投稿 点赞

}

return(ACC); }

void Write1302(unsigned char ucAddr, unsigned char ucDa) {

DS1302_RST = 0; DS1302_CLK = 0; DS1302_RST = 1;

DS1302InputByte(ucAddr); DS1302_CLK = 1; DS1302_RST = 0; }

unsigned char Read1302(unsigned char ucAddr) {

unsigned char ucData; DS1302_RST = 0; DS1302_CLK = 0; DS1302_RST = 1;

DS1302InputByte(ucAddr|0x01); // 地址,命令 ucData = DS1302OutputByte(); // 读1Byte数据 DS1302_CLK = 1; DS1302_RST = 0; return(ucData); }

void DS1302_GetTime(SYSTEMTIME *Time) //获取时钟芯片的时钟数据到自定义的结构型数组 {

unsigned char ReadValue;

ReadValue = Read1302(DS1302_SECOND);

Time->Second = ((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F); //高三位取出读出乘⑩ ReadValue = Read1302(DS1302_MINUTE);

Time->Minute = ((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F); ReadValue = Read1302(DS1302_HOUR);

Time->Hour = ((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F); ReadValue = Read1302(DS1302_DAY);

Time->Day = ((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F); ReadValue = Read1302(DS1302_WEEK);

Time->Week = ((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F); ReadValue = Read1302(DS1302_MONTH);

//读取DS1302某地址的数据 // 地址,命令

DS1302InputByte(ucDa); // 写1Byte数据

//

Write1302(0x8e,0x00);

//ucAddr: DS1302地址, ucData: 要写的数据

}

Time->Month = ((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F); ReadValue = Read1302(DS1302_YEAR);

Time->Year = ((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F);

void DateToStr(SYSTEMTIME *Time) //将时间年,月,日,星期数据转换成液晶显示字符串,放到数组里DateString[] {

if(hide_year<2) //这里的if,else语句都是判断位闪烁,<2显示数据,>2就不显示,输出字符串为 2007/07/22

{

if(hide_month<2) {

Time->DateString[5] = Time->Month/10 + '0'; Time->DateString[6] = Time->Month + '0'; } else {

Time->DateString[4] = '/'; Time->DateString[0] = '2'; Time->DateString[1] = '0';

Time->DateString[2] = Time->Year/10 + '0'; Time->DateString[3] = Time->Year + '0'; } else {

Time->DateString[0] = ' '; Time->DateString[1] = ' '; Time->DateString[2] = ' '; Time->DateString[3] = ' ';

}

Time->DateString[5] = ' '; Time->DateString[6] = ' '; }

Time->DateString[7] = '/';

if(hide_day<2) {

Time->DateString[8] = Time->Day/10 + '0'; Time->DateString[9] = Time->Day + '0'; } else {

Time->DateString[8] = ' '; Time->DateString[9] = ' '; }

if(hide_week<2) {

week_value[0] = Time->Week + '0'; //星期的数据另外放到 week_value[]数组里,跟年,月,日的分} else {

week_value[0] = ' '; }

week_value[1] = '\\0';

开存放,因为等一下要在最后显示

}

void TimeToStr(SYSTEMTIME *Time) //将时,分,秒数据转换成液晶显示字符放到数组 TimeString[]; {

if(hide_hour<2) {

Time->TimeString[2] = ':';

Time->TimeString[0] = Time->Hour/10 + '0'; Time->TimeString[1] = Time->Hour + '0'; } else {

Time->TimeString[0] = ' '; Time->TimeString[1] = ' ';

}

Time->DateString[10] = '\\0'; //字符串末尾加 '\\0' ,判断结束字符

if(hide_min<2)

if(hide_sec<2) {

Time->TimeString[6] = Time->Second/10 + '0'; Time->TimeString[7] = Time->Second + '0'; Time->TimeString[5] = ':'; {

Time->TimeString[3] = Time->Minute/10 + '0'; Time->TimeString[4] = Time->Minute + '0'; } else {

Time->TimeString[3] = ' '; Time->TimeString[4] = ' ';

}

} else {

Time->TimeString[6] = ' '; }

Time->TimeString[7] = ' '; Time->DateString[8] = '\\0'; }

基于51单片机的多功能数字时钟系统设计 (附完整程序版)

}return(ACC);}voidWrite1302(unsignedcharucAddr,unsignedcharucDa){DS1302_RST=0;DS1302_CLK=0;DS1302_RST=1;DS1302InputByte(uc
推荐度:
点击下载文档文档为doc格式
1w93s3mdlm7f2vc1ug0p
领取福利

微信扫码领取福利

微信扫码分享