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

📄 iicled.lst

📁 VB环境下的串口通讯设计
💻 LST
字号:
C51 COMPILER V8.05a   IICLED                                                               01/07/2008 22:56:23 PAGE 1   


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

line level    source

   1          /************************************************/
   2          #include <REG52.H>
   3          #include <intrins.h>
   4          #define uchar unsigned char
   5          #define uint unsigned int
   6          #define ulong unsigned long
   7          #define int8 unsigned char
   8          #define int16 unsigned int
   9          #define int32 unsigned long 
  10          sbit I2C_SDA= P1^5;
  11          sbit I2C_SCK= P1^4;
  12          sbit I2C_WP= P1^3;
  13          
  14          //============================
  15          sbit LED1=P3^4;
  16          sbit LED2=P1^6;
  17          sbit GRE=P1^7;
  18          sbit s1=P0^3;
  19          sbit s2=P2^3;
  20          sbit SCK=P2^4;
  21          sbit RCK=P2^5;
  22          sbit nG=P2^6;
  23          sbit SER=P2^7;
  24          uchar xdata tab[16][6];
  25          uchar count;
  26          uchar l;
  27          uint m;
  28          
  29          void McuInit(void);
  30          void Timer_Int();
  31          //===============================================
  32          /* 列选择*/
  33          void lay(int8 n)
  34          {
  35   1              int8 i;
  36   1              i=n;
  37   1              s1=0;
  38   1              s2=0;
  39   1              if(n<8)
  40   1              {
  41   2                      //_nop_();
  42   2                      P0=(P0&0xf8)|(~i);
  43   2              }
  44   1              else
  45   1              {       i=i-7;
  46   2                      i=i&0x07;
  47   2                      i=i|0xf0;                 //保护nG位
  48   2                      P2=(P2&0xf8)|(~i);
  49   2              }
  50   1      
  51   1      }               
  52          /*延时*/
  53          void delay(int8 N)
  54          {
  55   1              int8 i,j,k;
C51 COMPILER V8.05a   IICLED                                                               01/07/2008 22:56:23 PAGE 2   

  56   1              for(i=0;i<100;i++)
  57   1                      for(j=0;j<10;j++)
  58   1                              for(k=0;k<N;k++)GRE=~GRE;       
  59   1      
  60   1      }
  61          /*发送字节,移位发送*/
  62          void WriteByte(int8 val)
  63          {
  64   1              int8 i,m;
  65   1              m=~val;
  66   1              for (i = 8; i > 0; i --)
  67   1              {
  68   2              SCK = 0;//拉低74HC595时钟
  69   2              SER = m&0x01;//发送74HC595一位串行数据
  70   2              SCK = 1;//拉高74HC595时钟
  71   2                      m=m>>1;
  72   2              _nop_();//延时
  73   2        }
  74   1        SER = 1;//释放数据总线
  75   1      }
  76          
  77          /*发送字*/
  78          void display(int8 n )
  79          {
  80   1              int8 i;
  81   1              for(i=0;i<6;i++)
  82   1              WriteByte(tab[n][i]);
  83   1          RCK=0;      //保存并行数据
  84   1          _nop_();
  85   1          RCK=1;
  86   1      }
  87          
  88          void delays(int8 n)
  89          {       n=n;
  90   1              m=m+0x1;
  91   1              LED1=m&0x800;
  92   1              GRE=~LED1;
  93   1              LED2=m&0x1000;
  94   1      }
  95          
  96          void XianShiX(void)
  97          {
  98   1              /**/display(0);//行0
  99   1                      lay(14);   //列
 100   1                      delays(1); //短延时
 101   1              /**/display(1);//行1
 102   1                      lay(13);
 103   1                      delays(1);
 104   1              /**/display(2);//行2
 105   1                      lay(12);
 106   1                      delays(1);
 107   1              /**/display(3);//行3
 108   1                      lay(11);
 109   1                      delays(1);
 110   1              /**/display(4);//行4
 111   1                      lay(10);
 112   1                      delays(1);
 113   1              /**/display(5);//行5
 114   1                      lay(9);
 115   1                      delays(1);
 116   1              /**/display(6);//行6
 117   1                      lay(8);
C51 COMPILER V8.05a   IICLED                                                               01/07/2008 22:56:23 PAGE 3   

 118   1                      delays(1);
 119   1      
 120   1              ///**/Timer_Int();
 121   1              /**/display(7);//行7
 122   1                      lay(15);
 123   1                      delays(1);
 124   1              /**/display(8);//行8
 125   1                      lay(7);
 126   1                      delays(1);
 127   1              /**/display(9);//行9
 128   1                      lay(6);
 129   1                      delays(1);
 130   1              /**/display(10);//行10
 131   1                      lay(5);
 132   1                      delays(1);
 133   1              /**/display(11);//行11
 134   1                      lay(4);
 135   1                      delays(1);
 136   1              /**/display(12); //行12
 137   1                      lay(0);
 138   1                      delays(1);
 139   1              /**/display(13); //行13
 140   1                      lay(1);
 141   1                      delays(1);
 142   1              /**/display(14); //行14
 143   1                      lay(2);
 144   1                      delays(1);
 145   1              /**/display(15);  //行15
 146   1                      lay(3);
 147   1                      delays(1);
 148   1      }
 149          //=============================
 150          //延时10US
 151          //内部调用函数
 152          void  Delay_10_uS(void)
 153          {
 154   1           char i=2;
 155   1           while(i--);
 156   1      }
 157          
 158          
 159          
 160          //开始位
 161          //内部调用函数
 162          bit I2C_Start(void)
 163          {
 164   1           Delay_10_uS();
 165   1           I2C_SDA =1;
 166   1           Delay_10_uS();
 167   1           I2C_SCK =1;
 168   1           Delay_10_uS();
 169   1           if ( I2C_SDA == 0) return 0;
 170   1           if ( I2C_SCK == 0) return 0;
 171   1           I2C_SDA = 0;
 172   1           Delay_10_uS();
 173   1           I2C_SCK = 0;
 174   1           Delay_10_uS();
 175   1           return 1;
 176   1      }
 177          
 178          //停止位
 179          //内部调用函数
