行列键盘的输入例程

Code:
  1. #include<reg51.h>
  2. #include<absacc.h>
  3. #defineucharunsignedchar
  4. #defineuintunsignedint
  5. voiddelays(void);
  6. ucharkbscan(void);
  7. voidmain(void)
  8. {
  9. ucharkey;
  10. while(1)
  11. {
  12. key=kbscan();/*键扫描函数*/
  13. delays();/*键消抖的延时函数*/
  14. }
  15. }
  16. //键消抖的延时函数
  17. voiddelays(void)
  18. {
  19. uchari;
  20. for(i=300;i>0;i--);
  21. }
  22. //kbscan(void)键扫描函数
  23. ucharkbscan(void)
  24. {
  25. ucharsccode,recode;
  26. P1=0xf0;/*发全"0"行扫描码,列线输入*/
  27. if((P1&0xf0)!=0xf0)/*若有键按下*/
  28. {
  29. delays();/*延时去抖动*/
  30. if((P1&0xf0)!=0xf0)
  31. {
  32. sccode=0xfe;/*逐行扫描初值*/
  33. while((sccode&0x10)!=0)
  34. {
  35. P1=sccode;/*输出行扫描码*/
  36. if((P1&0xf0)!=0xf0)/*本行有键按下*/
  37. {
  38. recode=(P1&0xf0)|0x0f;
  39. return((~sccode)+(~recode));/*返回特征字节码*/
  40. }
  41. elsesccode=(sccode<<1)|0x01;/*行扫描码左移一位*/
  42. }
  43. }
  44. }
  45. return(0);/*无键按下,返回值为0*/
  46. }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值