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

📄 sp3530.lst

📁 工业以太网测控板资料FX04核心编程模块
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.05   SP3530                                                                03/19/2007 15:47:59 PAGE 1   


C51 COMPILER V7.05, COMPILATION OF MODULE SP3530
OBJECT MODULE PLACED IN sp3530.OBJ
COMPILER INVOKED BY: C:\SiLabs\MCU\IDEfiles\C51\BIN\C51.exe sp3530.c DB OE

stmt level    source

   1          #include <c8051f040.h>                                  // SFR declarations
   2          #include <intrins.h>
   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.05   SP3530                                                                03/19/2007 15:47:59 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              SFRPAGE   =SMB0_PAGE;
  84   1              SM_BUSY = 1;                                                                            // Occupy SMBus (set to busy)
  85   1              SMB0CN = 0x44;                                                                          // SMBus enabled, ACK on acknowledge cycle
  86   1              BYTE_NUMBER = 0;                                                                        // 2 address bytes.
  87   1              COMMAND = (CLOCK3530_ADDRESS_RESET | READ);             // Chip select + READ
  88   1              STA = 1;                                                                                        // Start transfer
  89   1              while (SM_BUSY);                                                                        // Wait for transfer to finish
  90   1      }
  91          
  92          //======================写S-3530A内部实时数据寄存器程序=====================
  93          //功能:将设定年、月、日、星期、时、分、秒数据写入S-3530A                  |
  94          //入口:发送数据放在年、月、日、星期、时、分、秒各寄存器                   |
  95          //出口:NONE                                                               |
  96          //==========================================================================
  97          void SetRealClock(void)
  98          {
  99   1              while (SM_BUSY);                                                                        // Wait for SMBus to be free.
 100   1              SFRPAGE   =SMB0_PAGE;
 101   1              SM_BUSY = 1;                                                                            // Occupy SMBus (set to busy)
 102   1              SMB0CN = 0x44;                                                                          // SMBus enabled, ACK on acknowledge cycle
 103   1              BYTE_NUMBER = 7;                                                                        // 2 address bytes.
 104   1              COMMAND = (CLOCK3530_ADDRESS_DATEHOUR | WRITE);         // Chip select + WRITE
 105   1              I2CDataBuff = &RealTime.ClockString[0];                         // Data to be writen
 106   1              STA = 1;
 107   1              while (SM_BUSY);                                                                                        // Start transfer
 108   1      }
 109          
 110          //==================读S-3530A实时数据寄存器子程序===========================
 111          //功能:从S-3530A读入当前时间数据                                          |
 112          //入口:NONE                                                               |
 113          //出口:接收数据放在年、月、日、星期、时、分、秒各寄存器                   |
 114          //==========================================================================
 115          void GetRealClock(void)
 116          {
 117   1              while (SM_BUSY);                                                                        // Wait for SMBus to be free.
C51 COMPILER V7.05   SP3530                                                                03/19/2007 15:47:59 PAGE 3   

 118   1              SFRPAGE   =SMB0_PAGE;
 119   1              SM_BUSY = 1;                                                                            // Occupy SMBus (set to busy)
 120   1              SMB0CN = 0x44;                                                                          // SMBus enabled, ACK on acknowledge cycle
 121   1              BYTE_NUMBER = 7;                                                                        // 2 address bytes.
 122   1              COMMAND = (CLOCK3530_ADDRESS_DATEHOUR | READ);          // Chip select + READ
 123   1              I2CDataBuff = &RealTime.ClockString[0];                         // Data to be writen
 124   1              STA = 1;                                                                                        // Start transfer
 125   1              while (SM_BUSY);                                                                        // Wait for transfer to finish
 126   1      }
 127          
 128          //============================写状态寄存器程序==============================
 129          //功能:读/写S-3530A状态寄存器,对S-3530A进行设置                          |
 130          //入口:NONE           出口:NONE                                          |
 131          //==========================================================================
 132          unsigned char  GetRealClockStatus(void)
 133          {
 134   1              unsigned char result; 
 135   1              while (SM_BUSY);                                                                        // Wait for SMBus to be free.
 136   1              SFRPAGE   =SMB0_PAGE;
 137   1              SM_BUSY = 1;                                                                            // Occupy SMBus (set to busy)
 138   1              SMB0CN = 0x44;                                                                          // SMBus enabled, ACK on acknowledge cycle
 139   1              BYTE_NUMBER = 1;                                                                        
 140   1              COMMAND = (CLOCK3530_ADDRESS_STATUS | READ);            
 141   1              I2CDataBuff = &result;                                                          
 142   1              STA = 1;                                                                                        // Start transfer
 143   1              while (SM_BUSY);                                                                        // Wait for transfer to finish
 144   1              return result;
 145   1      }
 146          void SetRealClockStatus(unsigned char status)
 147          {
 148   1              while (SM_BUSY);                                                                        // Wait for SMBus to be free.
 149   1              SFRPAGE   =SMB0_PAGE;
 150   1              SM_BUSY = 1;                                                                            // Occupy SMBus (set to busy)
 151   1              
 152   1              SMB0CN = 0x44;                                                                          // SMBus enabled, ACK on acknowledge cycle
 153   1              BYTE_NUMBER = 1;                                                                        
 154   1              COMMAND = (CLOCK3530_ADDRESS_STATUS | WRITE);           
 155   1              I2CDataBuff = &status;                                                          
 156   1              STA = 1;                                                                                        // Start transfer
 157   1      }
 158          
 159          #include "INTRINS.H"
 160          
 161          unsigned char revolve(unsigned char val)
 162          {
 163   1      char i;
 164   1      unsigned char val1=0;
 165   1              for (i=0;i<8;i++)
 166   1              {
 167   2                      if (val&0x1)
 168   2                              val1++;
 169   2                      val1=_crol_(val1,1);
 170   2                      val=_cror_(val,1);
 171   2              }
 172   1              val1=_cror_(val1,1);
 173   1              return val1;
 174   1      }
 175          
 176          void main (void)
 177          {
 178   1          unsigned char var ;

⌨️ 快捷键说明

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