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

📄 10.3.lst

📁 51单片机开发之 i2c中线的编程设计
💻 LST
字号:
C51 COMPILER V7.09   10_3                                                                  08/24/2005 11:34:00 PAGE 1   


C51 COMPILER V7.09, COMPILATION OF MODULE 10_3
OBJECT MODULE PLACED IN 10.3.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE 10.3.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1          
   2          #include <REG51F0X0.H>                                          // Header file for the Cygnal 8051F0X0
   3          #include <STDIO.H>                                                      // Header file for standard I/O
   4          #define  PCF8563DEVICEADDR       0x1
   5          unsigned char g8563_Time[6];
   6          unsigned char g8563_LastMinuteTime[6];                  //前一分钟时间备份
   7          
   8          #define         TRUE                    0x01                    // Value representing TRUE
   9          #define         FALSE                   0x00                    // Value representing FALSE
  10          #define         ON                              0x01                    // Value representing ON
  11          #define         OFF                             0x00                    // Value representing OFF
  12          #define         HIGH                    0x01                    // Value representing ON
  13          #define         LOW                             0x00                    // Value representing OFF
  14          
  15          #define         DELAY_WRITE             5000                    // approx. 5 ms delay write time (about 1000 cycles / ms)
  16          #define         DELAY_BLINK             50000                   // Value for delay time - blink 
  17          
  18          
  19          #define high_byte(x)            ((x & 0xFF00) >> 8)
  20          
  21          
  22          
  23          sbit            P1_6            =       0x96;                   // Define the individual bit (P1.6)
  24          #define         LED                             P1_6                    // The eval board has an LED on P1.6
  25          
  26          sbit            BUS_BUSY        =       0xC7;                   // SM Bus Busy (bit 7)
  27          sbit            BUS_EN          =       0xC6;                   // SM Bus Enable (bit 6)
  28          sbit            BUS_START       =       0xC5;                   // SM Bus Start (bit 5)
  29          sbit            BUS_STOP        =       0xC4;                   // SM Bus Stop (bit 4)
  30          sbit            BUS_INT         =       0xC3;                   // SM Bus Interrupt (bit 3)
  31          sbit            BUS_AA          =       0xC2;                   // SM Bus ACK (bit 2)
  32          sbit            BUS_FTE         =       0xC1;                   // SM Bus Clock timeout - high (bit 1)
  33          sbit            BUS_TOE         =       0xC0;                   // SM Bus Clock timeout - low (bit 0)
  34          
  35          
  36          //中断矢量
  37          unsigned char code iv_table [0xB0] _at_ 0x0003;
  38          
  39          
  40          void write_byte (unsigned char data_out, unsigned int address);
  41          unsigned char read_byte (unsigned int address);
  42          void i2c_write (unsigned char output_data);
  43          unsigned char i2c_read (void);
  44          void delay_time (unsigned int time_end);
  45          void i2c_start (void);
  46          unsigned char  i2c_stop_and_read (void);
  47          void repeated_i2c_start_and_write (unsigned char output_data);
  48          void i2c_stop_and_write (unsigned char output_data);
  49          //void P8563_CpyTime(unsigned char *p);
  50          
  51          const unsigned char cTimeDefault[]={0x00,0x00,0x12,0x01,0x01,0x03};
  52          enum Time{
  53              SECOND,
  54              MINUTE,
  55              HOUR,
C51 COMPILER V7.09   10_3                                                                  08/24/2005 11:34:00 PAGE 2   

  56              DAY,
  57              MONTH,
  58              YEAR
  59          };
  60          
  61          void main (void)
  62          {
  63   1              unsigned int eeprom_address,MONTH,DAY,HOUR,MINUTE;
  64   1              unsigned char eeprom_data;      
  65   1      
  66   1              // Disable the WDT (page 93 of data sheet)
  67   1              WDTCN = 0xDE;
  68   1              WDTCN = 0xAD;
  69   1      
  70   1              // Set internal oscilator to 16 MHz - Startup is 2 MHz (page 98 of data sheet)
  71   1              OSCICN = 0x07;
  72   1      
  73   1      
  74   1              // On the Cygnal processor there is a "Crossover" network that must     
  75   1              // be initialized to establish the port pin assignements
  76   1              // (see page 101 of the data sheet)
  77   1              XBR0 = 0x05;                                                    // Set UART and SMBus to be enabled
  78   1              XBR1 = 0x00;                                                    // No functions routed in this register
  79   1              XBR2 = 0x40;                                                    // Pull-ups enabled, XBAR enabled, no ADC
  80   1      
  81   1              PRT1CF = 0x40;                                                  // Set port 1.6 to push/pull 
  82   1                                                                                              // (i.e the LED on the Eval board)
  83   1      MONTH=g8563_Time[MONTH];
  84   1      DAY=g8563_Time[DAY];
  85   1      HOUR=g8563_Time[HOUR];
  86   1      MINUTE=g8563_Time[MINUTE];
  87   1              
  88   1      
  89   1      }