C51 COMPILER V8.05a   IICLED                                                               01/07/2008 22:56:23 PAGE 4   

 180          void  I2C_Stop(void)
 181          {
 182   1           Delay_10_uS();
 183   1           I2C_SDA = 0;
 184   1           Delay_10_uS();
 185   1           I2C_SCK = 1;
 186   1           Delay_10_uS();
 187   1           I2C_SDA = 1;
 188   1           Delay_10_uS();
 189   1      }
 190          
 191          
 192          //读数据后拉高应答信号
 193          //内部调用函数
 194          void I2C_Nack(void)
 195          {
 196   1           Delay_10_uS();
 197   1           I2C_SDA=1;
 198   1           Delay_10_uS();
 199   1           I2C_SCK=1;
 200   1           Delay_10_uS();
 201   1           I2C_SCK=0;
 202   1           Delay_10_uS();
 203   1      }
 204          
 205          //写单字节数据
 206          //内部调用函数
 207          bit I2C_Send_Byte( uchar d)
 208          {
 209   1           uchar i = 8;
 210   1           bit bit_ack;
 211   1           while( i-- )
 212   1           {
 213   2                Delay_10_uS();
 214   2                if ( d &0x80 )   I2C_SDA =1;
 215   2                else             I2C_SDA =0;
 216   2                Delay_10_uS();
 217   2                I2C_SCK = 1;
 218   2                Delay_10_uS();
 219   2                I2C_SCK = 0;
 220   2                d = d << 1;
 221   2           }
 222   1           Delay_10_uS();
 223   1           I2C_SDA = 1;
 224   1           Delay_10_uS();
 225   1           I2C_SCK = 1;
 226   1           Delay_10_uS();
 227   1           bit_ack = I2C_SDA;
 228   1           I2C_SCK =0;
 229   1           Delay_10_uS();
 230   1           return bit_ack;
 231   1      }
 232          
 233          //接收单字节数据
 234          //内部调用函数
 235          uchar I2C_Receive_Byte(void)
 236          {
 237   1           uchar i = 8, d;
 238   1           Delay_10_uS();
 239   1           I2C_SDA = 1;
 240   1           while ( i--)
 241   1           {
C51 COMPILER V8.05a   IICLED                                                               01/07/2008 22:56:23 PAGE 5   

 242   2                d = d << 1;
 243   2                Delay_10_uS();
 244   2                I2C_SCK =1;
 245   2                if ( I2C_SDA ) d++;
 246   2                Delay_10_uS();
 247   2                I2C_SCK =0;
 248   2           }
 249   1           return d;
 250   1      }
 251          
 252          
 253          
 254          //读多字节数据
 255          //供外部调用函数
 256          void AT24C64_R(void *mcu_address,uint AT24C64_address,uint count)
 257          {
 258   1               s1=0;s2=0;nG=1;
 259   1           while(count--)
 260   1           {
 261   2                I2C_Start();
 262   2                /*I2C_Send_Byte( 0xa0 + AT24C64_address / 256 
 263   2      *2 );*/   /* 24C16 USE */
 264   2                I2C_Send_Byte( 0xa0 );//写命令设备地址为10100000最后一位为0"写标志"
 265   2                I2C_Send_Byte( AT24C64_address/256 );//写存储器页地址
 266   2                I2C_Send_Byte( AT24C64_address % 256 );//写存储器字节地址
 267   2                I2C_Start();
 268   2                /*I2C_Send_Byte( 0xa1 + AT24C64_address /256 *2 );*/
 269   2                I2C_Send_Byte( 0xa1 );//写命令设备地址为10100001最后一位为1"读标志"
 270   2                *(uchar*)mcu_address = I2C_Receive_Byte();//读单字节数据到MCU指针指向的地址
 271   2                I2C_Nack();//回应答信号
 272   2                I2C_Stop();
 273   2                ((uchar*)mcu_address)++;
 274   2                AT24C64_address++;
 275   2           }
 276   1              s1=1;s2=1;nG=0;  
 277   1      }
 278          
 279          //=====================================
 280          void main()
 281          {
 282   1              uchar len;
 283   1              McuInit();
 284   1              GRE=1;
 285   1              AT24C64_R(tab,0x00,96);
 286   1              TR0=0;
 287   1              //TR1=1;
 288   1              EA=0;
 289   1              while(1) 
 290   1              {
 291   2              nG=0;
 292   2              len=250;
 293   2              AT24C64_R(tab,0x00,96);
 294   2              while(len>0){XianShiX();len--;}
 295   2              len=250;
 296   2              AT24C64_R(tab,0x60,96);
 297   2              while(len>0){XianShiX();len--;}
 298   2              len=250;
 299   2              AT24C64_R(tab,0xc0,96);
 300   2              while(len>0){XianShiX();len--;}
 301   2              
 302   2              //AT24C64_R(tab,0x00,96);
 303   2              }
C51 COMPILER V8.05a   IICLED                                                               01/07/2008 22:56:23 PAGE 6   

 304   1      
 305   1      }
 306          
 307          
 308          
 309          void McuInit(void)
 310          {
 311   1              s1=0;s2=0;nG=1;
 312   1              EA=0;
 313   1              LED1=0;
 314   1              LED2=0;
 315   1              GRE=0;
 316   1              delay(250);
 317   1              LED1=1;
 318   1              LED2=0;
 319   1              GRE=0;
 320   1              delay(100);
 321   1              LED1=0;
 322   1              LED2=1;
 323   1              GRE=0;
 324   1              delay(90);
 325   1              LED1=0;
 326   1              LED2=0;
 327   1              GRE=1;
 328   1              delay(60);
 329   1              LED1=1;
 330   1              LED2=0;
 331   1              GRE=1;
 332   1              delay(40);
 333   1              LED1=1;
 334   1              LED2=1;
 335   1              GRE=0;
 336   1              delay(20);
 337   1              LED1=0;
 338   1              LED2=0;
 339   1              GRE=0;
 340   1              
 341   1          ET0 = 0;        //允许定时器0中断
 342   1          TMOD = 0X01;       //定时器工作方式选择
 343   1          TL0 = 0x00;     
 344   1          TH0 = 0x00;     //定时器赋予初值
 345   1          TR0 = 0;        //启动定时器
 346   1              TR1=0;
 347   1              EX0=0;
 348   1              EX1=0;
 349   1              EA =0 ;         //开总中断
 350   1              nG=0;
 351   1      
 352   1      }
 353          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    787    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =     96    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =      4       8
   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 + -