找回密码
 注册会员
更新自动建库工具PCB Footprint Expert 2024.04 Pro / Library Expert 破解版

求大神看一下这个程序有问题吗?

[复制链接]
lfeng_13 发表于 2017-4-13 20:56:45 | 显示全部楼层 |阅读模式

本文包含原理图、PCB、源代码、封装库、中英文PDF等资源

您需要 登录 才可以下载或查看,没有账号?注册会员

×
#ifndef _ds1302_h_
#define _ds1302_h_
sbit T_RST=P3^5;
sbit T_CLK=P3^6;
sbit T_IO=P3^4;

sbit ACC0=ACC^0;
sbit ACC7=ACC^7;
typedef struct systemtime
{
   uchar second;
        uchar minute;
        uchar hour;
        uchar week;
        uchar day;
        uchar month;
        uchar year;
        uchar DateString[9];
        uchar TimeString[9];
}systemtime;        //定义的时间类型
/*向DS1302中写入1BYTE数据*/
void writeB(uchar ucda)
{
   uchar i;
   ACC=ucda;
        for(i=8;i>0;i--)
          {
            T_IO=ACC0;
                 T_CLK=1;
                 T_CLK=0;
                 ACC=ACC>>1;
          }
//        T_IO=0;
}
/*从DS1302中读出1BYTE数据*/
uchar readB()
{
  uchar i;
  for(i=8;i>0;i--)
    {
           ACC=ACC>>1;
                ACC7=T_IO;
                T_CLK=1;
                T_CLK=0;
         }
  return(ACC);
}
/*单字节读,向DS1302某地址中读出数据,
  先写地址后写命令/数据*************/
uchar r_ds1302(uchar ucaddr)
{
  uchar ucda;
  T_RST=0;
  T_CLK=0;
  T_RST=1;
  writeB(ucaddr);
  ucda=readB();
  T_CLK=1;
  T_RST=0;
  return(ucda);
}
/**********************************
读取 DS1302当前时间,
格式为:
   秒,分,时,日,月,星期,年
**********************************/
void get_ds1302(systemtime *Time)
{
   uchar readtime;
   readtime = r_ds1302(0x81);  //秒寄存器读操作0x81
        Time->second = ((readtime&0x70)>>4)*10 + (readtime&0x0f); //十位+个位
        readtime = r_ds1302(0x83);  //分寄存器读操作0x83
        Time->minute = ((readtime&0x70)>>4)*10 + (readtime&0x0f);
        readtime = r_ds1302(0x85);
        Time->hour = ((readtime&0x70)>>4)*10 + (readtime&0x0f);
        readtime = r_ds1302(0x87);
        Time->day = ((readtime&0x70)>>4)*10 + (readtime&0x0f);       

        readtime = r_ds1302(0x89);
        Time->month = ((readtime&0x70)>>4)*10 + (readtime&0x0f);
        readtime = r_ds1302(0x8d);
        Time->year = ((readtime&0x70)>>4)*10 + (readtime&0x0f);

          //将十进制数转换为液晶显示的ASCII值
        Time->DateString[0] = Time->year/10 + '0';
        Time->DateString[1] = Time->year%10 + '0';
        Time->DateString[2] = '-';
        Time->DateString[3] = Time->month/10 + '0';
        Time->DateString[4] = Time->month%10 + '0';
        Time->DateString[5] = '-';
        Time->DateString[6] = Time->day/10 + '0';
        Time->DateString[7] = Time->day%10 + '0';
        Time->DateString[8] = '\0';

        //将十进制数转换为液晶显示的ASCII值
        Time->TimeString[0] = Time->hour/10 + '0';
        Time->TimeString[1] = Time->hour%10 + '0';
        Time->TimeString[2] = ':';
        Time->TimeString[3] = Time->minute/10 + '0';
        Time->TimeString[4] = Time->minute%10 + '0';
        Time->TimeString[5] = ':';
        Time->TimeString[6] = Time->second/10 + '0';
        Time->TimeString[7] = Time->second%10 + '0';
        Time->TimeString[8] = '\0';
}
#endif

*滑块验证:
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

QQ|手机版|MCU资讯论坛 ( 京ICP备18035221号-2 )|网站地图

GMT+8, 2024-12-23 12:09 , Processed in 0.081291 second(s), 12 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表