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

📄 main.lst

📁 C code for using 8051 to control philiphs I2C FM tuner (use keil c compiler)
💻 LST
字号:
C51 COMPILER V8.09   MAIN                                                                  08/22/2007 16:08:50 PAGE 1   


C51 COMPILER V8.09, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN main.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE main.c OMF2 ROM(SMALL) BROWSE

line level    source

   1          /* giantbicycle */
   2          #include "at89s52.h"
   3          
   4          #define M_EN    0       /* Multi-channel Enable */
   5          
   6          /* GPIO Pin Definitions */
   7          
   8          //#define I2C_SCL_CLR   (P0 &= 0xFE)    /* Clear I2C SCL (P0.0)*/
   9          #define I2C_SCL_CLR             P0_0 = 0
  10          //#define I2C_SCL_SET   (P0 |= 0x01)    /* Set I2C_SCL */
  11          #define I2C_SCL_SET             P0_0 = 1
  12          //#define I2C_SDA_GET   P0 & 0x02       /* Read I2C SDA (P0.1) */
  13          #define I2C_SDA_SDA_GET         P0_1
  14          //#define I2C_SDA_CLR   (P0 &= 0xFD)    /* Clear I2C SDA */
  15          #define I2C_SDA_CLR                     P0_1 = 0
  16          //#define I2C_SDA_SET   (P0 |= 0x02)    /* Set I2C_SDA */
  17          #define I2C_SDA_SET                     P0_1 = 1
  18          
  19          /* I2C Data flow Direction Definitions */
  20          #define I2C_WRITE       0x00    /* Write Direction */
  21          #define I2C_READ        0x01    /* Read Direction */
  22          
  23          /* I2C Acknowledge Definitions */
  24          #define I2C_ACK         0
  25          #define I2C_NO_ACK      1
  26          
  27          /* FQ1236-MK3 Module Definitions */
  28          #define TUMER_I2C_ADDRESS       0xC2    /* AS_TU pin (PIN6) is left floating */
  29          #define IF_I2C_ADDRESS          0x86    /* AS_IF pin (PIN10) is open */
  30          
  31          /* I2C functions */
  32          /* Generate the start condition */
  33          void I2C_Start();
  34          /* Generate the stop condition */
  35          void I2C_Stop();
  36          /* Master send a byte to the slave device */
  37          void I2C_Send_Byte(unsigned char byte);
  38          /* Master send the slave address */
  39          void I2C_Send_Addr(unsigned char addr, unsigned char dir);
  40          /* Master send the data to the slave device */
  41          #define I2C_Send_data   I2C_Send_Byte
  42          /* Master get a byte from the slave device */
  43          //unsigned char I2C_Get_Byte();
  44          /* Master get the data from the slave device */
  45          //unsigned char I2C_Get_Data();
  46          /* Hold the voltage level of the signal */
  47          data unsigned char counter;
  48          void    I2C_NOP();
  49          
  50          /* Tuner functions */
  51          /* Tuner Section Programming (Write Mode) */
  52          void tuner_write();
  53          /* Tuner data array */
  54          data unsigned char tuner_data[5]; /* |DB1|DB2|CB|BB|AB| */
  55          
