Demo entry 6363967

py

   

Submitted by lu on May 15, 2017 at 08:06
Language: C. Code size: 699 Bytes.

#include <reg52.h>

#define uchar unsigned char
#define uint unsigned int

sbit KEY0=P2^0;
sbit KEY1=P2^1;
sbit KEY2=P2^2;
sbit KEY3=P2^3;



void delay10ms()   //误差 0us
{
    unsigned char a,b,c;
    for(c=1;c>0;c--)
        for(b=38;b>0;b--)
            for(a=130;a>0;a--);
}

uchar keyscan(uchar mode)
{	   
	static uchar flag=1;//按键按松开标志
	if(mode)
		flag=1;  //支持连按	
	if(flag&&(KEY0==0||KEY1==0||KEY2==0||KEY3==0))
	{
		delay10ms();//去抖动
		flag=0;
		if(KEY0==0)		
		return 1;
		else if(KEY1==0)	
		return 2;
		else if(KEY2==0)	
		return 3;
		else if(KEY3==0)	
		return 4;
	} else if(KEY0==1&&KEY1==1&&KEY2==1&&KEY3==1)
		flag=1;
		
	return 0;// 无按键按下
}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).