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

📄 text0.lst

📁 proteus实例集锦
💻 LST
字号:
C51 COMPILER V7.06   TEXT0                                                                 04/05/2007 20:30:13 PAGE 1   


C51 COMPILER V7.06, COMPILATION OF MODULE TEXT0
OBJECT MODULE PLACED IN Text0.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE Text0 BROWSE DEBUG OBJECTEXTEND

stmt level    source

   1          #define _PPDATAT_H
   2          
   3          #include <reg51.h>
   4          #include <string.h>
   5          
   6          #define uchar unsigned char
   7          #define uint unsigned int
   8          
   9          /* 握手信号宏定义 */
  10          #define CALL 0x24               // 主机呼叫
  11          #define OK 0x00                 // 从机准备好
  12          
  13          #define MAXLEN 64               // 缓冲区最大长度
  14          
  15          uchar buf[MAXLEN];
  16          
  17          sbit  p00 = P0^0; sbit  p01 = P0^1; sbit  p02 = P0^2; sbit  p03 = P0^3;
  18          sbit p10=P1^0; sbit p11=P1^1; sbit p12=P1^2; sbit p13=P1^3;
  19          sbit p14=P1^4; sbit p15=P1^5; sbit p16=P1^6; sbit p17=P1^7;
  20          sbit p23 = P2^3;sbit p25 = P2^5;sbit p27 = P2^7;
  21          
  22          unsigned char a;
  23          unsigned char b;
  24          unsigned char c;
  25          unsigned char d;
  26          unsigned char in1,in2,in3,count;
  27          unsigned char j1,j2;
  28          unsigned char z1,z2,z3;
  29          unsigned int x=1234;
  30          bit qidong;
  31          
  32          void delay();
  33          
  34          //********************八段码*************************//
  35          code unsigned char LEDMAP[] = { 
  36          0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07,
  37          0x7f, 0x6f, 0x00,0x71//共阳显示码,分别显示0、1、2、3、4、5、6、7、8、9、灭、F。
  38          };
  39          //***********************显示码选择**********************//
  40          int DisplayLED(unsigned char j)
  41          {
  42   1              unsigned int i=0;
  43   1              unsigned int x1;
  44   1              x1= LEDMAP[(i+j) & 0x0f];
  45   1              return  x1;
  46   1      }
  47          //***********************转换*************************//
  48          void si()
  49          {
  50   1          unsigned int M;
  51   1              a=x%10;
  52   1              M=x/10;
  53   1              b=M%10;
  54   1              M=M/10; 
  55   1              c=M%10;
C51 COMPILER V7.06   TEXT0                                                                 04/05/2007 20:30:13 PAGE 2   

  56   1              d=M/10;//a取出第四位,b取出第三位,c取出第二位,d取出第一位
  57   1      }
  58          //***********************显示**********************//
  59          void  display()
  60          {
  61   1          si();
  62   1              P0=0xf7;
  63   1              P1=DisplayLED(a);
  64   1              delay();
  65   1              P0=0xfb;
  66   1              P1=DisplayLED(b);
  67   1              delay();
  68   1              P0=0xfd;
  69   1              P1=DisplayLED(c);
  70   1              delay();
  71   1              P0=0xfe;
  72   1              P1=DisplayLED(d);
  73   1              delay();        
  74   1      }
  75          //************************扫描按键**********************//
  76          void timer0() interrupt 1 using 1
  77          {
  78   1              in1=p23;
  79   1              in2=p25;
  80   1              in3=p27;
  81   1              TH0=0xc3;
  82   1              TL0=0x50;
  83   1              count++;
  84   1      
  85   1              if(in1==0)
  86   1                      z1++;
  87   1              if(in2==0)
  88   1                      z2++;
  89   1              if(in3==0)
  90   1                      z3++;
  91   1              if(count==40)
  92   1              {
  93   2      //*************************x+***********************//
  94   2              if((0<z1)&(z1<40))
  95   2                              x++;
  96   2                      if (z1==40)
  97   2                              j1++;
  98   2                      count=0;
  99   2                      z1=0;
 100   2                      if((0<j1)&(j1<6))
 101   2                              x++;
 102   2                      if((5<j1)&(j1<11))
 103   2                              x=x+10;
 104   2                      if(10<j1)
 105   2                              x=x+100;
 106   2                      if(in1==1)
 107   2                              j1=0;
 108   2       //************************x-*******************//
 109   2                      if((0<z2)&(z2<40))
 110   2                              x--;
 111   2                      if (z2==40)
 112   2                              j2++;
 113   2                      z2=0;
 114   2                      if((0<j2)&(j2<6))
 115   2                              x--;
 116   2                      if((5<j2)&(j2<11))
 117   2                              x=x-10;
C51 COMPILER V7.06   TEXT0                                                                 04/05/2007 20:30:13 PAGE 3   

 118   2                      if(10<j2)
 119   2                              x=x-100;
 120   2                      if(in1==1)
 121   2                              j2=0;
 122   2       //************************启动*******************//
 123   2                      if(z3>5)
 124   2                        qidong=1;
 125   2               }  
 126   1      }
 127          void init()
 128          {
 129   1           TMOD=0x21;                          //定时器0工作于方式1,定时器1工作于方式2
 130   1              TH1 = 250;                          // 设置初值
 131   1                  TL1 = 250;
 132   1      
 133   1                  PCON = 0x80;                        // SMOD = 1
 134   1                  SCON = 0x50;                        //工作方式1,波特率9600bps,允许接收 
 135   1      
 136   1                  ET0=1;                              //允许定时器0中断
 137   1                  TR0=1;                              //定时器0开始工作
 138   1                  TR1 = 1;                            //定时器1开始工作
 139   1                  EA=1;                               //打开所有中断
 140   1      
 141   1      }
 142          //*************************delay*********************//
 143          void delay()
 144          {
 145   1              unsigned int i,n;
 146   1              n=100;
 147   1              for (i=0; i<n; i++) {}
 148   1      }
 149          //************************CRC计算****************************************//
 150          uint getcrc(uchar *s,uchar len)
 151          {
 152   1        uint acc=0,i,j=0;
 153   1      while(len--)
 154   1       {
 155   2          acc=acc^(*s++<<8);
 156   2          for(i=0;i++<8;)
 157   2            if(acc&0x8000)
 158   2              acc=(acc<<1)^0x1021;
 159   2            else
 160   2              acc=acc<<1;
 161   2       }
 162   1       return(acc);
 163   1      }
 164          
 165          
 166          //************************串口通信程序****************************************//
 167          
 168          /* 发送数据函数 */
 169          void senddata(uchar *buf)
 170          {
 171   1              uchar i;
 172   1              uchar len;                                      // 保存数据长度
 173   1              uint ecc;                                       // 保存校验字节
 174   1      
 175   1              len = strlen(buf);                      // 计算要发送数据的长度
 176   1      
 177   1              /* 发送数据长度 */
 178   1              TI = 0;
 179   1              SBUF = len;                                     // 发送长度
C51 COMPILER V7.06   TEXT0                                                                 04/05/2007 20:30:13 PAGE 4   

 180   1              while(!TI);
 181   1              TI = 0;
 182   1          /* 发送数据和校验字节 */
 183   1          ecc=getcrc(buf,len);
 184   1          buf[len]=ecc/256;
 185   1          buf[len+1]=ecc%256;
 186   1              for (i=0;i<len+2;i++)
 187   1              {
 188   2                      SBUF = *buf;
 189   2                      buf++;
 190   2                      while(!TI);
 191   2                      TI = 0;
 192   2              }
 193   1      }       
 194          void tongxin()
 195          { 
 196   1              uchar i = 0;
 197   1              uchar tmp; 
 198   1              /* 发送呼叫信号CALL并接收应答信息,如果没有接收到从机准备好的信号,则重新发送呼叫帧 */
 199   1              while(tmp!=OK)                  
 200   1              {
 201   2                      /* 发送呼叫信号CALL */
 202   2                      TI = 0;
 203   2                      SBUF = CALL;
 204   2                      while(!TI);
 205   2                      TI = 0;
 206   2      
 207   2                      /* 接收从机应答 */
 208   2                      RI = 0;
 209   2                      while(!RI);
 210   2                      tmp = SBUF;
 211   2                      RI = 0;         
 212   2              }
 213   1      
 214   1              
 215   1      }
 216          
 217          
 218          //*************************主函数***********************//
 219          void  main()
 220          {
 221   1                 init();
 222   1                 while(1)
 223   1                 {
 224   2                   display();
 225   2                   if(qidong==1)
 226   2                    {
 227   3                     si();
 228   3                     buf[0]=a;buf[1]=b;            
 229   3                     buf[2]=c;buf[3]=d;
 230   3                     senddata(buf);
 231   3                     tongxin();
 232   3                     qidong=0;     
 233   3                    }
 234   2                 }  
 235   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    854    ----
   CONSTANT SIZE    =     12    ----
   XDATA SIZE       =   ----    ----
C51 COMPILER V7.06   TEXT0                                                                 04/05/2007 20:30:13 PAGE 5   

   PDATA SIZE       =   ----    ----
   DATA SIZE        =     79      15
   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 + -