C51 COMPILER V8.09   MAIN                                                                  08/22/2007 16:08:50 PAGE 2   

  56          /* Generate the start condition */
  57          void I2C_Start()
  58          {
  59   1              I2C_SDA_SET;
  60   1              I2C_SCL_SET;
  61   1              I2C_NOP();
  62   1              I2C_SDA_CLR;
  63   1              I2C_NOP();
  64   1              I2C_SCL_CLR;
  65   1              I2C_NOP();
  66   1      }
  67          
  68          /* Generate the stop condition */
  69          void I2C_Stop()
  70          {
  71   1              I2C_SCL_CLR;
  72   1              I2C_SDA_CLR;
  73   1              I2C_NOP();
  74   1              I2C_SCL_SET;
  75   1              I2C_NOP();
  76   1              I2C_SDA_SET;
  77   1              I2C_NOP();
  78   1      }
  79          
  80          /* Master send a byte to the slave device */
  81          void I2C_Send_Byte(unsigned char byte)
  82          {
  83   1              unsigned char mask;
  84   1      
  85   1              /* Send the byte from MSB to LSB */
  86   1              for (mask = 0x80 ; mask > 0 ; mask = mask >> 1 )
  87   1              {
  88   2                      if (byte & mask)
  89   2                              I2C_SDA_SET;
  90   2                      else
  91   2                              I2C_SDA_CLR;
  92   2      
  93   2                      I2C_SCL_SET;
  94   2                      I2C_NOP();
  95   2                      I2C_SCL_CLR;
  96   2              }
  97   1      
  98   1              /* Check the Acknowledge from slave device */
  99   1              I2C_SDA_SET;
 100   1              I2C_SCL_SET;
 101   1              I2C_NOP();
 102   1              I2C_SCL_CLR;
 103   1              I2C_NOP();
 104   1      }
 105          
 106          /* Master send the slave address */
 107          void I2C_Send_Addr(unsigned char addr, unsigned char dir)
 108          {
 109   1              I2C_Send_Byte(addr + dir);
 110   1      }
 111          /* Master get a byte from the slave device */
 112          #if 0
              unsigned char I2C_Get_Byte()
              {
                      unsigned char mask;
                      unsigned char retVal;
              
C51 COMPILER V8.09   MAIN                                                                  08/22/2007 16:08:50 PAGE 3   

                      I2C_SDA_SET;    /* configure the pin for input */
                      retVal  = 0;    /* initial the return value */
              
                      for (mask = 0x80 ; mask != 0 ; mask = mask >> 1)
                      {
                              I2C_NOP();
                              I2C_SCL_SET;
                              if(I2C_SDA_GET)
                                      retVal = retVal | 1;
                              I2C_NOP();
                              I2C_SCL_CLR;
                      }
              
                      I2C_SDA_SET; /* No Acknowledge */
                      I2C_NOP();
                      I2C_SCL_SET;
                      I2C_NOP();
                      I2C_SCL_CLR;
              
                      return retVal;
              }
              #endif
 140          /* Master get the data from the slave device */
 141          #if 0
              unsigned char I2C_Get_Data()
              {
                      return I2C_Get_Byte();
              }
              #endif
 147          
 148          /* Hold the voltage level of the signal */
 149          void I2C_NOP()
 150          {
 151   1              counter = 0;
 152   1      }
 153          
 154          /* Tuner Section Programming (Write Mode) */
 155          /* |S|ADB(W)|A|DB1|A|DB2|A|CB|A|BB|A|AB|A|P| */
 156          void tuner_write()
 157          {
 158   1              I2C_Start();
 159   1              I2C_Send_Addr(TUMER_I2C_ADDRESS, I2C_WRITE);
 160   1              I2C_Send_data(tuner_data[0]);   /* DB1 */
 161   1              I2C_Send_data(tuner_data[1]);   /* DB2 */
 162   1              I2C_Send_data(tuner_data[2]);   /* CB  */
 163   1              I2C_Send_data(tuner_data[3]);   /* BB  */
 164   1              I2C_Send_data(tuner_data[4]);   /* AB  */
 165   1              I2C_Stop();
 166   1      }
 167          
 168          void main ()
 169          {       
 170   1              unsigned char i;
 171   1      #if M_EN
                      unsigned char j;
              #endif
 174   1              unsigned char channel = 11;     
 175   1      
 176   1              while(1) {
 177   2                      switch (channel) {
 178   3              
 179   3                      /*
C51 COMPILER V8.09   MAIN                                                                  08/22/2007 16:08:50 PAGE 4   

 180   3                              NTSC USA, fVIF = 45.75MHz, fss = 62.5KHz
 181   3                              Test Cable Channel 7, fRF = 175.25MHz, TV Mid Band
 182   3                      */
 183   3      #if M_EN
                              case 7:
                                      tuner_data[0] = 0x0D; // DB1
                                      tuner_data[1] = 0xD0; // DB2
                                      tuner_data[2] = 0xCE; // CB
                                      tuner_data[3] = 0x02; // BB
                                      tuner_data[4] = 0x20; // AB
              #endif
 191   3      #if M_EN
                                      channel = 11;
              #endif
 194   3                      break;
 195   3              
 196   3                      /*
 197   3                              Test Cable Channel 11, fRF = 199.25MHz, TV Mid Band
 198   3                      */
 199   3                      case 11:
 200   3                              tuner_data[0] = 0x0F; // DB1
 201   3                              tuner_data[1] = 0x50; // DB2
 202   3                              tuner_data[2] = 0xCE; // CB
 203   3                              tuner_data[3] = 0x02; // BB
 204   3                              tuner_data[4] = 0x20; // AB
 205   3      #if M_EN
                                      channel = 5;
              #endif
 208   3                      break;
 209   3      
 210   3                      /*
 211   3                              Test Cable Channel 5 , fRF = 77.25MHz, TV Low Band
 212   3                              (77.25 + 45.75) *  1000 / 62.5
 213   3                      */
 214   3      #if M_EN
                              case 5:
                                      tuner_data[0] = 0x07; // DB1
                                      tuner_data[1] = 0xB0; // DB2
                                      tuner_data[2] = 0xCE; // CB
                                      tuner_data[3] = 0x01; // BB
                                      tuner_data[4] = 0x20; // AB
              #endif
 222   3      #if M_EN
                                      channel = 9;
              #endif
 225   3                      break;
 226   3              
 227   3                      /*
 228   3                              Test Cable Channel 9 , fRF = 187.25MHz, TV Mid Band
 229   3                              (187.25 + 45.75) *  1000 / 62.5
 230   3                      */
 231   3      #if M_EN
                              case 9:
                                      tuner_data[0] = 0x0E; // DB1
                                      tuner_data[1] = 0x90; // DB2
                                      tuner_data[2] = 0xCE; // CB
                                      tuner_data[3] = 0x02; // BB
                                      tuner_data[4] = 0x20; // AB
              #endif
 239   3      #if M_EN
                                      channel = 7;
              #endif
C51 COMPILER V8.09   MAIN                                                                  08/22/2007 16:08:50 PAGE 5   

 242   3                      break;
 243   3      
 244   3                      }
 245   2      
 246   2                      tuner_write();
 247   2      
 248   2                      for (i = 0 ; i < 50 ; i++)
 249   2                              I2C_NOP();
 250   2      
 251   2                      tuner_write();
 252   2      #if M_EN
                              for (i = 0 ; i < 255 ; i++)
                                      for (j = 0 ; j < 255; j++)
                                              I2C_NOP();
              #endif
 257   2              }
 258   1      }
 259          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    153    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =      6       3
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
   EDATA SIZE       =   ----    ----
   HDATA SIZE       =   ----    ----
   XDATA CONST SIZE =   ----    ----
   FAR CONST SIZE   =   ----    ----
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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