*** WARNING C280 IN LINE 63 OF 10.3.C: 'eeprom_address': unreferenced local variable
*** WARNING C280 IN LINE 64 OF 10.3.C: 'eeprom_data': unreferenced local variable
  90          
  91          //发送I2C信号
  92          
  93          void write_byte (unsigned char data_out, unsigned int address)
  94          {
  95   1              i2c_start();                                                    // Send start signal
  96   1              i2c_write(0xA0);                                // Send identifier I2C address
  97   1              i2c_write(high_byte(address));                  // Send address to EEPROM
  98   1              i2c_write((unsigned char)address);      // Send address to EEPROM
  99   1              i2c_stop_and_write(data_out);                   // Send low byte to EEPROM
 100   1              delay_time(DELAY_WRITE);                        // Delay a period of time to write
 101   1      }
 102          
 103          //从EEPROM读一个字节
 104          unsigned char read_byte (unsigned int address)
 105          {
 106   1              unsigned char data_in;
 107   1      
 108   1              i2c_start();                                                    // Send start signal
 109   1              i2c_write(0xA0);                                // Send identifer I2C address
 110   1              i2c_write(high_byte(address));                  // Send address to EEPROM
 111   1                                                                                              // Send address to EEPROM
 112   1                                                                                              // Send repeated start signal
 113   1              repeated_i2c_start_and_write((unsigned char)address);                                   
 114   1      
 115   1              i2c_write(0xA1);                                // Send identifer I2C address
C51 COMPILER V7.09   10_3                                                                  08/24/2005 11:34:00 PAGE 3   

 116   1              data_in = i2c_stop_and_read();                  // Read byte, send stop signal
 117   1      
 118   1              return data_in;                 
 119   1      }
 120          
 121          
 122          //I2C开始
 123          void i2c_start (void)
 124          {
 125   1              while (BUS_BUSY);                                               // Wait until we are clear to write
 126   1              BUS_START = TRUE;                                               // Perform I2C start
 127   1              while (!BUS_INT);                                               // Wait until start sent
 128   1              BUS_START = FALSE;                                              // Reset I2C start
 129   1              BUS_INT = 0;                                                    // Clear SI
 130   1      }
 131          
 132          //重复开始
 133          void repeated_i2c_start_and_write (unsigned char output_data)
 134          {
 135   1              BUS_START = TRUE;                                               // Perform I2C start
 136   1              SMB0DAT = output_data;                                  // Put data into buffer
 137   1              while (!BUS_INT);                                               // Wait unitl we are done with send
 138   1              BUS_INT = 0;                                                    // Clear SI
 139   1              BUS_START = FALSE;                                              // Reset I2C start
 140   1              while (!BUS_INT);                                               // Wait unitl we are done with reset
 141   1              BUS_INT = 0;                                                    // Clear SI
 142   1      }
 143          
 144          //停止
 145          void i2c_stop_and_write (unsigned char output_data)
 146          {
 147   1              BUS_STOP = TRUE;                                                // Perform I2C stop
 148   1              SMB0DAT = output_data;                                  // Put data into buffer
 149   1              while (!BUS_INT);                                               // Wait unitl we are done with send
 150   1              BUS_INT = 0;                                                    // Clear SI
 151   1      }
 152          
 153          //读
 154          unsigned char i2c_stop_and_read (void)
 155          {
 156   1              unsigned char input_data;
 157   1      
 158   1              BUS_STOP = TRUE;                                                // Perform I2C stop
 159   1              while (!BUS_INT);                                               // Wait until we have data to read
 160   1              input_data = SMB0DAT;                                   // Read the data
 161   1              BUS_INT = 0;                                                    // Clear SI
 162   1      
 163   1              return input_data;
 164   1      }
 165          
 166          //写数据
 167          void i2c_write (unsigned char output_data)
 168          {
 169   1              SMB0DAT = output_data;                                  // Put data into buffer
 170   1              while (!BUS_INT);                                               // Wait unitl we are done with send
 171   1              BUS_INT = 0;                                                    // Clear SI
 172   1      }
 173          
 174          //读数据
 175          unsigned char i2c_read (void)
 176          {
 177   1              unsigned char input_data;
C51 COMPILER V7.09   10_3                                                                  08/24/2005 11:34:00 PAGE 4   

 178   1      
 179   1              while (!BUS_INT);                                               // Wait until we have data to read
 180   1              input_data = SMB0DAT;                                   // Read the data
 181   1              BUS_INT = 0;                                                    // Clear SI
 182   1      
 183   1              return input_data;
 184   1      }
 185          
 186          
 187          //延时
 188          void delay_time (unsigned int time_end)
 189          {
 190   1              unsigned int index;
 191   1              for (index = 0; index < time_end; index++);
 192   1      }
 193          
 194          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    219    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     18      16
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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