eeprom_ht1380.lst

来自「自己的平时一些制作 现在整理一下 与大家一起分享」· LST 代码 · 共 530 行 · 第 1/2 页

LST
530
字号
 249   1      SCL=1;
 250   1      _nop_();
 251   1      _nop_();
 252   1      _nop_();
 253   1      _nop_();
 254   1      CY=SDA;                                 /* 应答位返回值在CY中,0有效 */
 255   1      SCL=0;
 256   1      return(CY);
 257   1      }
 258          /***************
 259          对IIC总线产生应答
 260          ***************/
 261          
 262          void IICAck(void)
 263          {
 264   1      SDA=0;
 265   1      SCL=1;
 266   1      _nop_();
 267   1      _nop_();
 268   1      _nop_();
 269   1      _nop_();
 270   1      SCL=0;
 271   1      _nop_();
 272   1      SDA=1;
 273   1      }
 274          
 275          /*****************
 276          不对IIC总线产生应答
 277          *****************/
 278          void IICNoAck(void)
 279          {
 280   1      SDA=1;
 281   1      SCL=1;
 282   1      _nop_();
 283   1      _nop_();
 284   1      _nop_();
 285   1      _nop_();
 286   1      SCL=0;
 287   1      }
 288          
 289          /*******************
 290             向IIC总线写数据
 291          *******************/
 292          void IICSendByte(unsigned char sendbyte)
 293          {
 294   1      unsigned char data j=8;
 295   1      for(;j>0;j--)
 296   1      {
 297   2      SCL=0;
 298   2      sendbyte<<=1;  /* 发送字节变量sendbyte左移1位,CY=sendbyte^7,并回存 */
 299   2      SDA=CY;
 300   2      SCL=1;
 301   2      }
 302   1      SCL=0;
 303   1      }
C51 COMPILER V7.20   EEPROM_HT1380                                                         06/19/2007 13:42:25 PAGE 6   

 304          
 305          /********************
 306          从IIC总线读数据子程序
 307          ********************/
 308          unsigned char IICReceiveByte(void)
 309          {
 310   1      register receivebyte,i=8;
 311   1      SCL=0;
 312   1      while(i--)
 313   1      {
 314   2      SCL=1;
 315   2      receivebyte=(receivebyte<<1)|SDA;
 316   2      SCL=0;
 317   2      }
 318   1      return(receivebyte);
 319   1      }
 320          
 321          
 322          
 323          /******按键接口描述********/
 324          //左第一 二 三 四 个按键分别对应于 P2.7 P2.6 P2.5 P2.4 
 325          //左第一个按键键值为1 
 326          //左第二个按键键值为2 
 327          //左第三个按键键值为3 
 328          //左第四个按键键值为4
 329           
 330          /******读取按键子程序 getkey()*************/
 331          unsigned char getkey (void)
 332          {    unsigned char k,tem,keytem;
 333   1           keytem=0;
 334   1           tem=P2 & 0xf0;                      //第一次读取按键值
 335   1           if(tem!=0xf0)                      //判断有无按键按下
 336   1           {   
 337   2               for(k=0;k<20;k++)
 338   2               delay(250);             //延时一段时间
 339   2               tem=P2 & 0xf0;         //再次读取按键值
 340   2               if(tem!=0xf0)
 341   2               {    if(tem==0x70) keytem=1;          //表示左第一个按键按下
 342   3                    else if(tem==0xb0) keytem=2;         //表示左第二个按键按下
 343   3                    else if(tem==0xd0) keytem=3;         //表示左第三个按键按下
 344   3                    else if(tem==0xe0) keytem=4;         //表示左第四个按键按下
 345   3               }
 346   2            }
 347   1            
 348   1            while(tem!=0xf0) tem=P2 & 0xf0;  //等待按键释放 
 349   1            return(keytem);                              //返回按键值
 350   1      }
 351          
 352          
 353          /*****定时器初始化程序*******/
 354          void Init_Timer (void)
 355          {
 356   1          TMOD=0x21;
 357   1              TH0=(65536-1000)/256;
 358   1          TL0=(65536-1000)%256;
 359   1          TR0=1;
 360   1          ET0=1;
 361   1          EA=1;
 362   1      } 
 363          
 364          /*****定时器0中断服务程序******/
 365          //显示处理,具体可以参考前面的实验
