⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clock1.lst

📁 单片机用DS1302进行计时
💻 LST
字号:
C51 COMPILER V7.06   CLOCK1                                                                02/10/2009 21:00:44 PAGE 1   


C51 COMPILER V7.06, COMPILATION OF MODULE CLOCK1
OBJECT MODULE PLACED IN clock1.OBJ
COMPILER INVOKED BY: d:\Keil\C51\BIN\C51.EXE clock1.c BROWSE DEBUG OBJECTEXTEND

stmt level    source

   1          sbit rs=P1^0;
*** ERROR C202 IN LINE 1 OF CLOCK1.C: 'P1': undefined identifier
   2          sbit rw=P1^1;
*** ERROR C202 IN LINE 2 OF CLOCK1.C: 'P1': undefined identifier
   3          sbit lcden=P1^2;
*** ERROR C202 IN LINE 3 OF CLOCK1.C: 'P1': undefined identifier
   4          
   5          sbit sclk=P3^7;
*** ERROR C202 IN LINE 5 OF CLOCK1.C: 'P3': undefined identifier
   6          sbit io=P3^5;
*** ERROR C202 IN LINE 6 OF CLOCK1.C: 'P3': undefined identifier
   7          sbit rst=P3^6;
*** ERROR C202 IN LINE 7 OF CLOCK1.C: 'P3': undefined identifier
   8          uchar table[]="2009-01-30 MON";
