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

📄 i2c.lst

📁 171544C8051F020应用程序包.rar
💻 LST
📖 第 1 页 / 共 3 页
字号:
C51 COMPILER V6.23a  I2C                                                                   12/20/2002 12:46:27 PAGE 1   


C51 COMPILER V6.23a, COMPILATION OF MODULE I2C
OBJECT MODULE PLACED IN I2C.OBJ
COMPILER INVOKED BY: C:\KEIL\C51\BIN\C51.EXE I2C.c DB OE

stmt level    source

   1          #include <c8051f020.h>                                  // SFR declarations
   2          
   3          //------------------------------------------------------------------------------------
   4          // Global CONSTANTS
   5          //------------------------------------------------------------------------------------
   6          
   7          #define         WRITE   0x00                                            // SMBus WRITE command
   8          #define         READ    0x01                                            // SMBus READ command
   9          
  10          // Device addresses (7 bits, lsb is a don't care)
  11          #define         CLOCK3530_ADDRESS_RESET         0x60            //1 ack
  12          #define         CLOCK3530_ADDRESS_STATUS        0x62            //2 ack
  13          #define         CLOCK3530_ADDRESS_DATEHOUR      0x64            //8 ack  year month day week hour minute second
  14          #define         CLOCK3530_ADDRESS_HOUR          0x66            //4 ack  hour minute second
  15          #define         CLOCK3530_ADDRESS_INT1          0x68            //3 ack  
  16          #define         CLOCK3530_ADDRESS_INT2          0x6A            //3 ack  
  17          
  18          union 
  19          {
  20          unsigned char ClockString[7];
  21          struct RealClock
  22                  {
  23                          unsigned char Year,Month,Day,Week,Hour,Minute,Second;
  24                  } RT;
  25          } RealTime;
  26          
  27          
  28          // SMBus states:
  29          // MT = Master Transmitter
  30          // MR = Master Receiver
  31          #define SMB_BUS_ERROR   0x00                    // (all modes) BUS ERROR
  32          #define SMB_START               0x08                    // (MT & MR) START transmitted
  33          #define SMB_RP_START    0x10                    // (MT & MR) repeated START
  34          #define SMB_MTADDACK    0x18                    // (MT) Slave address + W transmitted;
  35                                                                                          //  ACK received
  36          #define SMB_MTADDNACK   0x20                    // (MT) Slave address + W transmitted;
  37                                                                                          //  NACK received
  38          #define SMB_MTDBACK             0x28                    // (MT) data byte transmitted; ACK rec'vd
  39          #define SMB_MTDBNACK    0x30                    // (MT) data byte transmitted; NACK rec'vd
  40          #define SMB_MTARBLOST   0x38                    // (MT) arbitration lost
  41          #define SMB_MRADDACK    0x40                    // (MR) Slave address + R transmitted;
  42                                                                                          //  ACK received
  43          #define SMB_MRADDNACK   0x48                    // (MR) Slave address + R transmitted;
  44                                                                                          //  NACK received
  45          #define SMB_MRDBACK             0x50                    // (MR) data byte rec'vd; ACK transmitted
  46          #define SMB_MRDBNACK    0x58                    // (MR) data byte rec'vd; NACK transmitted
  47          
  48          
  49          //-----------------------------------------------------------------------------------
  50          //Global VARIABLES
  51          //-----------------------------------------------------------------------------------
  52          char COMMAND;                   // Holds the slave address + R/W bit for use in the SMBus ISR.
  53          
  54          unsigned char *I2CDataBuff;                                             
  55          
