|
- sbit Pin_B1 = P3^2;
- sbit Pin_B2 = P3^3;
- sbit Pin_B3 = P3^4;
- u8 KeyVal = 0;//用完清零
- void key_Proc()//多鍵短按,1ms中斷內(nèi)運(yùn)行
- {
- static u8 Delay_XD=0; //消抖計(jì)數(shù)
- static bit ons = 0;
- if(!Pin_B1 || !Pin_B2 || !Pin_B3)
- {
- if(++Delay_XD>=20 && !ons) //消抖
- {
- ons = 1;
- if(!Pin_B1 && !Pin_B2)
- {
- KeyVal = SW2;
- }else if(!Pin_B2 && !Pin_B3)
- {
- KeyVal = SW4;
- }else if(!Pin_B1 && !Pin_B3)
- {
- KeyVal = SW6;
- }else{
- if(!Pin_B1)
- {
- KeyVal = SW1;
- }
- if(!Pin_B2)
- {
- KeyVal = SW3;
- }
- if(!Pin_B3
- {
- KeyVal = SW5;
- }
- }
- }
- }
- else //按鍵抬起
- {
- Delay_XD=0; //Delay_XD清0
- ons = 0;
- }
- }
復(fù)制代碼
|
|