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

📄 keycode.lst

📁 38键小键盘程序,可以实现大小键盘的切换工作,并且接收命令和液晶显示
💻 LST
字号:
C51 COMPILER V8.01   KEYCODE                                                               11/02/2007 21:28:31 PAGE 1   


C51 COMPILER V8.01, COMPILATION OF MODULE KEYCODE
OBJECT MODULE PLACED IN keycode.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE keycode.C OPTIMIZE(9,SPEED) BROWSE DEBUG OBJECTEXTEND

line level    source

   1          #include <reg51.h>
   2          #include <intrins.h>
   3          #include <string.h>
   4          #include  "Scod.h"
   5          ///////////////////////////////////////////////////////////////////
   6          sbit DATA=P3^4;     //用p3.3做数据线控制口(小键盘)
   7          sbit CLK =P3^2;     //用p3.2做时钟线控制口(小键盘)
   8          sbit Key_Data=P3^5; //定义接受标准键盘引脚控制口(数据线)
   9          //sbit Key_CLK=P3^3;  //定义接受标准键盘引脚控制口(时钟线,外部中断1)
  10          sbit inhibit=P4^0; //定义专用键盘和标准PS2键盘控制转换(P4.0)
  11          ///////////////////////////////////////////////////////////////////
  12          sbit a1 = P4^1;     //用p4.1做语音控制口1
  13          sbit a2 = P4^2;     //用p4.1做语音控制口2
  14          //////////////////////////////////////////////////////////////////
  15          sbit buzzer = P2^7;   //用p0.1做蜂鸣器控制口
  16          //////////////////////////////////////////////////////////////////
  17          sbit atxtflag  = P4^3; //用p4.3做AT/XT控制口(拨码开关)
  18          sbit bit1_6flag = P3^6; //用p3.6做1bit/6bit清除控制口(拨码开关)
  19          sbit numberflag = P3^7; //用p3.7做液晶显示数字和*号控制口(拨码开关)
  20          //////////////////////液晶控制位及数据接口/////////////////////////
  21          unsigned char code cdle_net[] = {"    WELCOME!    "}; 
  22          unsigned char code email[] = {"we do our best!!"}; 
  23          unsigned char code Cls[] = {"                "};   //清显示
  24          //字符以ASCII码存储,不需要转换
  25          //OSC=12MHZ 
  26          //LCMPORT=P2,4位模式,不带读“忙”状态功能, 
  27          //现用P0口实验. 
  28          //DATA(D7--D4),D3(E),D2(R/W),D1(RS),D0(VO). 
  29          sfr LCMPORT = 0x80; 
  30          sbit E=LCMPORT^3; 
  31          sbit RW=LCMPORT^2; 
  32          sbit RS=LCMPORT^1; 
  33          sbit VO=LCMPORT^0; 
  34          ///////////////////////////////////////////////////////////////////
  35          #define uchar unsigned char 
  36          #define uint  unsigned int 
  37          ///////////////////////////////////////////////////////////////////
  38          ////////////////////////////键盘扫描定义///////////////////////////
  39          unsigned char keyvartab[8][5]={'A','B','C','D','E',
  40                                         'F','G','H','I','J',
  41                                         'K','L','M','N','O',
  42                                         'P','Q','R','S','T',
  43                                         'U','V','1','2','3',
  44                                         ' ',' ','4','5','6',
  45                                         'W','X','7','8','9',
  46                                         'Y','Z','~','0','!'
  47                                          };
  48          //键盘行扫苗码
  49          #define NOKEY 0x01                                  //无键按下时的返回值 
  50          #define LOHI() P1=0xff; P2=0x80;_nop_()  //00           //列出行入 
  51          #define HOLI() P1=0x00; P2=0x9f;_nop_()  //1F          //行出列入 
  52          
  53          code unsigned char hh[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};    //行位置表 
  54          code unsigned char ll[5]={0x9e,0x9d,0x9b,0x97,0x8f};                                     
  55          
