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

📄 iic20080107.lst

📁 VB环境下的串口通讯设计
💻 LST
字号:
C51 COMPILER V8.05a   IIC20080107                                                          01/07/2008 19:59:16 PAGE 1   


C51 COMPILER V8.05a, COMPILATION OF MODULE IIC20080107
OBJECT MODULE PLACED IN IIC20080107.OBJ
COMPILER INVOKED BY: C:\Keilc51\C51\BIN\C51.EXE IIC20080107.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1          /************************************************/
   2          #include <REG52.H>
   3          #define uchar unsigned char
   4          #define uint unsigned int
   5          #define ulong unsigned long
   6          sbit I2C_SDA= P1^5;
   7          sbit I2C_SCK= P1^4;
   8          sbit I2C_WP= P1^3;
   9          sbit GRE=P1^7;
  10          
  11          //===============================================
  12          
  13          //=============================
  14          //延时10US
  15          //内部调用函数
  16          void  Delay_10_uS(void)
  17          {
  18   1           char i=10;
  19   1           while(i--);
  20   1      }
  21          
  22          //延时n_milisecond MS
  23          //供内部调用函数
  24          void delay_n_ms( uint n_milisecond)  /* n mS delay */
  25          {
  26   1           uchar i;
  27   1           while(n_milisecond--)
  28   1           {
  29   2                i=37;
  30   2                while(i--);
  31   2           }
  32   1      }
  33          
  34          //开始位
  35          //内部调用函数
  36          bit I2C_Start(void)
  37          {
  38   1           Delay_10_uS();
  39   1           I2C_SDA =1;
  40   1           Delay_10_uS();
  41   1           I2C_SCK =1;
  42   1           Delay_10_uS();
  43   1           if ( I2C_SDA == 0) return 0;
  44   1           if ( I2C_SCK == 0) return 0;
  45   1           I2C_SDA = 0;
  46   1           Delay_10_uS();
  47   1           I2C_SCK = 0;
  48   1           Delay_10_uS();
  49   1           return 1;
  50   1      }
  51          
  52          //停止位
  53          //内部调用函数
  54          void  I2C_Stop(void)
  55          {
C51 COMPILER V8.05a   IIC20080107                                                          01/07/2008 19:59:16 PAGE 2   

  56   1           Delay_10_uS();
  57   1           I2C_SDA = 0;
  58   1           Delay_10_uS();
  59   1           I2C_SCK = 1;
  60   1           Delay_10_uS();
  61   1           I2C_SDA = 1;
  62   1           Delay_10_uS();
  63   1      }
  64          
  65          
  66          //写单字节数据
  67          //内部调用函数
  68          bit I2C_Send_Byte( uchar d)
  69          {
  70   1           uchar i = 8;
  71   1           bit bit_ack;
  72   1           while( i-- )
  73   1           {
  74   2                Delay_10_uS();
  75   2                if ( d &0x80 )   I2C_SDA =1;
  76   2                else             I2C_SDA =0;
  77   2                Delay_10_uS();
  78   2                I2C_SCK = 1;
  79   2                Delay_10_uS();
  80   2                I2C_SCK = 0;
  81   2                d = d << 1;
  82   2           }
  83   1           Delay_10_uS();
  84   1           I2C_SDA = 1;
  85   1           Delay_10_uS();
  86   1           I2C_SCK = 1;
  87   1           Delay_10_uS();
  88   1           bit_ack = I2C_SDA;
  89   1           I2C_SCK =0;
  90   1           Delay_10_uS();
  91   1           return bit_ack;
  92   1      }
  93          
  94          
  95          
  96          //写多字节数据
  97          //供外部调用函数
  98          void AT24C64_W(void *mcu_address,uint AT24C64_address,uint count)
  99          {
 100   1      
 101   1           while(count--)
 102   1           {
 103   2                I2C_Start();
 104   2                /*I2C_Send_Byte( 0xa0 + AT24C64_address /256 *2);*/  /* 24C16  USE */
 105   2                I2C_Send_Byte( 0xa0 );//写命令设备地址为10100000最后一位为0"写标志"
 106   2                I2C_Send_Byte(  AT24C64_address/256 );//写存储器页地址
 107   2                I2C_Send_Byte( AT24C64_address %256 );//写存储器字节地址
 108   2                I2C_Send_Byte( *(uchar*)mcu_address );//写MCU地址指针指数据到存储单元
 109   2                I2C_Stop();
 110   2                delay_n_ms(10);       /* waiting for write cycle to be completed */
 111   2                ((uchar*)mcu_address)++;
 112   2                AT24C64_address++;
 113   2           }
 114   1      }
 115          
 116          //读多字节数据
 117          //供外部调用函数
