demo.LST
上传用户:zqdhsx28
上传日期:2010-03-30
资源大小:154k
文件大小:10k
源码类别:

RFID编程

开发平台:

C/C++

  1. C51 COMPILER V7.50   DEMO                                                                  04/04/2005 11:43:52 PAGE 1   
  2. C51 COMPILER V7.50, COMPILATION OF MODULE DEMO
  3. OBJECT MODULE PLACED IN demo.OBJ
  4. COMPILER INVOKED BY: C:KeilC51BINC51.EXE demo.c BROWSE DEBUG OBJECTEXTEND
  5. line level    source
  6.    1          #include <reg52.h>
  7.    2          //#include <string.h>
  8.    3          //#include <stdio.h>
  9.    4          
  10.    5          #define uchar unsigned char
  11.    6          
  12.    7          #define EMBIT P1^1
  13.    8          
  14.    9          uchar OLDEM=0;
  15.   10          
  16.   11          //u2270b 读卡模块,利用T0解码
  17.   12          
  18.   13                  SCON |= 0xc0;  //开启帧错误位。UART设置为9位。
  19. *** ERROR C129 IN LINE 13 OF DEMO.C: missing ';' before '|='
  20.   14                  TCON |= 0x00;  
  21.   15                  PCON &= 0x7f; 
  22.   16                  TMOD |= 0x11;  //定义T0工作模式定时器0作为双8位定时计数         器。
  23.   17                                         //TL0为8位定时/计数器通过标准定时器0控制位控制。
  24.   18                                         //TH0仅作为8位定时器,由定时器1控制位控制,此模式下定时/计数器1关闭。
  25.   19          
  26.   20          bit bitchange(void)//检查数据
  27.   21              {
  28.   22                uchar outtime;
  29.   23                bit bitc;
  30.   24                bitc=1;
  31.   25                outtime=200;
  32.   26          bitchlp1:      
  33.   27                if (((EMBIT==OLDEM) && (outtime!=0))==1)
  34.   28                 {
  35.   29                   outtime--;
  36.   30                   rst_wdog();
  37.   31                   goto bitchlp1;
  38.   32                 }
  39.   33                if (outtime==0)
  40.   34                 {
  41.   35                  bitc=0;
  42.   36                 }
  43.   37                OLDEM=EMBIT;
  44.   38                return bitc;
  45.   39              }
  46.   40          
  47.   41          bit findlongpluse(void)
  48.   42              {
  49.   43                bit retbit;
  50.   44                retbit=1;
  51.   45                OLDEM=EMBIT;
  52.   46                TH0=0;
  53.   47                TL0=0;
  54.   48                TR0=0;
  55.   49                if (bitchange()==0)
  56.   50                 {
  57.   51                   goto errfindlong;
  58.   52                 }
  59.   53                TR0=1;
  60.   54          findllp1:
  61. C51 COMPILER V7.50   DEMO                                                                  04/04/2005 11:43:52 PAGE 2   
  62.   55                if (bitchange()==0)
  63.   56                 {
  64.   57                   goto errfindlong;
  65.   58                 }
  66.   59                TR0=0;
  67.   60                if (TH0>2)
  68.   61                 {
  69.   62                   goto errfindlong;
  70.   63                 }
  71.   64                if (TH0==2)
  72.   65                 {
  73.   66                   goto findllp2;
  74.   67                 }
  75.   68                if ((TH0==1) && (TL0>98)) 
  76.   69                 {
  77.   70                   goto findllp2;
  78.   71                 }
  79.   72                if ((TH0==0) && (TL0<100))
  80.   73                 {
  81.   74                   goto errfindlong;
  82.   75                 }
  83.   76                TH0=0;
  84.   77                TL0=0;
  85.   78                TR0=1;
  86.   79                goto findllp1;
  87.   80          errfindlong:retbit=0;
  88.   81          findllp2:   return retbit;
  89.   82              }
  90.   83          
  91.   84          bit readbit(void)
  92.   85             {
  93.   86               bit retbit;
  94.   87               retbit=1;
  95.   88               TH0=0;
  96.   89               TL0=0;
  97.   90               TR0=1;
  98.   91               if (bitchange()==0)
  99.   92                {
  100.   93                  goto errreadbit;
  101.   94                }
  102.   95               TR0=0;
  103.   96               if (TH0>2)
  104.   97                {
  105.   98                 goto errreadbit;
  106.   99                }
  107.  100               if ((TH0==0) && (TL0<100))
  108.  101                {
  109.  102                  goto errreadbit;
  110.  103                }
  111.  104               if (TH0==2)
  112.  105                {
  113.  106                 goto okreadbit;
  114.  107                }
  115.  108               if ((TH0==1) && (TL0>35))
  116.  109                {
  117.  110                  goto okreadbit;
  118.  111                }
  119.  112               TH0=0;
  120.  113               TL0=0;
  121.  114               TR0=1;
  122.  115               if (bitchange()==0)
  123.  116                {
  124. C51 COMPILER V7.50   DEMO                                                                  04/04/2005 11:43:52 PAGE 3   
  125.  117                  goto errreadbit;
  126.  118                }
  127.  119               TR0=0;
  128.  120               if (TH0>1)
  129.  121                {
  130.  122                 goto errreadbit;
  131.  123                }
  132.  124               if ((TH0==0) && (TL0<100))
  133.  125                {
  134.  126                 goto errreadbit;
  135.  127                }
  136.  128               if ((TH0==1) && (TL0>35))
  137.  129                {
  138.  130                 goto errreadbit;
  139.  131                }
  140.  132               goto okreadbit;
  141.  133          errreadbit:retbit=0;
  142.  134          okreadbit:return retbit;
  143.  135             }
  144.  136          
  145.  137          bit findbegin(void)
  146.  138              {
  147.  139               bit retbit;
  148.  140               uchar tempdata;
  149.  141               uint fk;
  150.  142               fk=1000;
  151.  143               retbit=1;
  152.  144               tempdata=0;
  153.  145               if (findlongpluse()==0)
  154.  146                {
  155.  147                  goto errfindbegin;
  156.  148                }
  157.  149          findbelp1:
  158.  150               if (readbit()==0)
  159.  151                {
  160.  152                 goto errfindbegin;
  161.  153                }
  162.  154               if (OLDEM==0)
  163.  155                {
  164.  156                 if (tempdata==0xff)
  165.  157                  {
  166.  158                   goto okfindbegin;
  167.  159                  }
  168.  160                 tempdata=tempdata<<1;
  169.  161                 tempdata=tempdata | 1;
  170.  162                }
  171.  163               else
  172.  164                {
  173.  165                 tempdata=tempdata<<1;
  174.  166                }
  175.  167               fk--;
  176.  168               if (fk==0)
  177.  169                {
  178.  170                 goto errfindbegin;
  179.  171                }
  180.  172               goto findbelp1;
  181.  173          errfindbegin: retbit=0;
  182.  174          okfindbegin:return retbit;
  183.  175              }
  184.  176          
  185.  177          bit rdemdata(void)
  186.  178              {
  187. C51 COMPILER V7.50   DEMO                                                                  04/04/2005 11:43:52 PAGE 4   
  188.  179                bit retbit;
  189.  180                uchar i;
  190.  181                uchar j;
  191.  182                uchar parity;
  192.  183                uchar emcheck;
  193.  184                emcheck=0;
  194.  185                retbit=1;
  195.  186                if (findbegin()==0)
  196.  187                 {
  197.  188                  goto errrdem;
  198.  189                 }
  199.  190                for (j=0;j<=4;j++)
  200.  191                 {
  201.  192                  parity=0;
  202.  193                  for (i=1;i<=4;i++)
  203.  194                   {
  204.  195                    if (readbit()==0)
  205.  196                     {
  206.  197                      goto errrdem;
  207.  198                     }
  208.  199                    emdata[j]=emdata[j]<<1;
  209.  200                    if (OLDEM==0)
  210.  201                     {
  211.  202                       emdata[j]=emdata[j] | 1;
  212.  203                       parity++;
  213.  204                     }
  214.  205                   }
  215.  206                  if (readbit()==0)
  216.  207                   {
  217.  208                    goto errrdem;
  218.  209                   }
  219.  210                  if (OLDEM==0)
  220.  211                   {
  221.  212                     parity++;
  222.  213                   }
  223.  214                  if ((parity & 1)==1)
  224.  215                   {
  225.  216                     goto errrdem;
  226.  217                   }
  227.  218                  parity=0;
  228.  219                 
  229.  220                 for (i=1;i<=4;i++)
  230.  221                   {
  231.  222                     if (readbit()==0)
  232.  223                      {
  233.  224                       goto errrdem;
  234.  225                      }
  235.  226                     emdata[j]=emdata[j]<<1;
  236.  227                     if (OLDEM==0)
  237.  228                      {
  238.  229                       emdata[j]=emdata[j] | 1;
  239.  230                       parity++;
  240.  231                      }
  241.  232                    }
  242.  233                  if (readbit()==0)
  243.  234                   {
  244.  235                        goto errrdem;
  245.  236                   }
  246.  237                  if (OLDEM==0)
  247.  238                   {
  248.  239                        parity++;
  249.  240                   }
  250. C51 COMPILER V7.50   DEMO                                                                  04/04/2005 11:43:52 PAGE 5   
  251.  241                  if ((parity&1)==1)
  252.  242                      {
  253.  243                        goto errrdem;
  254.  244                      }
  255.  245                  }
  256.  246                  for (i=1;i<=5;i++)
  257.  247                   {
  258.  248                    if (readbit()==0)
  259.  249                     {
  260.  250                       goto errrdem;
  261.  251                     }
  262.  252                    emcheck=emcheck<<1;
  263.  253                    if (OLDEM==0)
  264.  254                     {
  265.  255                       emcheck=emcheck | 1;
  266.  256                     }
  267.  257                   }
  268.  258                  if ((emcheck&1)==1)
  269.  259                   {
  270.  260                     goto errrdem;
  271.  261                   }
  272.  262                  emcheck=emcheck<<3;
  273.  263                  for (j=0;j<=3;j++)
  274.  264                   {
  275.  265                    parity=0;
  276.  266                    for (i=0;i<=4;i++)
  277.  267                     {
  278.  268                       if (((emdata[i]<<j) & 0x80)==0x80)
  279.  269                        {
  280.  270                          parity++;
  281.  271                        }
  282.  272                       if (((emdata[i]<<j) & 0x8)==0x8)
  283.  273                        {
  284.  274                         parity++;
  285.  275                        }
  286.  276                     }
  287.  277                    if (((emcheck<<j) & 0x80)==0x80)
  288.  278                     {
  289.  279                       parity++;
  290.  280                     }
  291.  281                    if ((parity%2)==1)
  292.  282                     {
  293.  283                      goto errrdem;
  294.  284                     }
  295.  285                   }
  296.  286                  goto okrdemdata;
  297.  287          errrdem:retbit=0;
  298.  288          okrdemdata:return retbit;
  299.  289              }
  300.  290          
  301.  291          
  302.  292          
  303. C51 COMPILATION COMPLETE.  0 WARNING(S),  1 ERROR(S)