C51 COMPILER V7.20   EEPROM_HT1380                                                         06/19/2007 13:42:25 PAGE 7   

 366          void timer0() interrupt 1 using 1
 367          {
 368   1          TH0=(65536-1000)/256;
 369   1          TL0=(65536-1000)%256;
 370   1          number=number++;
 371   1          if(number>3) number=0;
 372   1          P2=digit[number];
 373   1          P0=tab[d[number]]; 
 374   1              //在第二个数码管显示时,将最高位的小数点显示出来,这里为冒号
 375   1          if(distime==1 && number==1)  
 376   1             P0=tab[d[number]]+0x80;  
 377   1       }
 378          /*******主函数***********/
 379          //效果:显示 分:秒
 380          void main (void)
 381          {
 382   1        /**EEPROM变量****/ 
 383   1       unsigned char *point_in,*point_out;  //定义输入输出指针
 384   1       unsigned char ii;
 385   1        
 386   1       unsigned char keyboard;         //键值变量
 387   1       unsigned char state=0;          //状态指示 =1设定定时状态  =0正常显示状态
 388   1       unsigned char i,distem,w=3;                //变量
 389   1       /*时钟处理以及定时器初始化*/
 390   1       year=07;month=03;day=0x04;hour=0x19;minute=0x16;second=13; //软件预设时间参数
 391   1      
 392   1                      
 393   1      *point_in=year;
 394   1      *(point_in+1)=month;
 395   1      *(point_in+2)=day;
 396   1      *(point_in+3)=hour;
 397   1      *(point_in+4)=minute;           
 398   1      *(point_in+5)=second;
 399   1      
 400   1      
 401   1      ht1380_rest=0;ht1380_sclk=0;   //选中时钟芯片
 402   1       set_time();                    //设置时间
 403   1       Init_Timer();                  //初始化定时器及全局变量
 404   1      
 405   1      Delay(50);                              /* 检查内部数据区0x30-0x39与0x40-0x49应完全相同 */                
             -   
 406   1      beep=1;
 407   1                      *point_out=year;
 408   1                      *(point_out+1)=month;
 409   1                      *(point_out+2)=day;
 410   1                      *(point_out+3)=hour;
 411   1                      *(point_out+4)=minute+0x01;             
 412   1                      *(point_out+5)=second;
 413   1                      RW24XX(point_out,6,0x0010,0xa0,6);
 414   1      while(1)
 415   1           {
 416   2                      distime=~distime;  // 闪动冒号    
 417   2                      read_time();      //读时间
 418   2      
 419   2                      *point_in=year;
 420   2                      *(point_in+1)=month;
 421   2                      *(point_in+2)=day;
 422   2                      *(point_in+3)=hour;
 423   2                      *(point_in+4)=minute;           
 424   2                      *(point_in+5)=second;
 425   2                  
 426   2                      RW24XX(point_out,6,0x0010,0xa1,6);
C51 COMPILER V7.20   EEPROM_HT1380                                                         06/19/2007 13:42:25 PAGE 8   

 427   2                      
 428   2                      if((*point_in==*point_out) || (*point_in==*point_out)  || (*(point_in+1)==*(point_out+1))  || (*(point_i
             -n+2)==*(point_out+2))  || (*(point_in+3)==*(point_out+3))  || (*(point_in+4)==*(point_out+4))  || (*(point_in+5)==*(poin
             -t_out+5)))
 429   2                      {
 430   3                      beep=0;
 431   3                      }
 432   2              
 433   2                      if(state==0)      //state=0 正常显示状态
 434   2              {
 435   3                 read_time();
 436   3                 d[0]=hour/16;
 437   3                 d[1]=hour %16;
 438   3                 d[2]=minute/16;
 439   3                 d[3]=minute %16;
 440   3              }
 441   2                 
 442   2              else               //较时状态。让需要较时的位闪动
 443   2              {
 444   3                 distem=d[w];
 445   3                 d[w]=10;
 446   3                 for(i=0;i<250;i++)
 447   3                     delay(250);
 448   3                 d[w]=distem;
 449   3                 for(i=0;i<250;i++)
 450   3                     delay(250);
 451   3              }
 452   2                      
 453   2                      keyboard=getkey(); //读按键
 454   2                      
 455   2              if(keyboard==1)    // keyboard=1时,切换转态到较时并且多次..
 456   2              {   
 457   3                              state=1;       // ..按键后会同时向后退到下一位
 458   3                  w++;
 459   3                  if(w>3) w=0; 
 460   3              }
 461   2              else if(keyboard==2)
 462   2              {   
 463   3                              d[w]++;
 464   3                  if(d[w]>9) d[w]=0;
 465   3              }
 466   2              else if(keyboard==3)
 467   2              {   
 468   3                              if(d[w]>0) d[w]--; 
 469   3                      }
 470   2              else if(keyboard==4)
 471   2              {    
 472   3                              hour=d[0]*16+d[1];
 473   3                  minute=d[2]*16+d[3];
 474   3                  second=0;
 475   3                              *point_out=year;
 476   3                              *(point_out+1)=month;
 477   3                              *(point_out+2)=day;
 478   3                              *(point_out+3)=hour;
 479   3                              *(point_out+4)=minute;          
 480   3                              *(point_out+5)=second;
 481   3                              RW24XX(point_out,6,0x0010,0xa0,6);
 482   3                  state=0;
 483   3              }
 484   2                      
 485   2           }
 486   1      }
C51 COMPILER V7.20   EEPROM_HT1380                                                         06/19/2007 13:42:25 PAGE 9   

*** WARNING C280 IN LINE 384 OF EEPROM_HT1380.C: 'ii': unreferenced local variable


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   1439    ----
   CONSTANT SIZE    =     14    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     12      22
   IDATA SIZE       =   ----    ----
   BIT SIZE         =      1       1
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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