C51 COMPILER V8.01   KEYCODE                                                               11/02/2007 21:28:31 PAGE 2   

  56          unsigned char DispFlag;
  57          unsigned char key;
  58          
  59          ////////////////////////////////////////////////////////////////////
  60          void initlcm4bit(void);
  61          void writport(unsigned char lcmdata);
  62          void writbyte(unsigned char RS,unsigned char asic);
  63          void DisplayOneChar(unsigned char X, unsigned char Y, unsigned char DData);
  64          void DisplayListChar(unsigned char X, unsigned char Y, unsigned char code *DData);
  65          /////////////////////////////////////////////////////////////////////
  66          void Delay5Ms(void);
  67          void Delay400Ms(void);
  68          void delay(unsigned  int N);
  69          /////////////////////////////////////////////////////////////////////
  70          void Decode(unsigned char ScanCode);
  71          /////////////////////////////////////////////////////////////////////
  72          void numbertocode(void);
  73          void initkeyvariable(void);
  74          unsigned char readkeyvar(void);
  75          unsigned char parity(unsigned char x);
  76          void SEND_byte(unsigned char byte_data);
  77          /////////////////////////////////////////////////////////////////////
  78          ////static unsigned char IntNum = 0; //中断次数计数
  79          ////static unsigned char KeyV; //键值
  80          ////static unsigned char DisNum = 0; //显示用指针
  81          ////static unsigned char Key_UP=0, Ctrl = 0;//Key_UP是键松开标识,Ctrl是Ctrl键按下标识
  82          ////static unsigned char BF = 0; //标识是否有字符被收到
  83          ////static unsigned char biaozhiflag = 1;//表示小键盘已经有键按下标志位
  84          /////////////////////////////////////////////////////////////////////
  85          unsigned char DisNum = 0; //显示用指针
  86          unsigned char biaozhiflag = 1;//表示小键盘已经有键按下标志位
  87          unsigned char dat=0,dat1=0,dat2=0; //接收键盘数据变量? 存储通码变量 接受连续通码变量
  88          unsigned char count=0,num=9,temp[5],shu=0; //中数次数 中断控制变量 缓冲区数组 缓冲区指针
  89          unsigned char key=0; //按键最终值
  90          /////////////////////////延时子函数开始//////////////////////////////
  91          void delay_ms(unsigned char ms) // 延时子程序
  92          {                                               
  93   1              unsigned char i;
  94   1              while(ms--)
  95   1              {
  96   2                for(i = 0; i < 120; i++);
  97   2              }
  98   1      }
  99          /////////////////////////////////////////
 100          void delayus(unsigned int us) //执行一次是机器周期=12÷11.0592MHz=1.0857μS
 101                                        //(65536-定时常数)*1.0857μS=50mS
 102                                        // 定时常数=4C00H 
 103          { 
 104   1      while(us--); 
 105   1      } 
 106          ////////////////////////////////////////
 107          void delay5Ms(void)
 108          {
 109   1              unsigned int TempCyc =5552;
 110   1              while(TempCyc--);
 111   1      }
 112          ////////////////////////////////////////
 113          //400ms延时函数
 114          void Delay400Ms(void)
 115          {
 116   1              unsigned char TempCycA = 5;
 117   1              unsigned int TempCycB;
C51 COMPILER V8.01   KEYCODE                                                               11/02/2007 21:28:31 PAGE 3   

 118   1              while(TempCycA--)
 119   1                      {
 120   2                              TempCycB=7269;
 121   2                              while(TempCycB--);
 122   2                      };
 123   1      }
 124          /////////////////////////延时子函数结束//////////////////////////////
 125          /////////////////////////////////////////////////////////////////////
 126          //////////////////////////1602-LCD驱动程序开始///////////////////////
 127          void writport(unsigned char lcmdata) 
 128          { 
 129   1      LCMPORT=lcmdata|0x08; 
 130   1      delayus(100);
 131   1      LCMPORT=lcmdata&0xf7; 
 132   1      } 
 133          ///////////////////////////////////////////////////
 134          //RS=1时为写数据,RS=0时为写命令。 
 135          void writbyte(unsigned char RS,unsigned char asic) 
 136          { 
 137   1      unsigned char temp=asic&0xf0; 
 138   1      if(RS) 
 139   1      { 
 140   2      temp|=0x02; 
 141   2      writport(temp); 
 142   2      temp=asic<<4; 
 143   2      temp|=0x02; 
 144   2      
 145   2      } 
 146   1      else 
 147   1      { 
 148   2      delayus(1050); 
 149   2      writport(temp); 
 150   2      temp&=0xf0; 
 151   2      temp=asic<<4; 
 152   2      
 153   2      } 
 154   1      writport(temp); 
 155   1      } 
 156          ///////////////////////////////////////////////////
 157          //4BIT 初始化,分两行。 
 158          void initlcm4bit(void) 
 159          { 
 160   1      E=0;E=0; 
 161   1      delayus(40000);// 
 162   1      writport(0x20); //4-BIT mode chage 
 163   1      delayus(10000); 
 164   1      writbyte(0,0x2C);//seting display mode 2 line mode,display off //0X2C
 165   1      writbyte(0,0x0C);//display on/off. //0X0F
 166   1      writbyte(0,0x01);//display clear 
 167   1      delayus(30000); 
 168   1      } 
 169          ///////////////////////////////////////////////////
 170          //按指定位置显示一个字符 
 171          void DisplayOneChar(unsigned char X, unsigned char Y, unsigned char DData) 
 172          { 
 173   1      Y &= 0x1; X &= 0xF; //限制X不能大于15,Y不能大于1 
 174   1      if (Y) X |= 0x40; //当要显示第二行时地址码+0x40; 
 175   1      X |= 0x80; //算出指令码 
 176   1      writbyte(0,X);
 177   1      writbyte(1,DData); 
 178   1      } 
 179          ///////////////////////////////////////////////////
