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

📄 i2c.lst

📁 silabs USB c8051f321 ,DAB USB dongle的资料,已经可以量产的东西
💻 LST
字号:
C51 COMPILER V7.07   I2C                                                                   03/24/2008 13:20:26 PAGE 1   


C51 COMPILER V7.07, COMPILATION OF MODULE I2C
OBJECT MODULE PLACED IN i2c.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\c51.exe i2c.c DB OE

stmt level    source

   1          
   2          #include <c8051f320.h>  
   3          #include "usb_api.h"
   4          
   5          sbit      SDA   =  P2^2 ;
   6          sbit      SCL   =  P2^3 ;
   7          
   8          #define   HIGH       1
   9          #define   LOW        0
  10          
  11          //int rda5800_reg_tab[45]={
  12          code const rda5800_reg_tab[]={
  13          0x0000,
  14          0x0000, 
  15          0xd881, //0x02
  16          //0x6300,
  17          0x8e00, //101.7M
  18          0x4400, //0x04
  19          0x06ff, //0x13ff, lilin, 06/22, 0x10f8, //0x05
  20          0x0000,
  21          0x00cd,
  22          0x0096,
  23          0x0020,
  24          0x4163,
  25          0x0806,
  26          0x5800,
  27          0x5800,
  28          0x5800,
  29          0x5800,
  30          0x4c17, //lilin, 08/13, seek_single step, 0x4817,
  31          0x20a2,
  32          0x0000,
  33          0x000f,
  34          0x06de,
  35          0xecc0,
  36          0x0200,
  37          0x5383,
  38          0x95a4,
  39          0xe848,
  40          0x0500, //0x0500, lilin, 06/22, 0x0500,
  41          0x00a4, //0x00a4, lilin, 06/22, 0x00a4,
  42          0x889b,
  43          0x0d84,
  44          0x4f04,
  45          0x8832,
  46          0x7f71,
  47          0x0660,
  48          0x4010,
  49          0x6002,
  50          0x1808,
  51          0x6458,
  52          0x787f,
  53          0x0100,
  54          0xc040,
  55          0xc020,
C51 COMPILER V7.07   I2C                                                                   03/24/2008 13:20:26 PAGE 2   

  56          0x0024,
  57          0x0400,
  58          0x0020,//
  59          };
  60          
  61          
  62          void nop(unsigned int cnt)
  63          {
  64   1              unsigned int i;
  65   1              for(i=0;i<cnt;i++);
  66   1      }
  67          
  68          
  69          void I2C_Start(void)
  70          {
  71   1              SDA=HIGH;
  72   1              nop(1);
  73   1              SCL = HIGH;
  74   1              nop(4);
  75   1              SDA = LOW;
  76   1              nop(4);
  77   1              SCL = LOW;
  78   1              nop(1);
  79   1      }
  80          
  81          
  82          
  83          void I2C_Stop(void)
  84          {
  85   1              SDA = LOW;
  86   1              nop(1);
  87   1              SCL = HIGH;
  88   1              nop(4);
  89   1              SDA = HIGH;
  90   1              nop(4);
  91   1      }
  92          
  93          
  94          void I2C_Write_Byte(unsigned char i2c_data)
  95          {
  96   1              unsigned char BitCnt;
  97   1              bit status;
  98   1      
  99   1              for(BitCnt = 0; BitCnt < 8; BitCnt++)
 100   1              {
 101   2      
 102   2                      if(i2c_data &0x80)
 103   2                                  SDA=1;
 104   2                      else
 105   2                                      SDA=0;
 106   2                      i2c_data = i2c_data << 1;
 107   2                      nop(4);
 108   2                      SCL=HIGH;
 109   2                      nop(4);
 110   2                      SCL=LOW;
 111   2              }
 112   1              SDA=LOW;
 113   1              nop(1);
 114   1              SCL = HIGH;
 115   1              nop(1);
 116   1              nop(1);
 117   1              status=SDA;
C51 COMPILER V7.07   I2C                                                                   03/24/2008 13:20:26 PAGE 3   

 118   1              SCL = LOW;
 119   1              nop(4);
 120   1      
 121   1      }
 122          
 123          
 124          
 125          
 126          
 127          unsigned char I2C_Read_Byte_ACK(void)           
 128          {
 129   1      
 130   1              unsigned char BitCnt,i2c_data=0;
 131   1      
 132   1              for(BitCnt= 0; BitCnt < 8; BitCnt++)
 133   1              {
 134   2      
 135   2                      i2c_data = i2c_data << 1;
 136   2      
 137   2                      SDA=HIGH;
 138   2                      nop(1);
 139   2                      SCL=HIGH;       
 140   2                      if(SDA==1)i2c_data++;
 141   2                      nop(4);
 142   2                      SCL=LOW;
 143   2      
 144   2      
 145   2              }
 146   1      
 147   1              SDA=LOW;//ack
 148   1      
 149   1              nop(1);
 150   1              SCL = HIGH;
 151   1              nop(4);
 152   1              SCL = LOW;
 153   1              nop(1); 
 154   1              
 155   1              return i2c_data;        
 156   1      
 157   1      }
 158          
 159          unsigned char I2C_Read_Byte_NAK(void)           
 160          {
 161   1              unsigned char BitCnt,i2c_data=0;
 162   1      
 163   1              for(BitCnt= 0; BitCnt < 8; BitCnt++)
 164   1              {
 165   2      
 166   2                      i2c_data = i2c_data << 1;
 167   2                      SDA=HIGH;
 168   2                      nop(1);
 169   2                      SCL=HIGH;       
 170   2                      if(SDA==1)i2c_data++;
 171   2                      nop(4);
 172   2                      SCL=LOW;
 173   2      
 174   2      
 175   2              }
 176   1      
 177   1              SDA=HIGH;//nak
 178   1      
 179   1              nop(1);
C51 COMPILER V7.07   I2C                                                                   03/24/2008 13:20:26 PAGE 4   

 180   1              SCL = HIGH;
 181   1              nop(4);
 182   1              SCL = LOW;
 183   1              nop(1); 
 184   1              
 185   1              return i2c_data;        
 186   1      
 187   1      }
 188          
 189          
 190          
 191          void Dab_Write_Register(int reg_addr,int reg_data)
 192          {
 193   1      
 194   1              unsigned char ValueH,ValueL,dev_addr;
 195   1      
 196   1              I2C_Start();
 197   1              //device address
 198   1              dev_addr = 0xD6;       
 199   1              I2C_Write_Byte(dev_addr);
 200   1      
 201   1      
 202   1      //write register address
 203   1      
 204   1              ValueL = (reg_addr & 0xFF);
 205   1              ValueH = ((reg_addr >> 8) & 0xFF);
 206   1              I2C_Write_Byte(ValueH);
 207   1              I2C_Write_Byte(ValueL);
 208   1      
 209   1      //write register value
 210   1              ValueL = (reg_data & 0xFF);
 211   1              ValueH = ((reg_data >> 8) & 0xFF);
 212   1              I2C_Write_Byte(ValueH);
 213   1              I2C_Write_Byte(ValueL);
 214   1      
 215   1              I2C_Stop();
 216   1      
 217   1      
 218   1      
 219   1      }
 220          
 221          
 222          
 223          void Dab_Read_Register(int reg_addr,int *ptrdata)
 224          {
 225   1      
 226   1              unsigned char ValueH,ValueL,dev_addr;
 227   1              //unsigned char i;
 228   1              
 229   1      
 230   1              I2C_Start();
 231   1              //device address
 232   1              dev_addr = 0xD6;  //write     
 233   1              I2C_Write_Byte(dev_addr);
 234   1      
 235   1      
 236   1      //write register address
 237   1      
 238   1              ValueL = (reg_addr & 0xFF);
 239   1              ValueH = ((reg_addr >> 8) & 0xFF);
 240   1              I2C_Write_Byte(ValueH);
 241   1              I2C_Write_Byte(ValueL);
C51 COMPILER V7.07   I2C                                                                   03/24/2008 13:20:26 PAGE 5   

 242   1      
 243   1              I2C_Start();
 244   1      
 245   1              //device address
 246   1              dev_addr = 0xD7;  //read     
 247   1              I2C_Write_Byte(dev_addr);
 248   1      
 249   1      
 250   1      
 251   1      
 252   1              ValueH = I2C_Read_Byte_ACK();
 253   1              ValueL = I2C_Read_Byte_NAK();
 254   1      
 255   1      
 256   1              I2C_Stop();
 257   1      
 258   1              *ptrdata = (((int)ValueH) << 8) | ValueL;
 259   1      
 260   1      }
 261          
 262          
 263          //add FM part;
 264          
 265          void DabFM_Write_Register( unsigned char reg_addr, int reg_data)
 266          {
 267   1      
 268   1              unsigned char ValueH,ValueL,dev_addr;
 269   1              unsigned char i;
 270   1              
 271   1              if(reg_addr<2)  return;
 272   1      
 273   1              I2C_Start();
 274   1              //device address
 275   1              dev_addr = 0x20;       
 276   1              I2C_Write_Byte(dev_addr);
 277   1      
 278   1              for(i=2;i<reg_addr;i++)
 279   1              {
 280   2                      ValueL = ((rda5800_reg_tab[i]) & 0xFF);
 281   2                      ValueH = (((rda5800_reg_tab[i]) >> 8) & 0xFF);
 282   2                      I2C_Write_Byte(ValueH);//high byte first
 283   2                      I2C_Write_Byte(ValueL);
 284   2              }
 285   1      
 286   1              ValueL = (reg_data & 0xFF);
 287   1              ValueH = ((reg_data >> 8) & 0xFF);
 288   1              I2C_Write_Byte(ValueH);//high byte first
 289   1              I2C_Write_Byte(ValueL);
 290   1      
 291   1              I2C_Stop();
 292   1      
 293   1      }
 294          
 295          
 296          
 297          void DabFM_Read_Register( unsigned char reg_addr, int *ptrdata)
 298          {
 299   1      
 300   1              unsigned char ValueH,ValueL,dev_addr;
 301   1              unsigned char i;
 302   1      
 303   1      
C51 COMPILER V7.07   I2C                                                                   03/24/2008 13:20:26 PAGE 6   

 304   1              I2C_Start();
 305   1              //device address
 306   1              dev_addr = 0x21;        
 307   1              I2C_Write_Byte(dev_addr);
 308   1      
 309   1              if(reg_addr<0x0a)       
 310   1              {
 311   2                      for(i=0x0a;i<=0x3a;i++)
 312   2                      {
 313   3      
 314   3                              ValueH = I2C_Read_Byte_ACK();
 315   3                              ValueL = I2C_Read_Byte_ACK();
 316   3                              
 317   3                      }
 318   2      
 319   2                      for(i=0x00;i<reg_addr;i++)
 320   2                      {
 321   3      
 322   3                              ValueH = I2C_Read_Byte_ACK();
 323   3                              ValueL = I2C_Read_Byte_ACK();
 324   3      
 325   3                      }
 326   2              
 327   2      
 328   2              }
 329   1      
 330   1              if(reg_addr>0x0a)
 331   1              {
 332   2                      for(i=0x0a;i<reg_addr;i++)
 333   2                      {
 334   3      
 335   3                              ValueH = I2C_Read_Byte_ACK();
 336   3                              ValueL = I2C_Read_Byte_ACK();
 337   3                              
 338   3                      }
 339   2      
 340   2              }
 341   1      
 342   1              ValueH = I2C_Read_Byte_ACK();
 343   1              ValueL = I2C_Read_Byte_NAK();
 344   1      
 345   1              I2C_Stop();     
 346   1              *ptrdata = (((int)ValueH) << 8) | ValueL;
 347   1      
 348   1      
 349   1      }
 350          
 351          
 352          void DabFM_Init(void)
 353          {
 354   1              int register_data; 
 355   1      
 356   1          DabFM_Write_Register(45,0x0020);
 357   1      
 358   1              Dab_Write_Register(0x2000,0x1234);
 359   1      
 360   1              Dab_Read_Register(0x2000,&register_data);
 361   1      
 362   1      
 363   1      
 364   1              DabFM_Read_Register(0x0a,&register_data);
 365   1      
C51 COMPILER V7.07   I2C                                                                   03/24/2008 13:20:26 PAGE 7   

 366   1              DabFM_Read_Register(0x0a,&register_data);
 367   1      
 368   1      }
 369          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    596    ----
   CONSTANT SIZE    =     90    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----      20
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----       1
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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