C51 COMPILER V6.23a  I2C                                                                   12/20/2002 12:46:27 PAGE 2   

  56          char BYTE_NUMBER;                                                       // Used by ISR to check what data has just been
  57                                                                                                          // sent - High address byte, Low byte, or data byte
  58          
  59          unsigned char HIGH_ADD, LOW_ADD;                // High & Low byte for EEPROM memory address
  60                                          
  61          bit SM_BUSY;                                                            // This bit is set when a send or receive
  62                                                                                                          // is started. It is cleared by the
  63                                                                                                          // ISR when the operation is finished.
  64          
  65          
  66          //------------------------------------------------------------------------------------
  67          // Function PROTOTYPES
  68          //------------------------------------------------------------------------------------
  69          
  70          void SMBus_ISR (void);                                                          
  71          
  72          //------------------------------------------------------------------------------------
  73          // MAIN Routine
  74          //------------------------------------------------------------------------------------
  75          //
  76          // Main routine configures the crossbar and SMBus, and tests
  77          // the SMBus interface between the three EEPROMs
  78          
  79          
  80          void ResetRealClock(void)
  81          {
  82   1              while (SM_BUSY);                                                                        // Wait for SMBus to be free.
  83   1              SM_BUSY = 1;                                                                            // Occupy SMBus (set to busy)
  84   1              SMB0CN = 0x44;                                                                          // SMBus enabled, ACK on acknowledge cycle
  85   1              BYTE_NUMBER = 0;                                                                        // 2 address bytes.
  86   1              COMMAND = (CLOCK3530_ADDRESS_RESET | READ);             // Chip select + READ
  87   1              STA = 1;                                                                                        // Start transfer
  88   1              while (SM_BUSY);                                                                        // Wait for transfer to finish
  89   1      }
  90          
  91          //======================写S-3530A内部实时数据寄存器程序=====================
  92          //功能:将设定年、月、日、星期、时、分、秒数据写入S-3530A                  |
  93          //入口:发送数据放在年、月、日、星期、时、分、秒各寄存器                   |
  94          //出口:NONE                                                               |
  95          //==========================================================================
  96          void SetRealClock(void)
  97          {
  98   1              while (SM_BUSY);                                                                        // Wait for SMBus to be free.
  99   1              SM_BUSY = 1;                                                                            // Occupy SMBus (set to busy)
 100   1              SMB0CN = 0x44;                                                                          // SMBus enabled, ACK on acknowledge cycle
 101   1              BYTE_NUMBER = 7;                                                                        // 2 address bytes.
 102   1              COMMAND = (CLOCK3530_ADDRESS_DATEHOUR | WRITE);         // Chip select + WRITE
 103   1              I2CDataBuff = &RealTime.ClockString[0];                         // Data to be writen
 104   1              STA = 1;                                                                                        // Start transfer
 105   1      }
 106          
 107          //==================读S-3530A实时数据寄存器子程序===========================
 108          //功能:从S-3530A读入当前时间数据                                          |
 109          //入口:NONE                                                               |
 110          //出口:接收数据放在年、月、日、星期、时、分、秒各寄存器                   |
 111          //==========================================================================
 112          void GetRealClock(void)
 113          {
 114   1              while (SM_BUSY);                                                                        // Wait for SMBus to be free.
 115   1              SM_BUSY = 1;                                                                            // Occupy SMBus (set to busy)
 116   1              SMB0CN = 0x44;                                                                          // SMBus enabled, ACK on acknowledge cycle
 117   1              BYTE_NUMBER = 7;                                                                        // 2 address bytes.
C51 COMPILER V6.23a  I2C                                                                   12/20/2002 12:46:27 PAGE 3   

 118   1              COMMAND = (CLOCK3530_ADDRESS_DATEHOUR | READ);          // Chip select + READ
 119   1              I2CDataBuff = &RealTime.ClockString[0];                         // Data to be writen
 120   1              STA = 1;                                                                                        // Start transfer
 121   1              while (SM_BUSY);                                                                        // Wait for transfer to finish
 122   1      }
 123          
 124          //============================写状态寄存器程序==============================
 125          //功能:读/写S-3530A状态寄存器,对S-3530A进行设置                          |
 126          //入口:NONE           出口:NONE                                          |
 127          //==========================================================================
 128          unsigned char  GetRealClockStatus(void)
 129          {
 130   1              unsigned char result; 
 131   1              while (SM_BUSY);                                                                        // Wait for SMBus to be free.
 132   1              SM_BUSY = 1;                                                                            // Occupy SMBus (set to busy)
 133   1              SMB0CN = 0x44;                                                                          // SMBus enabled, ACK on acknowledge cycle
 134   1              BYTE_NUMBER = 1;                                                                        
 135   1              COMMAND = (CLOCK3530_ADDRESS_STATUS | READ);            
 136   1              I2CDataBuff = &result;                                                          
 137   1              STA = 1;                                                                                        // Start transfer
 138   1              while (SM_BUSY);                                                                        // Wait for transfer to finish
 139   1              return result;
 140   1      }
 141          void SetRealClockStatus(unsigned char status)
 142          {
 143   1              while (SM_BUSY);                                                                        // Wait for SMBus to be free.
 144   1              SM_BUSY = 1;                                                                            // Occupy SMBus (set to busy)
 145   1              SMB0CN = 0x44;                                                                          // SMBus enabled, ACK on acknowledge cycle
 146   1              BYTE_NUMBER = 1;                                                                        
 147   1              COMMAND = (CLOCK3530_ADDRESS_STATUS | WRITE);           
 148   1              I2CDataBuff = &status;                                                          
 149   1              STA = 1;                                                                                        // Start transfer
 150   1      }
 151          /*
 152          void  SetRealClockINT1(unsigned int Int1)
 153          {
 154                  while (SM_BUSY);                                                                        // Wait for SMBus to be free.
 155                  SM_BUSY = 1;                                                                            // Occupy SMBus (set to busy)
 156                  SMB0CN = 0x44;                                                                          // SMBus enabled, ACK on acknowledge cycle

⌨️ 快捷键说明

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