C51 COMPILER V8.01   KEYCODE                                                               11/02/2007 21:28:31 PAGE 4   

 180          //按指定位置显示一串字符  ***原来的遇到空格0x20就不显示*** 
 181          void DisplayListChar(unsigned char X, unsigned char Y, unsigned char code *DData) 
 182          { 
 183   1        unsigned char ListLength,j; 
 184   1        ListLength = strlen(DData); 
 185   1        Y &= 0x1; 
 186   1        X &= 0xF; //限制X不能大于15,Y不能大于1 
 187   1            if (X <= 0xF) //X坐标应小于0xF 
 188   1              {  
 189   2            for(j=0;j<ListLength;j++) 
 190   2              { 
 191   3                   DisplayOneChar(X, Y, DData[j]); //显示单个字符 
 192   3                   //delayus5Ms();
 193   3                   X++; 
 194   3                  } 
 195   2              } 
 196   1      } 
 197          //////////////////////////1602-LCD驱动程序结束///////////////////////
 198          void zhongduan(void) interrupt 2 //外部中断1 用来接受键盘发来的数据
 199          {
 200   1          dat>>=1; //接受数据 低->高
 201   1          if(Key_Data) dat|=0x80;
 202   1          count++;
 203   1          if(count==num)
 204   1          {
 205   2            if(count==9)
 206   2            {
 207   3              dat1=dat; //中断9次后为键盘所按按键的通码(开始位始终为0在第一次中断时右移中忽略)
 208   3              num=20; //使中断可以继续中断11次
 209   3            }
 210   2            if(count==20)
 211   2            {
 212   3              dat2=dat; //取回第二个通码
 213   3              if(dat1==0xe0 || dat2==0xf0) //第一个通码是0xe0则证明所按按键为功能键,第二个通码是0xf0证明按键结

⌨️ 快捷键说明

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