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

📄 main.lst

📁 Demo for I2C Master and Slave
💻 LST
字号:
C51 COMPILER V7.20   MAIN                                                                  07/21/2004 17:06:28 PAGE 1   


C51 COMPILER V7.20, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN main.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE main.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1          /*------------------------------------------------------------------------------
   2          main.c
   3          
   4          Version:
   5          July 2004 Version 1.0 - Initial Version
   6          
   7          Dependencies:
   8          upsd_lcd.c   - LCD driver.
   9          upsd_i2c.c   - I2C driver.
  10          upsd_timer.c - Timer driver.
  11          
  12          
  13          Description:  Demo for I2C Slave
  14          The main function of this code is to demonstrate the use of the I2C driver in
  15          Slave mode.  As a slave, the uPSD device receives data written to it and sends 
  16          the data back when read.  The number of bytes received and sent is displayed
  17          on the LCD.
  18          
  19          It is intended that the I2C master device this slave communicates with is a uPSD
  20          device programmed with the I2C Master demo code.  The SCL and SDA lines of the
  21          master and slave devices must be connected together with a pull-up on each 
  22          signal.  The two devices must also have their GNDs tied together.  Using two 
  23          DK3200 boards, no pull-ups are required (as they are already on the board) but
  24          the two signals, SCL and SDA, plus GND must be connected.
  25          
  26          
  27          Note:
  28          This demo includes an option to enable or disable compilation of the code that
  29          places the uPSD32xx in idle mode between I2C transfers as well as turn on 
  30          LED ONE and LED TWO on the DK3200 while in idle mode.  This file, main.c, only
  31          conditionally compiles the code that intializes port B for driving LED ONE and
  32          LED TWO.  Also see upsd_i2c.c where the code that places the uPSD32xx in idle 
  33          mode and toggles the LEDs is located.
  34          
  35          
  36          Copyright (c) 2004 STMicroelectronic Inc.
  37          
  38          This example demo code is provided as is and has no warranty,
  39          implied or otherwise.  You are free to use/modify any of the provided
  40          code at your own risk in your applications with the expressed limitation
  41          of liability (see below) so long as your product using the code contains
  42          at least one uPSD products (device).
  43          
  44          LIMITATION OF LIABILITY:   NEITHER STMicroelectronics NOR ITS VENDORS OR 
  45          AGENTS SHALL BE LIABLE FOR ANY LOSS OF PROFITS, LOSS OF USE, LOSS OF DATA,
  46          INTERRUPTION OF BUSINESS, NOR FOR INDIRECT, SPECIAL, INCIDENTAL OR
  47          CONSEQUENTIAL DAMAGES OF ANY KIND WHETHER UNDER THIS AGREEMENT OR
  48          OTHERWISE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  49          ------------------------------------------------------------------------------*/
  50          
  51          #include "upsd3200.h"
  52          #include "upsd_hardware.h"
  53          #include "upsd_I2C.h"
  54          #include "upsd_timer.h"
  55          #include "upsd_LCD.h"
C51 COMPILER V7.20   MAIN                                                                  07/21/2004 17:06:28 PAGE 2   

  56          
  57          #define I2C_ADDR 0x88
  58          
  59          #define IDLE_MODE_DEMO 0                        //0 = don't compile slave idle mode demo code
  60                                                                                  //1 = compile slave idle mode demo code
  61                                                                                  //Note: This #define is also in upsd_i2c.c file
  62          
  63          unsigned char temp_xmit_buf[10];                                        // I2C transmit buffer
  64          unsigned char temp_rcv_buf[10];                                         // I2C receive buffer
  65          
  66          xdata PSD_REGS PSD8xx_reg _at_ PSD_REG_ADDR; 
  67          
  68          main()
  69          {       
  70   1              unsigned char i,temp;
  71   1              static unsigned char *temp_data_len,r;
  72   1      
  73   1              WDKEY=0x55;                                                                     // disable watchdog timer               
  74   1              PSD8xx_reg.VM |= 0x80;          
  75   1      
  76   1              timer0_init();                                                          // initialize timer0 interrupt 
  77   1              lcd_init();                                                                     // initialize LCD. 8 bits, 2 lines, 5x7 font,
  78   1                                                                                                      // no blink, cursor off, clear 
  79   1              printfLCD("I2C Slave");                                         // display on LCD
  80   1              printfLCD("\nWait for master\n");
  81   1      
  82   1      #if IDLE_MODE_DEMO
                      printfLCD("I2C Slave - Idle");                          // display on LCD - indicate idle mode demo
              
                      //initialize port B for driving LED ONE and LED TWO on DK3200 board
                      PSD8xx_reg.DIRECTION_B|=0x03;   // set PB0 & PB1 to output
                      PSD8xx_reg.DRIVE_B|=0x03;       // set PB0 & PB1 to open Drain 
              
                      PSD8xx_reg.DATAOUT_B|=0x03;             // PB0 & PB1 - (LEDs off)
              
                      //      Note: PB0 and PB1 jumpers on DK3200 must be installed for LEDs to turn on.
              #endif
  93   1      
  94   1              upsd_i2c_init (833,I2C_ADDR);                                                   // initialize I2C interface
  95   1      
  96   1      
  97   1              while(1)
  98   1              {               
  99   2                      temp=upsd_i2c_Slave_Recv(temp_rcv_buf,temp_data_len);
 100   2      
 101   2                      if(temp==I2C_SR_END)
 102   2                      {
 103   3                              r=*temp_data_len;
 104   3                              printfLCD("\nRec.    %x bytes\n",r);
 105   3                      }
 106   2                      else if(temp==I2C_SX_APP)
 107   2                      {
 108   3                              for(i=0;i<r;i++)
 109   3                                      temp_xmit_buf[i]=temp_rcv_buf[i];
 110   3                              
 111   3                              if(upsd_i2c_Slave_Xmit(temp_xmit_buf,temp_data_len)==I2C_SX_END)
 112   3                              {
 113   4                                      r=*temp_data_len;
 114   4                                      printfLCD("\nSent    %x bytes\n",r);
 115   4                              }
 116   3                      }
 117   2              }
C51 COMPILER V7.20   MAIN                                                                  07/21/2004 17:06:28 PAGE 3   

 118   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    165    ----
   CONSTANT SIZE    =     66    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     24       1
   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 + -