C51 COMPILER V8.05a   IIC20080107                                                          01/07/2008 19:59:16 PAGE 3   

 118          
 119          void write1()
 120          {
 121   1              uchar i,j;
 122   1              bit kbit;
 123   1              uchar xdata tab[96]=
 124   1              {       
 125   1      
 126   1      0x8,0x40,0x2,0x0,0x8,0x0,0xc,0x40,0x1,0x0,0x1c,0x0,0x8,0x40,0x3f,0xfe,0x31,0xfc,0x17,0xfc,0x44,0x4,0x40,0x
             -0,0x10,0x48,0x44,0x8,0x88,0x0,0x34,0x4c,0x7,0xf0,0xc,0x0,0x53,0x48,0xc,0x20,0x1b,0xfe,0x92,0x50,0x12,0x40,0x30,0x20,0x1f
             -,0xfe,0x21,0x80,0x50,0x20,0x10,0xa0,0x6,0x70,0x90,0x20,0x10,0xa0,0x3f,0xfe,0x10,0x20,0x11,0x10,0xc8,0x14,0x10,0x20,0x11,
             -0x18,0x8,0x10,0x10,0x20,0x12,0xe,0x8,0x10,0x10,0x20,0x14,0x4,0xf,0xf0,0x10,0xa0,0x0,0x0,0x8,0x10,0x10,0x40
 127   1              };                                                                                                                                                      
 128   1              AT24C64_W(tab,0x00,0x60);
 129   1      for(j=1;j<8;j++)
 130   1      {       kbit=(bit)(tab[0]&0x80);
 131   2              for(i=0;i<96;i++)
 132   2              {
 133   3                      tab[i]=tab[i]<<1;
 134   3                      tab[i+1]=(bit)(tab[i]&0x08);
 135   3              }
 136   2              tab[95]=tab[95]|(uchar)kbit;
 137   2              AT24C64_W(tab,j*0x60,0x60);
 138   2      
 139   2      }
 140   1      }
 141          
 142          //void write2()
 143          //{
 144          //uchar tab[2][16]={
 145          //      {0x10,0x40,0x1A,0x40,0x13,0x40,0x32,0x40,0x23,0xFC,0x64,0x40,0xA4,0x40,0x28,0x40},
 146          //      {0x2F,0xFE,0x20,0x40,0x20,0x40,0x20,0x40,0x20,0x40,0x20,0x40,0x20,0x40,0x20,0x40}/*"件",2*/
 147          //      };
 148          //      AT24C64_W(tab,0x0040,0x20);     
 149          //}
 150          //=====================================
 151          void main()
 152          {
 153   1      
 154   1              //uchar i,j;
 155   1              //P1=0;
 156   1              //P2=0;
 157   1              P3=0;
 158   1              GRE=0;
 159   1              write1();
 160   1      //      write2();
 161   1              GRE=1;
 162   1      }
 163          
 164          
 165          
 166          
 167          
 168          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    365    ----
   CONSTANT SIZE    =     96    ----
   XDATA SIZE       =   ----      96
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----       8
C51 COMPILER V8.05a   IIC20080107                                                          01/07/2008 19:59:16 PAGE 4   

   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----       2
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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