void key_check(void) { unsigned int i;

for(i=0;i<200;i++);         //延时去抖动
if(0x27!=(P2IN&0x27))       //是否有键按下?
{
    for(i=0;i<200;i++);
    while(0x27!= (P2IN&0x27));      //一直等待按键松开
    //key_value=P2IN&0xD8;
    //return key_value;
}
else
    key_value=0x00;         

}

void key_interrupt(void) { P2IE |= 0x27; //使能P2.0、P2.1、P2.2和P2.7的中断 P2IES |= 0x27; //设置P2.0、P2.1、P2.2和P2.7的中断触发边沿为下降沿触发 P2IFG &= ~0x27; //清除P2.0、P2.1、P2.2和P2.7的中断标志位 __bis_SR_register(GIE); //使能总中断 }

#pragma vector=PORT2_VECTOR __interrupt void Port_2(void) { unsigned int i; for(i=0;i<200;i++); //延时去抖动 if(0x27!=(P2IN&0x27)) //是否有键按下? { for(i=0;i<200;i++); while(0x27!= (P2IN&0x27)); //一直等待按键松开 //key_value=P2IN&0xD8; //return key_value; } else key_value=0x00;

P2IFG &= ~0x27;     //清除P2.0、P2.1、P2.2和P2.7的中断标志位
void key_checkvoid	unsigned char temp;	unsigned int i;	fori=0;i200;i++;			延时去抖动	if0x27!=P2IN&0x27		是否有键按下?			fori=0;i200;i++;		while0x27!= P2IN&0x27;		一直等待按键松开		key_value=P2IN&0xD8;		return key_value;

原文地址: https://www.cveoy.top/t/topic/hN30 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录