打印
[DemoCode下载]

单片机PS/2协议的应用——PS/2的键盘程序

[复制链接]
954|7
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
Messi1999|  楼主 | 2015-12-21 21:32 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
/*

     PS/2协议的应用:(常见的有PS/2接口鼠标、键盘等)用PS/2的键盘控制单片机,用字符型液晶显示器1602简单

                                        显示键盘的输入值

                                     由于at89s52单片机的工作频率过低,不易扫描更多键值


*/
#include"reg52.h"
#define uchar unsigned char
#define uint unsigned int
sbit psda=P3^0;
uchar keyvalue;
uint keynum;
uchar BIT;
uchar temp;
uint j=0;
uchar  table1[3];
sbit lcden=P2^6;
sbit lcdrs=P2^4;
sbit lcdrw=P2^5;
sbit dula=P3^7;
uchar num;



沙发
Messi1999|  楼主 | 2015-12-21 21:33 | 只看该作者
uchar code table2[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,'`',        //0-15
      0,0,0,0,0,'Q','1',0,0,0,'Z','S','A','W','2',0,        //16-31
      0,'C','X','D','E','4','3',0,0,0x20,'V','F','T','R','5',0,      //32-47
      0,'N','B','H','G','Y','6',0,0,0,'M','J','U','7','8',0, //48-63
      0,',','K','I','O','0','9',0,0,'.','/','L',';','P','-',0,//64-79
      0,0,0,0,'[','=',0,0,0,0,0,']',0,'|',0,0,               //80-95
      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,                //96-111
      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,         //112-127
      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,              //128-143
      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,           //144-159
      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,          //160-175
      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,         //176-191
      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,       //192-207
      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,          //208-223
      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,        //224-239
      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0          //240-255
     };
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
  for(y=11;y>0;y--);
}

使用特权

评论回复
板凳
Messi1999|  楼主 | 2015-12-21 21:33 | 只看该作者
void write_com(uchar com)
{
lcdrs=0;
P0=com;
delay(5);
lcden=1;
delay(10);
lcden=0;
delay(10);

}
void write_data(uchar _data)
{
lcdrs=1;
P0=_data;
delay(5);
lcden=1;
delay(10);
lcden=0;
delay(10);
}

使用特权

评论回复
地板
Messi1999|  楼主 | 2015-12-21 21:34 | 只看该作者
void _init_()
{
IT0=1;//外部中断下降沿触发
EX0=1;//开外部0中断
EA=1;//开总中断
dula=1;
lcdrw=0;
write_com(0x01);
write_com(0x38);//指令(001 DL N F 00)表示:DL=1,8数据位;N=1,位移宽度为2倍;F=1,5*10;F=0,5*7;
write_com(0x0f);//指令(00001DCB)表示:D=1,开显示;C=1,显示光标;B=1,光标闪烁
write_com(0x06);//指令(000001[I/D]S)表示:N=1,地址加一;[I/D]=0,地址减一;S=1,开整屏移动
write_com(0x80);//第一行:0x80+(字符序号【0--f】);第二行:0xc0+(字符序号【0--f】)

}

使用特权

评论回复
5
Messi1999|  楼主 | 2015-12-21 21:36 | 只看该作者
void main()
{
_init_();
while(1)
{
  if(keynum==3)
  {
   keynum=0;
   temp=table1[0];
   if((j%32>0)&&(j%16==0))
   {
    write_com(0xc0);
   }
   if((j%32==0)&&(j%16==0))
   {write_com(0x80);}
   write_data(table2[temp]);
   j++;
  }
  

}
}

使用特权

评论回复
6
Messi1999|  楼主 | 2015-12-21 21:37 | 只看该作者
void int0 () interrupt 0
{
if((BIT>0)&&(BIT<9))
{
  keyvalue=keyvalue>>1;
  if(psda)
   keyvalue=keyvalue|0x80;
}
BIT++;
if(BIT>10)
{
  BIT=0;
  table1[keynum]=keyvalue;
  keynum++;

}

}

使用特权

评论回复
7
捉虫天师| | 2015-12-21 23:51 | 只看该作者
第二套扫描码:
101 102 和104 键的键盘:

