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

📄 i2c.lst

📁 上学时做的一个51单片机按键显示程序
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.07   I2C                                                                   11/25/2005 20:22:01 PAGE 1   


C51 COMPILER V7.07, COMPILATION OF MODULE I2C
OBJECT MODULE PLACED IN i2c.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE i2c.c BROWSE DEBUG OBJECTEXTEND

stmt level    source

   1          /*
   2          * Copyright(c)2005 - 2009 danise .China
   3          * All rights reserved.
   4          * Redistribution and use in source and bianry forms
   5          * with or without modification ,are permitted provided
   6          * that following conditions are met:
   7          * 
   8          * 1.Redistrubution of source code must retain the 
   9          * above copyright notice,this list of conditions and
  10          * following disclaimer.
  11          * 
  12          * 2.Redistributions in binary form must reproduce the 
  13          * above copyright notice,this list of conditions and 
  14          * following disclaimer in the documentation and /or other
  15          * materials provided with the distribution.
  16          * 
  17          * Alternately, this acknowledgment may appear in the software
  18          * itself,if and wherever such third-party acknowledgements
  19          * normally appear.
  20          *
  21          * This software is designed for key board and led display.
  22          * 
  23                  
  24          */
  25          #include "./include/i2c.h"
  26          #include "./include/global.h"
  27          #include "./include/display.h"
  28          #include "./include/system.h"
  29          
  30          UINT8 idata I2CRC = 0;
  31          UINT8 idata i2cbuf[13];
  32          UINT8 idata i2recvbuf[13] ;//= {4,0x22,0x41,0x05};
  33          UINT8 i2cSendOk=0;
  34          UINT8 i2cRecvOk=0;
  35          
  36          UINT8 sendindex = 0;
  37          UINT8 recvindex = 0;
  38          UINT16 i2cChkCount=0;
  39          
  40          bit RcvByte(UINT8 *c)
  41          { I2CON = RELEASE_BUS_ACK;              /* 清除标志位                           */
  42   1        while( SI==0 );                               /* 放开总线,等待接收           */
  43   1        if( I2STAT==0xA0 )                            /* 接收到停止位或重新启动位 */
  44   1        { I2CON = RELEASE_BUS_ACK;            /* 先放开总线,再返回0          */
  45   2          return(0);
  46   2        }
  47   1        *c = I2DAT;                                   /* 取数据                                       */
  48   1        return(1);
  49   1      }
  50          /*
  51          
  52          */
  53          
  54          
  55          bit SendByte(UINT8 c)
C51 COMPILER V7.07   I2C                                                                   11/25/2005 20:22:01 PAGE 2   

  56          { if( I2STAT==0xC0 )                /* 上次发送数据后,接收到非应答位 */
  57   1        { I2CON = RELEASE_BUS_ACK;
  58   2          return(0);
  59   2        }
  60   1        I2DAT = c;                                            /* 发送数据                                     */
  61   1        I2CON = RELEASE_BUS_ACK;              /* 释放总线                                     */
  62   1        while( SI==0 );                                       /* 等待字节数据发送完成         */
  63   1        return(1);
  64   1      }
  65          /*
  66                  
  67          */
  68          void SetBus(UINT8 addr)
  69          { I2ADR = addr&0xfe;            /* 设置从地址不接收广播地址                     */
  70   1        I2CON =  RELEASE_BUS_ACK; /* 启动硬件I2C                                              */
  71   1      }
  72          
  73          /*
  74          */
  75          void I2CISR(void) interrupt 6 
  76          {
  77   1              bit i2csendresult = 0;
  78   1              bit i2crecvresult = 0;
  79   1              
  80   1              UINT8 temp = 0;
  81   1              sendindex = 0;
  82   1              recvindex = 0;
  83   1              
  84   1              CPL932_ET0=0;
  85   1              EI2C=0;
  86   1              elapsetime = 0;
  87   1              I2CRC= 0;
  88   1              sreensaveclk = 0; /* clr screen save */
  89   1              scrflag = 0;      /* stop screen save */
  90   1              switch(I2STAT)
  91   1              {
  92   2                      case RDSLA:     while(1)/* Sending */
  93   2                                              { 
  94   3                                                      EA =0;
  95   3                                                      i2csendresult=SendByte(i2cbuf[sendindex++]);
  96   3                                                      EA =1;
  97   3                                                      if(!i2csendresult){
  98   4                                                              i2cSendOk = 0x1;
  99   4                                                              break;
 100   4                                                      }
 101   3                                                      if( sendindex>i2cbuf[0] ){
 102   4                                                              i2cSendOk = 0x1;
 103   4                                                              break;                                                  
 104   4                                                      }
 105   3                                                      if(elapsetime>=40){
 106   4                                                              /*1 s*/ 
 107   4                                                              i2cSendOk=0x0;/* fail testing by time elapse */
 108   4                                                              break;
 109   4                                                      }
 110   3                                              }
 111   2                                              
 112   2                               break;
 113   2                      case WRSLA: if(0x0 == i2cRecvOk){ //if_1
 114   3                                              while(1)/* receiving */
 115   3                                                      {// while
 116   4                                                              EA =0;
 117   4                                                              i2crecvresult= RcvByte(&temp);
C51 COMPILER V7.07   I2C                                                                   11/25/2005 20:22:01 PAGE 3   

 118   4                                                              EA =1;
 119   4                                                              if(!i2crecvresult){
 120   5                                                              //      I2CRC=I2CRC+temp;  /* ? */
 121   5                                                                      if( 0xff == I2CRC )
 122   5                                                                              i2cRecvOk = 1;
 123   5                                                                      else
 124   5                                                                         i2cRecvOk = 0;
 125   5                                                                      break;                                                                                                          
 126   5                                                              }
 127   4                                                              i2recvbuf[recvindex++]=temp;
 128   4                                                              I2CRC=I2CRC+temp;
 129   4                                                              if(recvindex > i2recvbuf[0]){
 130   5                                                                      if( I2CRC == 0xff ){
 131   6                                                                              i2cRecvOk = 1;
 132   6                                                                      }
 133   5                                                                      else 
 134   5                                                                      i2cRecvOk =0;
 135   5                                                                      break;
 136   5                                                                      
 137   5                                                              }
 138   4      
 139   4                                                              if(elapsetime>=50){
 140   5                                                                      /*1 s*/ 
 141   5                                                                      i2cRecvOk = 0;/* reception testing by time elapse */
 142   5                                                                      break;
 143   5                                                              }       
 144   4                                                      

⌨️ 快捷键说明

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