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

📄 tian.lst

📁 根据示波器的原理最做的代存储和显示的简易装置
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.04   TIAN                                                                  09/12/2003 17:56:34 PAGE 1   


C51 COMPILER V7.04, COMPILATION OF MODULE TIAN
OBJECT MODULE PLACED IN tian.OBJ
COMPILER INVOKED BY: F:\keil\C51\Bin\c51.exe tian.c DB SB OE ROM(LARGE) SMALL OT(6,SPEED) WL(2) RB(0)

stmt level    source

   1          #include <reg51.h>
   2          #include <stdio.h>
   3          
   4          #define uchar unsigned char 
   5          
   6          #define uint  unsigned int
   7          
   8          
   9          sbit addo=P1^2;//数据线
  10          sbit adcs=P1^0;//片选线
  11          sbit adclk=P1^1;//时钟线
  12          
  13          
  14          
  15          
  16          sbit I2C_SCK=P1^5;//时钟线
  17          sbit I2C_SDA=P1^6;//数据线
  18          
  19          //键盘键码对应表
  20          uchar code number[]={0x11,0x12,0x14,0x18,0x21,0x22,0x24,0x28,0x41,0x42,0x44,0x48,0x81,0x82,0x84,0x88};
  21          
  22          
  23          //uchar code number1[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
  24          
  25          uchar j,str[10],str1[10];
  26          /*********************************************************
  27          tcl8031 子程序
  28          **********************************************************/
  29          
  30          
  31          void Delay(uchar x)  //延迟
  32          {
  33   1              uchar i;
  34   1              for(i=0;i<x;i++)
  35   1                 {
  36   2                 }
  37   1      }
  38          
  39          void Adclk() //下降沿
  40          {
  41   1              adclk=1; 
  42   1              Delay(2);
  43   1              adclk=0;
  44   1              Delay(2);
  45   1      }
  46          
  47          uchar  ReadAd(void) //取数
  48          {
  49   1              uchar i;
  50   1              uchar str;
  51   1              adcs=0;
  52   1              Adclk();
  53   1              str=0;
  54   1              
  55   1      //              while(1)
C51 COMPILER V7.04   TIAN                                                                  09/12/2003 17:56:34 PAGE 2   

  56   1         // {
  57   1          //  if(addo==0)
  58   1          //          break;
  59   1              //  }
  60   1          for(i=0;i<8;i++)
  61   1              {
  62   2                      Adclk();
  63   2                      str<<=1; 
  64   2                      str=str|addo;
  65   2              }
  66   1          adcs=1;
  67   1          return str;
  68   1      }
  69          
  70          /************************************************************
  71          24c64子程序
  72          **************************************************************/
  73          
  74          bit   I2C_Start(void);
  75          void  I2C_Stop(void);
  76          void  I2C_Ack(void);
  77          void  I2C_Nack(void);
  78          bit   I2C_Send_Byte( uchar);
  79          uchar I2C_Receive_Byte(void);
  80          void  AT24C64_R(void *mcu_address,uint AT24C64_address,uint count);
  81          void  AT24C64_W(void *mcu_address,uint AT24C64_address,uint count);
  82          
  83          
  84          void  Delay_10_uS(void)   //延迟
  85          {
  86   1       char i=10;
  87   1       while(i--);
  88   1      }
  89          void Delay_N_mS( uint n_milisecond)  /* 延迟  n delay */
  90          {
  91   1       uchar i;
  92   1       while(n_milisecond--)
  93   1       {
  94   2        i=37;
  95   2        while(i--);
  96   2       }
  97   1      }
  98          bit I2C_Start(void)
  99          {
 100   1       Delay_10_uS();
 101   1       I2C_SDA =1;
 102   1       Delay_10_uS();
 103   1       I2C_SCK =1;
 104   1       Delay_10_uS();
 105   1       if ( I2C_SDA == 0) return 0;
 106   1       if ( I2C_SCK == 0) return 0;
 107   1       I2C_SDA = 0;
 108   1       Delay_10_uS();
 109   1       I2C_SCK = 0;
 110   1       Delay_10_uS();
 111   1       return 1;
 112   1      }
 113          void  I2C_Stop(void)
 114          {
 115   1       Delay_10_uS();
 116   1       I2C_SDA = 0;
 117   1       Delay_10_uS();
C51 COMPILER V7.04   TIAN                                                                  09/12/2003 17:56:34 PAGE 3   

 118   1       I2C_SCK = 1;
 119   1       Delay_10_uS();
 120   1       I2C_SDA = 1;
 121   1       Delay_10_uS();
 122   1      }
 123          void I2C_Ack(void)
 124          {
 125   1       Delay_10_uS();
 126   1       I2C_SDA=0;
 127   1       Delay_10_uS();
 128   1       I2C_SCK=1;
 129   1       Delay_10_uS();
 130   1       I2C_SCK=0;
 131   1       Delay_10_uS();
 132   1      }
 133          void I2C_Nack(void)
 134          {
 135   1       Delay_10_uS();
 136   1       I2C_SDA=1;
 137   1       Delay_10_uS();
 138   1       I2C_SCK=1;
 139   1       Delay_10_uS();
 140   1       I2C_SCK=0;
 141   1       Delay_10_uS();
 142   1      }
 143          bit I2C_Send_Byte( uchar d)
 144          {
 145   1       uchar i = 8;
 146   1       bit bit_ack;
 147   1       while( i-- )
 148   1       {
 149   2        Delay_10_uS();
 150   2        if ( d &0x80 )   I2C_SDA =1;
 151   2        else             I2C_SDA =0;
 152   2        Delay_10_uS();
 153   2        I2C_SCK = 1;
 154   2        Delay_10_uS();
 155   2        I2C_SCK = 0;
 156   2        d = d << 1;
 157   2       }
 158   1       Delay_10_uS();
 159   1       I2C_SDA = 1;
 160   1       Delay_10_uS();
 161   1       I2C_SCK = 1;
 162   1       Delay_10_uS();
 163   1       bit_ack = I2C_SDA;
 164   1       I2C_SCK =0;
 165   1       Delay_10_uS();
 166   1       return bit_ack;
 167   1      }
 168          uchar I2C_Receive_Byte(void)
 169          {
 170   1       uchar i = 8, d;
 171   1       Delay_10_uS();
 172   1       I2C_SDA = 1;
 173   1       while ( i--)
 174   1       {
 175   2        d = d << 1;
 176   2        Delay_10_uS();
 177   2        I2C_SCK =1;
 178   2        if ( I2C_SDA ) d++;
 179   2        Delay_10_uS();
C51 COMPILER V7.04   TIAN                                                                  09/12/2003 17:56:34 PAGE 4   

 180   2        I2C_SCK =0;
 181   2       }
 182   1       return d;
 183   1      }
 184          void AT24C64_W(void *mcu_address,uint AT24C64_address,uint count)
 185          {
 186   1      // DOG_WDI=!DOG_WDI;
 187   1      // DOGTIME=0;
 188   1       while(count--)
 189   1       {
 190   2        I2C_Start();
 191   2        /*I2C_Send_Byte( 0xa0 + AT24C64_address /256 *2);*/  /* 24C16  USE */
 192   2        I2C_Send_Byte( 0xa0 );
 193   2        I2C_Send_Byte(  AT24C64_address/256 );
 194   2        I2C_Send_Byte( AT24C64_address %256 );
 195   2        I2C_Send_Byte( *(uchar*)mcu_address );
 196   2        I2C_Stop();
 197   2        Delay_N_mS(10);       /* waiting for write cycle to be completed */
 198   2        ((uchar*)mcu_address)++;
 199   2        AT24C64_address++;
 200   2       }
 201   1      }
 202          void AT24C64_R(void *mcu_address,uint AT24C64_address,uint count)
 203          {
 204   1      // DOG_WDI=!DOG_WDI;
 205   1      // DOGTIME=0;
 206   1       while(count--)
 207   1       {
 208   2        I2C_Start();
 209   2        /*I2C_Send_Byte( 0xa0 + AT24C64_address / 256 *2 );*/   /* 24C16 USE */
 210   2        I2C_Send_Byte( 0xa0 );
 211   2        I2C_Send_Byte( AT24C64_address/256 );
 212   2        I2C_Send_Byte( AT24C64_address % 256 );
 213   2        I2C_Start();
 214   2        /*I2C_Send_Byte( 0xa1 + AT24C64_address /256 *2 );*/
 215   2        I2C_Send_Byte( 0xa1 );
 216   2        *(uchar*)mcu_address = I2C_Receive_Byte();
 217   2        I2C_Nack();
 218   2        I2C_Stop();
 219   2        ((uchar*)mcu_address)++;
 220   2        AT24C64_address++;
 221   2       }
 222   1      }
 223          
 224          /*uchar str[20]={10,9,8,7,6,5,4,3,2,0x1};
 225          char str2[20];
 226          main()
 227          {
 228                  //      uchar i;
 229                  AT24C64_W(str,0,10);
 230                  while(1)
 231                   AT24C64_R(str2,0,10);

⌨️ 快捷键说明

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