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

📄 串行.lst

📁 数码管的串行显示。有时候IO口不够用时候
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V6.23a  ____                                                                  07/23/2008 10:15:45 PAGE 1   


C51 COMPILER V6.23a, COMPILATION OF MODULE ____
OBJECT MODULE PLACED IN F:\设计\编译通~1\键盘串~1\串行.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE F:\设计\编译通~1\键盘串~1\串行.C DB SB OE

stmt level    source

   1          #include<reg51.h>
   2          #define uchar unsigned char
   3          #define uint  unsigned int
   4          uint z,num,numduan;
   5          uchar temp,numwei=0,numwei1;
   6          static west=0;
   7          
   8          uchar code tableduan[]={       //键盘表
   9          0x3f,0x06,0x5b,0x4f,
  10          0x66,0x6d,0x7d,0x07,
  11          0x7f,0x6f,0x77,0x7c,
  12          0x39,0x5e,0x79,0x71};
  13          
  14          uchar code tablewei[]={
  15          0xfe,0xfd,0xfb,0xf7,
  16          0xef,0xdf,0xbf,0x7f};
  17          
  18          
  19          
  20          void init();
  21          void sent(uchar aa);
  22          void receive();
  23          uchar jianpan();
  24          void display(uchar dis);
  25          uchar cc;
  26          
  27          void main()
  28          {
  29   1          init();
  30   1          while(1)
  31   1           {
  32   2             numduan=jianpan();
  33   2             display(cc);
  34   2      
  35   2           if(west) {
  36   3            cc=numduan;
  37   3            sent(numduan);
  38   3            west=0;  }
  39   2            
  40   2            
  41   2          receive();
  42   2            
  43   2      
  44   2           }
  45   1      
  46   1      }
  47          
  48          void init()
  49          {
  50   1        SM0=0;
  51   1         SM1=1;
  52   1         REN=1;
  53   1         TMOD=0x20;
  54   1         TH1=0xfd;
  55   1         TL1=0xfd;
C51 COMPILER V6.23a  ____                                                                  07/23/2008 10:15:45 PAGE 2   

  56   1         TR1=1;
  57   1         TI=0;
  58   1      
  59   1       }
  60          
  61          //------------------------------------------------
  62          void delay(uint z)
  63          
  64            {
  65   1             uint x,y;
  66   1           for(x=z;x>0;x--)
  67   1             for(y=120;y>0;y--);
  68   1         }
  69          
  70          
  71          void display(uchar dis)
  72          {
  73   1      
  74   1          P0=tableduan[dis];
  75   1          P2=0;
  76   1      
  77   1      
  78   1      }
  79          
  80          //--------------------------------键盘子程序:
  81          
  82           uchar jianpan( )
  83              {
  84   1                 P1=0xfe;
  85   1                 temp=P1;
  86   1                 temp=temp&0xf0;
  87   1      
  88   1                 if(temp!=0xf0)
  89   1      
  90   1                          {
  91   2                             delay(5);
  92   2                             temp=P1;
  93   2                             temp=temp&0xf0;
  94   2                             if(temp!=0xf0)
  95   2                                      {
  96   3                                        temp=P1;
  97   3                                      switch(temp)
  98   3                                                {
  99   4                                                   case 0xee: num=1; break;
 100   4                                               case 0xde: num=2; break;
 101   4                                               case 0xbe: num=3; break;
 102   4                                               case 0x7e: num=4; break;
 103   4                                                }
 104   3                                      }
 105   2                              while(temp!=0xf0)                   //松手检测
 106   2                                       {
 107   3                                           temp=P1;
 108   3                                           temp=temp&0xf0;
 109   3                                           west=1;
 110   3      
 111   3                                        }
 112   2                           }
 113   1      
 114   1      
 115   1      
 116   1      //-------------------------------------------
 117   1             P1=0xfd;
C51 COMPILER V6.23a  ____                                                                  07/23/2008 10:15:45 PAGE 3   

 118   1                 temp=P1;
 119   1                 temp=temp&0xf0;
 120   1      
 121   1                 if(temp!=0xf0)
 122   1      
 123   1                          {
 124   2                             delay(5);
 125   2                             temp=P1;
 126   2                             temp=temp&0xf0;
 127   2                             if(temp!=0xf0)
 128   2                                      {
 129   3                                        temp=P1;
 130   3                                      switch(temp)
 131   3                                                {
 132   4                                                   case 0xed: num=5; break;
 133   4                                                   case 0xdd: num=6; break;
 134   4                                                   case 0xbd: num=7; break;
 135   4                                                   case 0x7d: num=8; break;
 136   4                                                }
 137   3                                      }
 138   2                              while(temp!=0xf0)                   //松手检测
 139   2                                       {
 140   3                                           temp=P1;
 141   3                                           temp=temp&0xf0;
 142   3                                           west=1;
 143   3      
 144   3                                        }
 145   2                           }
 146   1      
 147   1      
 148   1      //-------------------------------------------
 149   1              P1=0xfb;
 150   1              temp=P1;
 151   1              temp=temp&0xf0;
 152   1      
 153   1               if(temp!=0xf0)
 154   1      
 155   1                 {
 156   2                      delay(5);
 157   2                     temp=P1;
 158   2                     temp=temp&0xf0;
 159   2                     if(temp!=0xf0)
 160   2                      {
 161   3                        temp=P1;

⌨️ 快捷键说明

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