KEY

通码

断码

KEY通码断码KEY通码断码
A
1C
F0 1C
   946F0 46   [54F0 54
B
32
F0 32
`0EF0 0EINSERTE0 70E0 F0 70
C
21
F0 21
-4EF0 4EHOMEE0 6CE0 F0 6C
D
23
F0 23
=55F0 55PG UPE0 7DE0 F0 7D
E
24
F0 24
\5DF0 5DDELETEE0 71E0 F0 71
F2BF0 2BBKSP66F0 66ENDE0 69E0 F0 69
G34F0 34SPACE29F0 29PG DNE0 7AE0 F0 7A
H33F0 33TAB0DF0 0DU ARROWE0 75E0 F0 75
I43F0 43CAPS58F0 58L ARROWE0 6BE0 F0 6B
J3BF0 3BL SHFT12F0 12D ARROWE0 72E0 F0 72
K42F0 42L CTRL14F0 14R ARROWE0 74E0 F0 74
L4BF0 4BL GUIE0 1FE0 F0 1FNUM77F0   77
M3AF0 3AL ALT11F0 11KP /E0 4AE0 F0 4A
N31F0 31R SHFT59F0 59KP *7CF0   7C
O44F0 44R CTRLE0 14E0 F0 14KP -7BF0 7B
P4DF0 4DR GUIE0 27E0 F0 27KP +79F0 79
Q15F0 15R ALTE0 11E0 F0 11KP ENE0 5AE0 F0 5A
R2DF0 2DAPPSE0 2FE0 F0 2FKP71F0 71
S1BF0 1BENTER5AF0 5AKP 070F0 70
T2CF0 2CESC76F0 76KP 169F0 69
U3CF0 3CF105F0 05KP 272F0 72
V2AF0 2AF206F0 06KP 37AF0 7A
W1DF0 1DF304F0 04KP 46BF0 6B
X22F0 22F40CF0 0CKP 573F0 73
Y35F0 35F503F0 03KP 674F0 74
Z1AF0 1AF60BF0 0BKP 76CF0 6C
045F0 45F783F0 83KP 875F0 75
116F0 16F80AF0 0AKP 97DF0 7D
21EF0 1EF901F0 01]58F0 58
326F0 26F1009F0 09;4CF0 4C
425F0 25F1178F0 78'52F0 52
52EF0 2EF1207F0 07,41F0 41
636F0 36PRNT
SCRN
E0 12
E0 7C
E0 F0
7C E0
F0 12
.49F0 49
73DF0 3DSCROLL7EF0,7E/4AF0 4A
83EF0 3EPAUSEE1 14 77
E1 F0 14
F0 77
-NONE-
ACPI 扫描码:

KEY

通码

断码

Power
E0, 37
E0, F0, 37
Sleep
E0, 3F
E0, F0, 3F
Wake
E0, 5E
E0, F0, 5E
Windows 多媒体扫描码:

KEY

通码

断码

Next Track
E0, 4D
E0, F0, 4D
Previous Track
E0, 15
E0, F0, 15
Stop
E0, 3B
E0, F0, 3B
Play/PauseE0, 34E0, F0, 34
MuteE0, 23E0, F0, 23
Volume UpE0, 32E0, F0, 32
Volume DownE0, 21E0, F0, 21
Media SelectE0, 50E0, F0, 50
E-MailE0, 48E0, F0, 48
CalculatorE0, 2BE0, F0, 2b
My ComputerE0, 40E0, F0, 40
WWW SearchE0, 10E0, F0, 10
WWW HomeE0, 3AE0, F0, 3a
WWW BackE0, 38E0, F0, 38
WWW ForwardE0, 30E0, F0, 20
WWW StopE0, 28E0, F0, 28
WWW RefreshE0, 20E0, F0, 20
WWW FavoritesE0, 18E0, F0, 18

使用特权

评论回复
8
643757107| | 2015-12-22 11:38 | 只看该作者
最好把协议搞上来,我来补充一下。
PS-2接口协议.pdf (135.85 KB)

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

36

主题

363

帖子

1

粉丝