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

📄 t.lst

📁 at89c51 读取写入24c64的C源代码
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.06   T                                                                     06/27/2008 14:25:55 PAGE 1   


C51 COMPILER V7.06, COMPILATION OF MODULE T
OBJECT MODULE PLACED IN t.OBJ
COMPILER INVOKED BY: f:\Keil\C51\BIN\C51.EXE t.c BROWSE DEBUG OBJECTEXTEND

stmt level    source

   1          #include <at89x51.h>
   2          #include <intrins.h>
   3          
   4          #define uchar unsigned char
   5          #define uint unsigned int 
   6          #define byte unsigned char
   7          #if 0
              bit   I2C_Start(void);
              void  I2C_Stop(void);
              void  I2C_Ack(void);
              void  I2C_Nack(void);
              bit   I2C_Send_Byte( uchar);
              uchar I2C_Receive_Byte(void);
              void  AT24C64_R(void *mcu_address,uint AT24C64_address,uint count);
              void  AT24C64_W(void *mcu_address,uint AT24C64_address,uint count);
              #else
  17          void I2C_ReceiveFromSubAddress(byte SlaveAddress,uint SubAddress,byte *pRData,uchar N);
  18          void I2C_SendToSubAddress(byte SlaveAddress,uint SubAddress,byte *pSData,uchar N);
  19          
  20          #endif
  21          
  22          //RXD TXD
  23          #define KEY_LINE1 P3_0
  24          #define KEY_LINE2 P3_1
  25          #define KEY_LINE3 P3_7
  26          
  27          //T0 T1
  28          #define SCL P3_4
  29          #define SDA P3_5
  30          void delay(unsigned int n)
  31          {
  32   1              unsigned int i,j;
  33   1              for(j=0;j<100;j++)
  34   1              for(i=0;i<n;i++);
  35   1      }
  36          unsigned char wdat[10]={0xF0,0x0F,0xA0,0x0A,0xAA,0x99,0x3C,0xC3,0x81,0x18};
  37          unsigned char rdat[10]={0};
  38          void main()
  39          {
  40   1              EX0=0;//enable int 1
  41   1              EX1=1;//
  42   1              ET0  = 0;//disable 2 timer
  43   1              ET1  = 0;//
  44   1              IT0=0;//
  45   1              IT1=1;//edge trigger
  46   1      
  47   1              EA=1;
  48   1              P1=~0x00;
  49   1      
  50   1              for(;;);
  51   1      
  52   1      }
  53          unsigned char func,pw,pr;
  54          void interrupt_func1() interrupt 2
  55          {
C51 COMPILER V7.06   T                                                                     06/27/2008 14:25:55 PAGE 2   

  56   1              unsigned char k1,k2,k3;
  57   1              delay(1);
  58   1              k1=KEY_LINE1;
  59   1              k2=KEY_LINE2;
  60   1              k3=KEY_LINE3;
  61   1      
  62   1      
  63   1              if(k1==0)
  64   1              {
  65   2                      func=(func+1)%4;
  66   2      
  67   2                      if(func==0) pw=0;
  68   2                      else if(func==1) pr=0;
  69   2      
  70   2                      P1=~func;
  71   2              }
  72   1      
  73   1      
  74   1              if(func==0)//pw display
  75   1              {
  76   2                      if(k2==0)       {unsigned int i;for(i=0;i<10;i++)rdat[i]=0; P1=~0xA0;}//clear rdat to 0
  77   2                      else if(k3==0)  {unsigned int i;for(i=0;i<10;i++)wdat[i]=0xAA; P1=~0xAA;}//set wdat to 0xAA
  78   2              }
  79   1              else if(func==1)//pr display
  80   1              {
  81   2                      if(k2==0)       {pw=(pw+9)%10;P1=~wdat[pw];}//pw--
  82   2                      else if(k3==0)  {pw=(pw+1)%10;P1=~wdat[pw];}//pw++
  83   2              }
  84   1              else if(func==2)//pr display
  85   1              {
  86   2                      if(k2==0)       {pr=(pr+9)%10;P1=~rdat[pr];}//pr--
  87   2                      else if(k3==0)  {pr=(pr+1)%10;P1=~rdat[pr];}//pr++
  88   2              }
  89   1      #if 0
                      else if(func==3)//write and read
                      {
                              if(k2==0)       {AT24C64_W(wdat,0x100,10); P1=~0xF0; }// write
                              else if(k3==0)  {AT24C64_R(rdat,0x100,10); P1=~0xF1;}// read
                      }
              #else
  96   1              else if(func==3)//write and read
  97   1              {
  98   2                      if(k2==0)       {I2C_SendToSubAddress(0xa0,0x100,wdat,10); P1=~0xF3; }// write
  99   2                      else if(k3==0)  {I2C_ReceiveFromSubAddress(0xa0,0x100,rdat,10); P1=~0xF1;}// read
 100   2              }
 101   1      #endif
 102   1      
 103   1      }
 104          
 105          #if 0
              #define I2C_SCK SCL
              #define I2C_SDA SDA
              
              
              /*24C64子程序 */
              void  Delay_10_uS(void)
              {
               //uchar i=10;
               //while(i--);
              }
              void Delay_N_mS( uint n_milisecond)  /* n mS delay */
              {
C51 COMPILER V7.06   T                                                                     06/27/2008 14:25:55 PAGE 3   

               uint i;
               while(n_milisecond--)
               {
                i=10;//37;
                while(i--);
               }
              }
              bit I2C_Start(void)
              {
               Delay_10_uS();
               I2C_SDA =1;
               Delay_10_uS();
               I2C_SCK =1;
               Delay_10_uS();
               if ( I2C_SDA == 0) return 0;
               if ( I2C_SCK == 0) return 0;
               I2C_SDA = 0;
               Delay_10_uS();
               I2C_SCK = 0;
               Delay_10_uS();
               return 1;
              }
              void  I2C_Stop(void)
              {
               Delay_10_uS();
               I2C_SDA = 0;
               Delay_10_uS();
               I2C_SCK = 1;
               Delay_10_uS();
               I2C_SDA = 1;
               Delay_10_uS();
              }
              void I2C_Ack(void)
              {
               Delay_10_uS();
               I2C_SDA=0;
               Delay_10_uS();
               I2C_SCK=1;
               Delay_10_uS();
               I2C_SCK=0;
               Delay_10_uS();
              }
              void I2C_Nack(void)
              {
               Delay_10_uS();
               I2C_SDA=1;
               Delay_10_uS();
               I2C_SCK=1;
               Delay_10_uS();
               I2C_SCK=0;
               Delay_10_uS();
              }
              bit I2C_Send_Byte( uchar d)
              {
               uchar i = 8;
               bit bit_ack;
               while( i-- )
               {
                Delay_10_uS();
                if ( d &0x80 )   I2C_SDA =1;
                else             I2C_SDA =0;
                Delay_10_uS();
C51 COMPILER V7.06   T                                                                     06/27/2008 14:25:55 PAGE 4   

                I2C_SCK = 1;
                Delay_10_uS();
                I2C_SCK = 0;
                d = d << 1;
               }
               Delay_10_uS();
               I2C_SDA = 1;
               Delay_10_uS();
               I2C_SCK = 1;
               Delay_10_uS();
               bit_ack = I2C_SDA;
               I2C_SCK =0;
               Delay_10_uS();
               return bit_ack;
              }
              uchar I2C_Receive_Byte(void)
              {
               uchar i = 8, d;
               Delay_10_uS();
               I2C_SDA = 1;
               while ( i--)
               {
                d = d << 1;
                Delay_10_uS();
                I2C_SCK =1;
                if ( I2C_SDA ) d++;
                Delay_10_uS();
                I2C_SCK =0;
               }
               return d;
              }
              void AT24C64_W(void *mcu_address,uint AT24C64_address,uint count)
              {
               //DOG_WDI=!DOG_WDI;
               //DOGTIME=0;
               while(count--)
               {
                I2C_Start();
                /*I2C_Send_Byte( 0xa0 + AT24C64_address /256 *2);*/  /* 24C16  USE */
                I2C_Send_Byte( 0xa0 );
                I2C_Send_Byte(  AT24C64_address/256 );
                I2C_Send_Byte( AT24C64_address %256 );
                I2C_Send_Byte( *(uchar*)mcu_address );

⌨️ 快捷键说明

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