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

📄 keyboard.lst

📁 小区可视对讲键盘检测程序.利用pt6964芯片.
💻 LST
📖 第 1 页 / 共 4 页
字号:
C51 COMPILER V8.08   KEYBOARD                                                              05/25/2008 20:21:42 PAGE 1   


C51 COMPILER V8.08, COMPILATION OF MODULE KEYBOARD
OBJECT MODULE PLACED IN keyboard.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE keyboard.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1          #include<stc12c5410ad.h>
   2          #include<buzzer.h>
   3          #include<main.h>
   4          #include<uart.h>
   5          #define KEY_601         0x61
   6          #define KEY_501         0x51
   7          #define KEY_401         0x41
   8          #define KEY_301         0x31
   9          #define KEY_201         0x21
  10          #define KEY_101         0x11
  11          #define KEY_602         0x62
  12          #define KEY_502         0x52
  13          #define KEY_402         0x42
  14          #define KEY_302         0x32
  15          #define KEY_202         0x22
  16          #define KEY_102         0x12
  17          #define KEY_SURE        0x01
  18          #define KEY_CANCLE      0x02
  19          #define KEY_CENTER      0x03
  20          #define KEY_SET         0x04
  21          #define KEY_NULL        0x00
  22          //----------------------------------
  23          //extern variables
  24          //-----------------------------------
  25          extern unsigned char buzzer_timer;
  26          extern unsigned char buzzer_timer_trigger;
  27          extern unsigned char display_buffer[4];
  28          extern unsigned char current_state;
  29          extern unsigned char send_buffer[4];
  30          
  31          void free_state_process(unsigned char key_codea)   ;
  32          void funcselect_state_process(unsigned char key_codeb);
  33          void fourthfunc_process(unsigned char key_codec);
  34          void callingcenter_process(unsigned char key_coded);
  35          void eighteenthfunc_process(unsigned char key_codee);
  36          /*-----------------------------------
  37          golbal variables
  38          -------------------------------------*/
  39          unsigned char keyboard_busy = 0; 
  40          unsigned char last_key = 0;
  41          unsigned char last_key_times = 0;
  42          unsigned char function_index = 0;
  43          
  44          unsigned char psw_buffer[6]={0,0,0,0,0,0};
  45          unsigned char psw_index = 0;
  46          //---------------------------------------------
  47          //functions about keyboard
  48          //--------------------------------------------- 
  49          
  50          //---------------------------------------------
  51          //keyboard initial so that we can test keyboard
  52          //---------------------------------------------
  53          void keyboard_initial(void)
  54          {
  55   1              P3M0 = P3M0 | 0x30; //P34  P35输入PM0=1,PM1=0
C51 COMPILER V8.08   KEYBOARD                                                              05/25/2008 20:21:42 PAGE 2   

  56   1              P3M1 = P3M1 & 0xcf;
  57   1              P2M0 = P2M0 | 0x30;      //P24  P25输入PM0=1,PM1=0
  58   1              P2M1 = P2M1 & 0xcf;
  59   1      }
  60          //----------------------------------------------
  61          //scan key board ,and return the key code
  62          //-----------------------------------------------
  63          unsigned char keyscan(void)
  64          {  
  65   1              unsigned char key_code = 0;
  66   1              unsigned char seg_temp = 0;
  67   1              unsigned char bit_temp = 0;
  68   1              unsigned char return_value =0;
  69   1      //save current pin values 
  70   1              if(P21 == 1)seg_temp=seg_temp|0x80;
  71   1              if(P12 == 1)seg_temp=seg_temp|0x40;
  72   1              if(P15 == 1)seg_temp=seg_temp|0x20;
  73   1              if(P16 == 1)seg_temp=seg_temp|0x10;
  74   1              if(P17 == 1)seg_temp=seg_temp|0x08;
  75   1              if(P20 == 1)seg_temp=seg_temp|0x04;
  76   1              if(P14 == 1)seg_temp=seg_temp|0x02;
  77   1              if(P23 == 1)bit_temp = bit_temp | 0x80;
  78   1              if(P22 == 1)bit_temp = bit_temp | 0x40;
  79   1              if(P11 == 1)bit_temp = bit_temp | 0x20;
  80   1              if(P13 == 1)bit_temp = bit_temp | 0x10;
  81   1      // test if any key pressed
  82   1              P21 = 1;
  83   1              P12     = 1;
  84   1              P15     = 1;
  85   1              P16     = 1;
  86   1              P17     = 1;
  87   1              P20 = 1;
  88   1              P14 = 1;
  89   1      
  90   1       
  91   1              P23     = 0;
  92   1              P22     = 1;
  93   1              P11     = 1;
  94   1              P13     = 1;
  95   1              if(P34 == 1){key_code = 0x61;     goto con; }
  96   1              if(P35 == 1){key_code = KEY_501;   goto con; }
  97   1              if(P24 == 1){key_code = KEY_401;   goto con; }
  98   1              if(P25 == 1){key_code = KEY_301;  goto con; }
  99   1      
 100   1      
 101   1      
 102   1              P23     = 1;
 103   1              P22     = 1;
 104   1              P11     = 0;
 105   1              P13     = 1;
 106   1              if(P34 == 1)key_code = KEY_602;
 107   1              if(P35 == 1)key_code = KEY_502;
 108   1              if(P24 == 1)key_code = KEY_402; 
 109   1              if(P25 == 1){key_code = KEY_302; }
 110   1      
 111   1      con:
 112   1      
 113   1         if(key_code != 0)goto con2;
 114   1      
 115   1              P23     = 1;
 116   1              P22     = 1;
 117   1              P11     = 1;
C51 COMPILER V8.08   KEYBOARD                                                              05/25/2008 20:21:42 PAGE 3   

 118   1              P13     = 0;
 119   1              if(P34 == 1){key_code = KEY_202; goto con2; }
 120   1              if(P35 == 1){key_code = KEY_102; goto con2; } 
 121   1              if(P24 == 1){key_code = KEY_CANCLE;  goto con2; }
 122   1              if(P25 == 1){key_code = KEY_SURE;  goto con2; } 
 123   1      
 124   1      
 125   1      
 126   1      
 127   1      
 128   1      
 129   1      
 130   1      
 131   1              P23     = 1;
 132   1              P22     = 0;
 133   1              P11     = 1;
 134   1              P13     = 1;
 135   1              if(P34 == 1)key_code = KEY_201;  
 136   1              if(P35 == 1)key_code = KEY_101;   
 137   1              if(P24 == 1)key_code = KEY_CENTER;
 138   1              if(P25 == 1)key_code = KEY_SET;  
 139   1      con2:
 140   1      
 141   1      //restore pins about
 142   1              if(bit_temp&0x80) P23 = 1;else P23 = 0;
 143   1              if(bit_temp&0x40) P22 = 1;else P22 = 0;
 144   1              if(bit_temp&0x20) P11 = 1;else P11 = 0;
 145   1              if(bit_temp&0x10) P13 = 1;else P13 = 0;
 146   1              if(seg_temp&0x80) P21 = 1;else P21 = 0;
 147   1              if(seg_temp&0x40) P12 = 1;else P12 = 0;
 148   1              if(seg_temp&0x20) P15 = 1;else P15 = 0;
 149   1              if(seg_temp&0x10) P16 = 1;else P16 = 0;
 150   1              if(seg_temp&0x08) P17 = 1;else P17 = 0;
 151   1              if(seg_temp&0x04) P20 = 1;else P20 = 0;
 152   1              if(seg_temp&0x02) P14 = 1;else P14 = 0;
 153   1      
 154   1      
 155   1      
 156   1      //judge if any key definitely pressed
 157   1      //situation 1: keyboard is busy
 158   1              if(keyboard_busy&&(key_code == 0)){keyboard_busy = 0;last_key = 0;return_value = key_code;}
 159   1              if(keyboard_busy&&(key_code != 0)){return_value = 0; }
 160   1      //situation 2:keyboard is not busy
 161   1              if(!keyboard_busy&&(key_code == 0)){last_key_times = 0;last_key = 0;return_value = KEY_NULL;}    //key_code
             - ==0
 162   1              if(!keyboard_busy&&(key_code != 0))                                      //key code !=0
 163   1              {                                                                        
 164   2              if(key_code != last_key){       
 165   3      
 166   3      
 167   3              last_key = key_code;last_key_times =1;return_value = KEY_NULL;}
 168   2              else{   
 169   3      
 170   3                                                                      last_key_times++;
 171   3                                                                      if(last_key_times >= 4){
 172   4                                                                                                                      last_key_times = 0;
 173   4                                                                                                                      keyboard_busy = 1;
 174   4                                                                                                              
 175   4                                                                                                                      return_value = key_code;
 176   4                                                                                                                      }
 177   3                                                                      else return_value = KEY_NULL;
 178   3                       }
C51 COMPILER V8.08   KEYBOARD                                                              05/25/2008 20:21:42 PAGE 4   

 179   2              }
 180   1              return return_value;
 181   1      }
 182          
 183          //--------------------------------------------------
 184          //process the key code ,come from key scan function
 185          //--------------------------------------------------
 186          void key_process(unsigned char key_codex) 
 187          {
 188   1       if((current_state&0xf8 )== STATE_FREE)free_state_process(key_codex);
 189   1       else if((current_state&0xf8) == STATE_FUNCSELECT) funcselect_state_process(key_codex);
 190   1       else if((current_state&0xf8) == STATE_FOURTHFUNC){fourthfunc_process(key_codex);}
 191   1       else if((current_state&0xf8) == STATE_CALLINGCENTER){callingcenter_process(key_codex);}
 192   1       else if((current_state&0xf8) == STATE_EIGHTEENTHFUNC){eighteenthfunc_process(key_codex);}
 193   1       else {open_buzzer();    //BEEP
 194   2                                                                       buzzer_timer = 125;
 195   2                                                                       buzzer_timer_trigger = 1;}
 196   1      }
 197          //--------------------------------------------------
 198          //process the key code ,come from key process function
 199          //--------------------------------------------------
 200          void free_state_process(unsigned char key_codea)
 201          {
 202   1              if(current_state&0x07 == STATE_FREE_CALLING)
 203   1              {

⌨️ 快捷键说明

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