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

📄 lcd_key_1.lst

📁 基于Proteus的交通灯控制系统
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V8.15   LCD_KEY_1                                                             08/10/2008 20:26:24 PAGE 1   


C51 COMPILER V8.15, COMPILATION OF MODULE LCD_KEY_1
OBJECT MODULE PLACED IN LCD_KEY_1.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE LCD_KEY_1.C BROWSE DEBUG OBJECTEXTEND

line level    source

   1          #include <reg51.h>
   2          #define uchar unsigned char
   3          #include <1602lcd.ini>
   4          #define ns P2
   5          #define ew P3
   6          uchar led[6]={0xdd,0xfd,0xed,0xfb,0xf6,0xfe};
   7          uchar ctime[5]={8,2,5,2,5};
   8          uchar key,x=0,tround=0,sed=0,min=0,sedpre;
   9          uchar ledstate=0,ledsed=0;
  10          bit nsew=0;
  11          bit execute=0;             //执行
  12          bit upled=0;
  13          bit d_pause=0;
  14          uchar manage=0;
  15          uchar cnt1,cnt2,indata;
  16          uchar insed[3],inN,discount;
  17          //-----------------------------------------------------------------------------------
  18          void IT0R(void) interrupt 1 using 1
  19          {
  20   1      TH0=0x3c;
  21   1      TL0=0xb0;
  22   1      tround++;
  23   1      if (tround==10) {                        //1S时,更新时间
  24   2                       tround=0;
  25   2                       sed++;ledsed--;
  26   2                                       if (ledsed==255) ledsed=0;
  27   2                       if (sed==60) {sed=0;min++;}
  28   2                       }
  29   1      
  30   1      }
  31          
  32          //------------------------------------------------------------------------------------
  33          
  34          void delay(uchar ms){
  35   1      uchar i;
  36   1      while(ms--){
  37   2      for(i=0;i<125;i++);
  38   2      }
  39   1      }
  40          
  41          //------------------------------------------------------------------------------------
  42          
  43          
  44          //-----------------------------------------------------------------------------------
  45          int getkey(){
  46   1      return ((~P1)&0xf0);
  47   1      }
  48          //-----------------------------------------------------------------------------------
  49          //判断是否有键按下
  50          void chkkey(){
  51   1      if (getkey()) {
  52   2      delay(0x2);          //延时,去抖
  53   2      delay(0x02);
  54   2      }
  55   1      }
C51 COMPILER V8.15   LCD_KEY_1                                                             08/10/2008 20:26:24 PAGE 2   

  56          
  57          //-----------------------------------------------------------------------------------
  58          void findkey(){ //扫描法得出键值
  59   1      uchar i,k,j;
  60   1      i=(~P1)&0xf0;
  61   1      j=0x10;
  62   1      for (k=0;k<4;k++) {
  63   2      if (i&j) key=k;      //得出行号
  64   2      j<<=1;
  65   2      }
  66   1      key=key*4;
  67   1      P1=0xfe;
  68   1      if ((~P1)&0xf0) key=key;    //得出行键值=行号+列号
  69   1      P1=0xfd;
  70   1      if ((~P1)&0xf0) key=key+1;
  71   1      P1=0xfb;
  72   1      if ((~P1)&0xf0) key=key+2;
  73   1      P1=0xf7;
  74   1      if ((~P1)&0xf0) key=key+3;
  75   1      //}
  76   1      P1=0xf0;
  77   1      }
  78          //------------------------------------------------------------------------------------
  79          void disstate(){
  80   1      Set_LCM_XY(0,0);
  81   1      if (!nsew) Send_String_LCM("NS:");
  82   1          else Send_String_LCM("EW:");
  83   1      Set_LCM_XY(3,0);
  84   1      switch (ledstate){
  85   2      case 0:{Send_String_LCM("G+M     ");break;}
  86   2      case 1:{Send_String_LCM("G       ");break;}
  87   2      case 2:{Send_String_LCM("G+Rt    ");break;}
  88   2      case 3:{Send_String_LCM("Y       ");break;}
  89   2      case 4:{Send_String_LCM("R+Lt    ");break;}
  90   2      case 5:{Send_String_LCM("StopAll ");break;}
  91   2      
  92   2      
  93   2      
  94   2      }
  95   1      }
  96          
  97          //------------------------------------------------------------------------------------
  98          void Updatedis(uchar i){
  99   1      if (i!=5){
 100   2      ledsed=ctime[i];
 101   2      if (!nsew) {ns=led[i];ew=led[5];}          //2
 102   2          else {ew=led[i];ns=led[5];}
 103   2      if (manage==0) disstate();
 104   2      ledstate++;
 105   2      }
 106   1        else {  
 107   2                  nsew=~nsew;
 108   2                      ledstate=0;
 109   2                      }
 110   1      }
 111          //------------------------------------------------------------------------------------
 112          void trafficlamp()
 113          {
 114   1      if (ledstate==0) Updatedis(0);
 115   1        else { if (ledsed==0)  Updatedis(ledstate);}
 116   1      
 117   1      }
C51 COMPILER V8.15   LCD_KEY_1                                                             08/10/2008 20:26:24 PAGE 3   

 118          //-----------------------------------------------------------------------------------
 119          void discnt(){
 120   1      Send_Command_LCM(0x01);
 121   1      Set_LCM_XY(0,0);
 122   1      if (manage==1) {
 123   2                      Send_String_LCM("Regulate Ex-Time:");
 124   2                                      inN=0;
 125   2                                      Set_LCM_XY(0,1);
 126   2                                      switch (cnt1){
 127   3                                      case 1:{Send_String_LCM("Green+M    :");break;}
 128   3                                      case 2:{Send_String_LCM("Green      :");break;}
 129   3                                      case 3:{Send_String_LCM("Green+Right:");break;}
 130   3                                      case 4:{Send_String_LCM("Yellow     :");break;}
 131   3                                      case 5:{Send_String_LCM("Red+Light  :");break;}
 132   3                                      case 6:{Send_String_LCM("StopAll    :");break;}
 133   3                                      }
 134   2                                      Send_Command_LCM(0x0f);
 135   2                                      Send_Num_LCM(ctime[cnt1-1]/100);        //X=12
 136   2                                      Send_Num_LCM((ctime[cnt1-1]%100)/10);     //X=13
 137   2                                      Send_Num_LCM(ctime[cnt1-1]%10);   //X=14
 138   2                                      Set_LCM_XY(12,1);
 139   2                                       return;
 140   2                       }
 141   1      if (manage==2) {
 142   2                      Send_String_LCM("Emergency:");
 143   2                                      Set_LCM_XY(0,1);
 144   2                                      switch (cnt2){
 145   3                                      case 1:{Send_String_LCM("1.All Red ");break;}
 146   3                                      case 2:{Send_String_LCM("2.EW Stopped");break;}
 147   3                                      case 3:{Send_String_LCM("3.NS Stopped");break;}
 148   3                                       }
 149   2      
 150   2                                       return;
 151   2                       }
 152   1      if (manage==3) {
 153   2                      Send_String_LCM("Pause:");
 154   2                                      Set_LCM_XY(0,1);
 155   2                                      Send_String_LCM("Are you sure?");
 156   2                                      return;
 157   2                       }
 158   1      
 159   1      }
 160          //-----------------------------------------------------------------------------------
 161          void keyfun(){
 162   1      uchar i;
 163   1      if (key<=9) {if (manage!=1) return;
 164   2                     else {                    //输入数字
 165   3                                      Send_Num_LCM(key);
 166   3                                              insed[inN]=key;
 167   3                                              inN++;
 168   3                                              if (inN>=3) {inN=0;Set_LCM_XY(12,1);}
 169   3      
 170   3      
 171   3      
 172   3                                              }
 173   2      

⌨️ 快捷键说明

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