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

📄 i2c.lst

📁 用于Slave I2C得读写,此代码针对特定得芯片,但对其他得芯片也有借鉴作用.
💻 LST
字号:
C51 COMPILER V7.02b   I2C                                                                  11/13/2006 17:18:10 PAGE 1   


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

stmt level    source

   1          /**********************************************************
   2          *File: i2C.c
   3          *Content: Test I2C interface of 24AA256
   4          
   5          *data:   03/18/2006       Eric    V0.1
   6          * Copyright (c) 2005 Fameg, Inc. All rights reserved
   7          ***********************************************************/
   8          #include "DP8051.h"
   9          #include "FS7822.h"
  10          #include "I2C.h"
  11          
  12          #define SLAVE_ADDRESS  0xEA
  13          #define bmI2CCK_DIV       0x54
  14          #define bmCLK_PRE         0x40
  15          
  16          #define I2C_EN                  0x80
  17          #define I2C_MODE                0x40
  18          #define MST_MODE                0x20
  19          #define START                   0x02
  20          #define STOP                    0x01
  21          
  22          void InitCPU()
  23          {
  24   1              SYS_CFG=bmCPUCLK_SEL|bmPM_AVBLE|bmSYS_SWRST; //select system  clock,firmware dispose USB request, reset t
             -he device
  25   1      
  26   1          SYSIO_CFG=bmSPI_EN|bmI2C_EN;
  27   1      
  28   1              SW_RST=bmSPI_RST|bmI2C_RST;
  29   1      
  30   1              BPPUCTL=bmSPIPUCTL;
  31   1      
  32   1              MEMCON=bmMEMCON|bmASYN;
  33   1          //MEMCON=0x08;
  34   1      }
  35          
  36          void I2c_Init(BOOL isHigh)
  37          {
  38   1          SW_RST|=bmI2C_RST;
  39   1      
  40   1          if(isHigh)
  41   1                I2C_CLK = bmI2CCK_DIV;                     //400k
  42   1          else
  43   1                I2C_CLK = bmCLK_PRE|bmI2CCK_DIV;           //100k
  44   1      
  45   1              I2C_CTL &= 0x3F;             //master
  46   1              I2C_MABT = 0x01;          //设定超时时间
  47   1      }
  48          
  49          
  50          
  51          void I2C_Write(unsigned char *input,unsigned short wordadd,unsigned char Len)  //向地址wordadd中写入Len长

⌨️ 快捷键说明

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