*** ERROR C129 IN LINE 8 OF CLOCK1.C: missing ';' before 'table'
   9          uchar table1[]="00:00:00";
  10          void delay(uint z)
  11          {
  12                  uint x;
  13                  for(;z>0;z--)
  14                          for(x=10;x>0;x--)
  15                          ;
  16          }
  17          void write_com(uchar command)
  18          {
  19                  lcden=0;
  20                  rs=0;
  21                  rw=0;
  22                  P0=command;
  23                  lcden=1;
  24                  delay(1);
  25                  lcden=0;
  26                  
  27          }
  28          void write_data(uchar date)
  29          {
  30                  lcden=0;
  31                  rs=1;
  32                  rw=0;
  33                  P0=date;
  34                  lcden=1;
  35                  delay(1);
  36                  lcden=0;
  37          }
  38          
  39          void init()
  40          {
  41                  write_com(0x38);
  42                  write_com(0x0c);
  43                  write_com(0x06);
  44          }
  45          
  46          /*****************************************
  47          函数名称:write_byte
  48          功能:向DS1302写入一个字节数据(无RST操作)
C51 COMPILER V7.06   CLOCK1                                                                02/10/2009 21:00:44 PAGE 2   

  49          参数:byte 要写入数据
  50          返回值:无
  51          *****************************************/
  52          
  53          void write_byte(uchar byte)
  54          {
  55                  uchar i;                //8位数据计数
  56          
  57                  for(i=0;i<8;i++)
  58                  {
  59                          sclk=0;                 //拉低时钟信号
  60                          io=byte&0x01;   //给数据最低位
  61                          delay(1);               //调整时钟和脉冲宽度
  62                          sclk=1;                 //提供时钟上升沿
  63                          byte=byte>>1;   //数据右移一位,为送出新数据做准备
  64                  }
  65          }
  66          
  67          uchar read_byte(void)           //读一个字节
  68          {
  69                  uchar i,byte=0;
  70                  for(i=0;i<8;i++)
  71                  {
  72                          byte>>=1;               //保存输出数据
  73                          sclk=1;                 //时钟是高电平
  74                          delay(1);               //延时,调整时钟脉冲宽度
  75                          sclk=0;                 //时钟下降沿,准备读数据位
  76                          delay(1);
  77                          if(io==1)               //读出数据位为1,给最高位置1
  78                          byte=byte|0x80;
  79                          if(io==0)               //读出数据位为0,给最高位置0
  80                          byte=byte&0x7f; 
  81                  }
  82                  return byte;            //返回读出数据
  83          }
  84          
  85          void write_D(uchar addr,uchar date)             //向某个地址写入一个字节的数据
  86          {
  87                  rst=0;                  //拉低片选端
  88                  sclk=0;                 //拉低时钟端
  89                  delay(1);
  90                  rst=1;                  //拉高片选端
  91                  delay(1);
  92                  write_byte(addr);               //写入操作命令(地址)
  93                  delay(1);
  94                  sclk=0;                 //拉低时钟端端
  95                  delay(1);
  96                  write_byte(date);               //写入数据
  97                  sclk=0;                 //拉低时钟端
  98                  delay(1);
  99                  rst=0;          //拉低片选端
 100          }
 101          
 102          /*uchar read_D(uchar addr)              //在某地址读一个字节数据
 103          {
 104                  uchar date;
 105                  rst=0;                  //拉低片选端
 106                  sclk=0;                 //拉低时钟端
 107                  delay(1);
 108                  rst=1;                  //拉高片选端
 109                  delay(1);
 110                  write_byte(addr);       //写入操作命令(地址)
C51 COMPILER V7.06   CLOCK1                                                                02/10/2009 21:00:44 PAGE 3   

 111                  delay(1);
 112                  date=read_byte;         //读出数据
 113                  delay(1);
 114                  sclk=0;                         //拉低时钟端
 115                  rst=0;                          //拉低片选端
 116                  return date;            //返回读出数据
 117          
 118          }*/
 119          void set_time(uchar ptime[])            //设置时间
 120          {
 121                  uchar i;
 122              uchar addr=0x80;
 123                  write_D(0x8e|0x00,0x00);                //写入控制命令,WP为0,允许写操作
 124                  delay(200);                                     //稍长延时
 125                  for(i=0;i<7;i++)
 126                  {
 127                          write_D(addr|0x00,ptime[i]);            //写入秒 分 时 日 月 星期 年
 128                          addr=addr+2;                                    //地址加2
 129                          delay(10);
 130                  }
 131                  write_D(0x8e|0x00,0x80);                        //写控制命令,WP为1
 132          }
 133          
 134          void get_time(uchar time[])             //读取当前时间
 135          {
 136                  uchar i;
 137          /****************************************
 138          //单次读写      
 139                  uchar addr=0x80;
 140                  for(i=0;i<7;i++)
 141                  {
 142                          time[i]=read_D(addr|0x00);              //秒 分 时 日 月 星期 年
 143                          addr=addr+2;
 144                  }
 145          *******************************************/
 146          //多字节读取
 147                  rst=0;          //拉低片选
 148                  delay(1);
 149                  rst=1;          //拉高片选
 150                  delay(1);
 151                  write_byte(0xbf);               //写入时钟多字节读取命令 0xbf
 152                  for (i=0;i<8;i++)       //时间数据的存放格式是:
 153              {                        //秒,分,时,日,月,星期,年,控制
 154                  time[i]=read_byte(); //【7个数据(BCD格式)+1个控制】 
 155              }
 156                  rst=0;  //拉低片选
 157          //
 158                  sclk=0;         //拉低时钟端
 159          
 160          }
 161          
 162          void DS_init()  //初始化DS1302
 163          {
 164                  write_D(0x8e|0x00,0x00);                //写入写允许命令
 165                  write_D(0x80|0x00,0x00);                //启动振荡器,DS1302开始工作
 166                  write_D(0x8e|0x00,0x80);                //写控制命令,不允许写操作
 167          
 168          }
 169          
 170          void bcd_asc(uchar bcd,uchar pasc[])
 171          {
 172                  pasc[0]=bcd/16|0x30;    //转换十位
C51 COMPILER V7.06   CLOCK1                                                                02/10/2009 21:00:44 PAGE 4   

 173                  pasc[1]=bcd&0x0f|0x30;          //转换个位
 174          }
 175          
 176          void disp(uchar time[])
 177          {
 178                  uchar i,asc[2];
 179                  uchar line1[11]={0,0,'-',0,0,'-',0,0,' ',0,'\0'};//显示第1行的字符数组
 180                  uchar line2[9]={0,0,':',0,0,':',0,0,'\0'};                //显示第2行的字符数组
 181                  for(i=0;i<3;i++)                //
 182                  {
 183                          bcd_asc(time[2-i],asc);
 184                          line2[i*3]=asc[0];
 185                          line2[i*3+1]=asc[1];
 186                  }
 187                  bcd_asc(time[6],asc);
 188                  line1[0]=asc[0];
 189                  line1[1]=asc[1];
 190                  bcd_asc(time[4],asc);                                             //为第1行的月赋值
 191                  line1[3]=asc[0];
 192                  line1[4]=asc[1];
 193                  bcd_asc(time[3],asc);                                             //为第1行的日赋值
 194                  line1[6]=asc[0];
 195                  line1[7]=asc[1];
 196                  bcd_asc(time[5],asc);                                             //为第1行的星期赋值
 197                  line1[9]=asc[1];
 198          
 199                  write_com(0x80+0x01);
 200                  for(i=0;i<strlen(line1);i++)
 201                  {
 202                          write_data(line1[i]);
 203                  }                                                                                       //显示第一行
 204                  write_com(0x80+0x44);
 205                  for(i=0;i<strlen(line2);i++)
 206                  {
 207                          write_data(line2[i]);
 208                  }                                                                                       //显示第二行
 209          
 210          
 211          }

C51 COMPILATION COMPLETE.  0 WARNING(S),  7 ERROR(S)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -