经典按键扫描程序

setbit(PORTC,PORTC0);
                      NOP();
                      NOP();                                                  
                      if (checkbit(PINC,PINC4)) setbit(new_key1,0);
                      if (checkbit(PINC,PINC5)) setbit(new_key1,1);
                      if (checkbit(PINC,PINC6)) setbit(new_key1,2);
                      clrbit(PORTC,PORTC0);
                      setbit(PORTC,PORTC1);
                      NOP();
                      NOP();
                      if (checkbit(PINC,PINC4)) setbit(new_key2,0);
                      if (checkbit(PINC,PINC5)) setbit(new_key2,1);
                      if (checkbit(PINC,PINC6)) setbit(new_key2,2);   
                      clrbit(PORTC,PORTC1);
                      setbit(PORTC,PORTC2);
                      NOP();
                      NOP();
                      if (checkbit(PINC,PINC4)) setbit(new_key3,0);
                      if (checkbit(PINC,PINC5)) setbit(new_key3,1);
                      if (checkbit(PINC,PINC6)) setbit(new_key3,2);
                      clrbit(PORTC,PORTC2);
                      setbit(PORTC,PORTC3);
                      NOP();
                      NOP();
                      if (checkbit(PINC,PINC4)) setbit(new_key4,0);
                      if (checkbit(PINC,PINC5)) setbit(new_key4,1);
                      if (checkbit(PINC,PINC6)) setbit(new_key4,2);
                      clrbit(PORTC,PORTC3);
//------------------------------------接收到正确命令处理
                      if (checkbit(works,uorder_ok)) unit_order();
                      if (checkbit(works,norder_ok)) net_order();            
                  
                      time1++;
                      }while (time1<0xfe);
                      time1=0x00;
//-------------------------------------按键处理程序
                      tmp_key1=old_key1;
                      tmp_key1=(tmp_key1^new_key1);
                      tmp_key1=(tmp_key1&new_key1);
                      old_key1=new_key1;
                      if (checkbit(tmp_key1,0))
                           {
                         key_data=0x01;
                         scan_in();
                         }
                      if (checkbit(tmp_key1,1))
                           {
                         key_data=0x02;
                         scan_in();
                         }
                      if (checkbit(tmp_key1,2))
                           {
                         key_data=0x03;
                         scan_in();
                         }     
                       new_key1=0x00;
                      tmp_key2=old_key2;
                      tmp_key2=(tmp_key2^new_key2);
                      tmp_key2=(tmp_key2&new_key2);
                      old_key2=new_key2;
                      if (checkbit(tmp_key2,0))
                           {
                         key_data=0x04;
                         scan_in();
                         }
                      if (checkbit(tmp_key2,1))
                           {
                         key_data=0x05;
                         scan_in();
                         }
                      if (checkbit(tmp_key2,2))
                           {
                         key_data=0x06;
                         scan_in();
                         }     
                       new_key2=0x00;
                     
                      tmp_key3=old_key3;
                      tmp_key3=(tmp_key3^new_key3);
                      tmp_key3=(tmp_key3&new_key3);
                      old_key3=new_key3;
                      if (checkbit(tmp_key3,0))
                           {
                         key_data=0x07;
                         scan_in();
                         }
                      if (checkbit(tmp_key3,1))
                           {
                         key_data=0x08;
                         scan_in();
                         }
                      if (checkbit(tmp_key3,2))
                           {
                         key_data=0x09;
                         scan_in();
                         }     
                       new_key3=0x00;
                     
                      tmp_key4=old_key4;
                      tmp_key4=(tmp_key4^new_key4);
                      tmp_key4=(tmp_key4&new_key4);
                      old_key4=new_key4;
                      if (checkbit(tmp_key4,0))
                           {
                         key_data=0x0C;
                         scan_in();
                         }
                      if (checkbit(tmp_key4,1))
                           {
                         key_data=0x00;
                         scan_in();
                         }
                      if (checkbit(tmp_key4,2))
                           {
                         key_data=0x0A;
                         scan_in();
                         }     
                       new_key4=0x00;—原文来自《新e代电子网》网址是:http://www.elecm.com/a/read-htm-tid-103023-fpage-6.html

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值