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

📄 26.lst

📁 这是我大学4年来做过的竞赛以及老师的科研项目所积累下来的c51源代码
💻 LST
📖 第 1 页 / 共 2 页
字号:
 160          // I2C Peripheral Function Prototypes
 161          //------------------------------------------------------------------------------
 162          
 163          //------------------------------------------------------------------------------
 164          // Procedure:   write_byte
 165          // Inputs:              data out, address
 166          // Outputs:             none
 167          // Description: Writes a byte to the EEPROM given the address 
 168          //------------------------------------------------------------------------------
 169          void write_byte (unsigned char data_out, unsigned int address)
 170          {
 171   1              i2c_start();                                                    // Send start signal
 172   1              i2c_write(0xA0);                                // Send identifier I2C address
 173   1              i2c_write(high_byte(address));                  // Send address to EEPROM
 174   1              i2c_write((unsigned char)address);      // Send address to EEPROM
 175   1              i2c_stop_and_write(data_out);                   // Send low byte to EEPROM
 176   1              delay_time(DELAY_WRITE);                        // Delay a period of time to write
 177   1      }
 178          
 179          //------------------------------------------------------------------------------
C51 COMPILER V7.09   26                                                                    03/22/2005 10:03:29 PAGE 4   

 180          // Procedure:   read_byte
 181          // Inputs:              address
 182          // Outputs:             none
 183          // Description: Reads a byte from the EEPROM given the address 
 184          //------------------------------------------------------------------------------
 185          unsigned char read_byte (unsigned int address)
 186          {
 187   1              unsigned char data_in;
 188   1      
 189   1              i2c_start();                                                    // Send start signal
 190   1              i2c_write(0xA0);                                // Send identifer I2C address
 191   1              i2c_write(high_byte(address));                  // Send address to EEPROM
 192   1                                                                                              // Send address to EEPROM
 193   1                                                                                              // Send repeated start signal
 194   1              repeated_i2c_start_and_write((unsigned char)address);                                   
 195   1      
 196   1              i2c_write(0xA1);                                // Send identifer I2C address
 197   1              data_in = i2c_stop_and_read();                  // Read byte, send stop signal
 198   1      
 199   1              return data_in;                 
 200   1      }
 201          
 202          
 203          //------------------------------------------------------------------------------
 204          //      Routine:        i2c_start
 205          //      Inputs:         none
 206          //      Outputs:        none
 207          //      Purpose:        Sends I2C Start Trasfer - State "B"
 208          //------------------------------------------------------------------------------
 209          void i2c_start (void)
 210          {
 211   1              while (BUS_BUSY);                                               // Wait until we are clear to write
 212   1              BUS_START = TRUE;                                               // Perform I2C start
 213   1              while (!BUS_INT);                                               // Wait until start sent
 214   1              BUS_START = FALSE;                                              // Reset I2C start
 215   1              BUS_INT = 0;                                                    // Clear SI
 216   1      }
 217          
 218          //------------------------------------------------------------------------------
 219          //      Routine:        repeated_i2c_start_and_write
 220          //      Inputs:         none
 221          //      Outputs:        none
 222          //      Purpose:        Sends I2C Start Trasfer - State "B"
 223          //------------------------------------------------------------------------------
 224          void repeated_i2c_start_and_write (unsigned char output_data)
 225          {
 226   1              BUS_START = TRUE;                                               // Perform I2C start
 227   1              SMB0DAT = output_data;                                  // Put data into buffer
 228   1              while (!BUS_INT);                                               // Wait unitl we are done with send
 229   1              BUS_INT = 0;                                                    // Clear SI
 230   1              BUS_START = FALSE;                                              // Reset I2C start
 231   1              while (!BUS_INT);                                               // Wait unitl we are done with reset
 232   1              BUS_INT = 0;                                                    // Clear SI
 233   1      }
 234          
 235          //------------------------------------------------------------------------------
 236          //      Routine:        i2c_stop_and_write
 237          //      Inputs:         output byte
 238          //      Outputs:        none
 239          //      Purpose:        Sends I2C Stop Trasfer - State "C" (also sends last byte)
 240          //------------------------------------------------------------------------------
 241          void i2c_stop_and_write (unsigned char output_data)
C51 COMPILER V7.09   26                                                                    03/22/2005 10:03:29 PAGE 5   

 242          {
 243   1              BUS_STOP = TRUE;                                                // Perform I2C stop
 244   1              SMB0DAT = output_data;                                  // Put data into buffer
 245   1              while (!BUS_INT);                                               // Wait unitl we are done with send
 246   1              BUS_INT = 0;                                                    // Clear SI
 247   1      }
 248          
 249          //------------------------------------------------------------------------------
 250          //      Routine:        i2c_stop_and_read
 251          //      Inputs:         none
 252          //      Outputs:        input byte
 253          //      Purpose:        Sends I2C Stop Trasfer - State "C" (also reads last byte)
 254          //------------------------------------------------------------------------------
 255          unsigned char i2c_stop_and_read (void)
 256          {
 257   1              unsigned char input_data;
 258   1      
 259   1              BUS_STOP = TRUE;                                                // Perform I2C stop
 260   1              while (!BUS_INT);                                               // Wait until we have data to read
 261   1              input_data = SMB0DAT;                                   // Read the data
 262   1              BUS_INT = 0;                                                    // Clear SI
 263   1      
 264   1              return input_data;
 265   1      }
 266          
 267          //------------------------------------------------------------------------------
 268          //      Routine:        i2c_write
 269          //      Inputs:         output byte
 270          //      Outputs:        none
 271          //      Purpose:        Writes data over the I2C bus
 272          //------------------------------------------------------------------------------
 273          void i2c_write (unsigned char output_data)
 274          {
 275   1              SMB0DAT = output_data;                                  // Put data into buffer
 276   1              while (!BUS_INT);                                               // Wait unitl we are done with send
 277   1              BUS_INT = 0;                                                    // Clear SI
 278   1      }
 279          
 280          //------------------------------------------------------------------------------
 281          //      Routine:        i2c_read
 282          //      Inputs:         none
 283          //      Outputs:        input byte
 284          //      Purpose:        Reads data from the I2C bus
 285          //------------------------------------------------------------------------------
 286          unsigned char i2c_read (void)
 287          {
 288   1              unsigned char input_data;
 289   1      
 290   1              while (!BUS_INT);                                               // Wait until we have data to read
 291   1              input_data = SMB0DAT;                                   // Read the data
 292   1              BUS_INT = 0;                                                    // Clear SI
 293   1      
 294   1              return input_data;
 295   1      }
 296          
 297          
 298          
 299          ////////////////////////////////////////////////////////////////////////////////
 300          //      Routine:        delay_time
 301          //      Inputs:         counter value to stop delaying
 302          //      Outputs:        none
 303          //      Purpose:        To pause execution for pre-determined time
C51 COMPILER V7.09   26                                                                    03/22/2005 10:03:29 PAGE 6   

 304          ////////////////////////////////////////////////////////////////////////////////
 305          void delay_time (unsigned int time_end)
 306          {
 307   1              unsigned int index;
 308   1              for (index = 0; index < time_end; index++);
 309   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    366    ----
   CONSTANT SIZE    =    208    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----       8
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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