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

📄 i2c.lst

📁 c8051单片机程序包,keil C编写
💻 LST
📖 第 1 页 / 共 3 页
字号:
C51 COMPILER V7.02b   I2C                                                                  12/21/2002 22:32:37 PAGE 1   


C51 COMPILER V7.02b, COMPILATION OF MODULE I2C
OBJECT MODULE PLACED IN I2C.OBJ
COMPILER INVOKED BY: D:\keil702\C51\BIN\C51.EXE I2C.c OPTIMIZE(0,SPEED) BROWSE DEBUG OBJECTEXTEND

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 V7.02b   I2C                                                                  12/21/2002 22:32:37 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 V7.02b   I2C                                                                  12/21/2002 22:32:37 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
 157                  BYTE_NUMBER = 2;                                                                        
 158                  COMMAND = (CLOCK3530_ADDRESS_INT1 | WRITE);             
 159                  I2CDataBuff = (unsigned char*)&Int1;                                                            
 160                  STA = 1;                                                                                        // Start transfer
 161          }
 162          */
 163          #include "INTRINS.H"
 164          
 165          unsigned char revolve(unsigned char val)
 166          {
 167   1      char i;
 168   1      unsigned char val1=0;
 169   1              for (i=0;i<8;i++)
 170   1              {
 171   2                      if (val&0x1)
 172   2                              val1++;
 173   2                      val1=_crol_(val1,1);
 174   2                      val=_cror_(val,1);
 175   2              }
 176   1              val1=_cror_(val1,1);
 177   1              return val1;
 178   1      }
 179          
C51 COMPILER V7.02b   I2C                                                                  12/21/2002 22:32:37 PAGE 4   

 180          /*--  文字:  时  --*/
 181          char code Shi[]=
 182          {
 183                  0x00,0x00,0xFC,0x44,0x44,0xFC,0x00,0x08,0x48,0x88,0x08,0xFF,0x08,0x08,0x08,0x00,
 184                  0x00,0x00,0x1F,0x04,0x04,0x0F,0x00,0x00,0x00,0x11,0x20,0x1F,0x00,0x00,0x00,0x00,
 185          };
 186          /*--  文字:  钟  --*/
 187          char code Zhong[]=
 188          {
 189                  0x00,0x60,0x38,0xE7,0x24,0x24,0x04,0x00,0xF8,0x88,0x88,0xFF,0x88,0x88,0xF8,0x00,
 190                  0x00,0x01,0x01,0x3F,0x11,0x09,0x01,0x00,0x01,0x00,0x00,0x3F,0x00,0x00,0x01,0x00,
 191          };
 192          /*--  文字:  修  --*/
 193          char code xiu[]=
 194          {
 195                  0x00,0x20,0x10,0xFC,0x03,0xF8,0x10,0x88,0x47,0x2C,0x94,0x2C,0x46,0x44,0x40,0x00,
 196                  0x00,0x00,0x00,0x3F,0x00,0x2F,0x20,0x2A,0x2A,0x15,0x14,0x0A,0x09,0x04,0x00,0x00,
 197          };
 198          /*--  文字:  改  --*/
 199          char code gai[]=
 200          {
 201                  0x00,0x04,0xC4,0x44,0x44,0x44,0x7E,0x44,0x30,0xDF,0x10,0x10,0xF0,0x18,0x10,0x00,
 202                  0x00,0x00,0x1F,0x10,0x08,0x08,0x24,0x20,0x10,0x0B,0x04,0x0A,0x11,0x20,0x20,0x00,
 203          };
 204          /*--  文字:  改  --*/
 205          char code Blank[]=
 206          {
 207                  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 208                  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 209          };
 210          
 211          void LCD_WriteHZ(char x,char y,char *Dot);
 212          void LCD_DispChar(char x,char y,char ch); //128*64  取值x=0-128 y=0-8
 213          void InitLCD(void);
 214          void Delay1ms(unsigned char T);

⌨️ 快捷键说明

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