No.90112 作者:npsgsys 邮件:lsh9982009@163.com ID:47933 登陆:2次 文章数:4篇 最后登陆IP:125.89.2.206 最后登陆:2006/10/20 8:38:15 注册:2006/2/24 13:41:59 财富:118 发帖时间:2006/3/13 13:55:55 发贴者IP:218.14.25.119 标题:npsgsys:请教:请各位大哥,这是我写的一个 键盘程序 (ps/2),可是不正确! 摘要:No.90112请教:请各位大哥,这是我写的一个 键盘程序 (ps/2),可是不正确! /********************************************************************** 这是我自己做的一个键盘(相当于标准的 PC 键盘,插在 PC 的 PS/2 口) 现在我的这个键盘还只有一个按钮,我希望按下这个按钮就相当于在标准的 PC 键盘上按下 "w" ,这个按钮接在 P3.3 上,当按下这个按钮,就 把 P3.3 拉低,外部中断1 的下降沿触发。 下面是 PS/2 协议: 我推荐下面的过程发送一个单一字节从仿真键盘/鼠标到主机 1) 等待Clock = high 2) 延时 50 微秒 3) Clock s 仍旧为 high? No—到第1 步 4) Data = high? No—放弃 (并且从主机读取字节) 5) 延迟 20 毫秒 (=40 微秒 to the time Clock is pulled low in sending the start bit.) 6) 输出起始位 (0) \ 在发送所有这些位的每一位后 7) 输出 8 个数据位 > 测试时钟确认主机是否把它拉低了 8) 输出校验位 / 这说明主机要放弃这次传送 9) 输出停止位 (1) 10) 延迟30 毫秒 (=50 微秒 from the time Clock is released in sending the stop bit) ************************************************************************/ #include "reg52.h" #include "intrins.h" sbit P2_0 = P2^2; //数据线 sbit P2_5 = P2^5; //时钟线 sbit P3_3 = P3^3; //外部中断 static unsigned char IntNum = 0; //中断次数计数 static unsigned char KeyV; //键值 int Check_status( ); //检查状态 void SendMessage( ); //向 PC 机的 PS/2 口发送数据 void Send_Start_Bit( ); //发送起始位 void Send_Data_Bit( ); //发送数据位 void Send_Check_Bit( );//发送效验位 void Send_End_Bit( );//发送停止位 void Delay50us( ); //延时 50 微秒 void Delay20ms( ); //延时 20 毫秒 void Delay30ms( ); //延时 30 毫秒 void main() { P2_5 = 1; //把时钟线置为高电平 P2_0 = 1; //把数据线置为高电平 IT1 = 1; //设外部中断1为下降沿触发 EA = 1; //开中断 EX1 = 1; //开中断 while(1) { } } void Delay50us( ) //延时 50 微妙 { int i; for (i=0;i <50;i++) { _nop_(); } } void Delay20ms( ) //延时 20 毫秒 { int i,j; for (i=0;i <200;i++) { for (j=0;j <100;j++) { _nop_(); } } } void Delay30ms( ) //延时 30 毫秒 { int i,j; for (i=0;i <300;i++) { for (j=0;j <100;j++) { _nop_(); } } } void Send_Start_Bit( ) //发送起始位 { P2_0 = 0 ; //起始位的值 P2_5 = 0; //发送起始位 _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); P2_5 = 1; //上拉 } void Send_Data_Bit( ) //发送数据位 { int ......
>>返回讨论的主题
|