key.h

来自「自制的51单片机学习板」· C头文件 代码 · 共 72 行

H
72
字号
//#include <at89x52.h>
extern unsigned char keytemp;
extern unsigned char hourf=0,minutef=0;
unsigned char key(void);
void Delay1ms(unsigned int count)
{
	unsigned int i,j;
	for(i=0;i<count;i++)
	for(j=0;j<120;j++);
}


void Time1_Init()
{
	TMOD |= 0x10;
	IE 	 |= 0x88;
	TH1  = 0xff;
	TL1  = 0x00;		//12MZ晶振,10ms
}

void Time1_Int() interrupt 3
{   
     P0_7=0;
     TR1=0;
    //keytemp=key();
     keytemp=key();

   /* a=key()+'0';
	 LCD_set_position(0x00);
	 LCD_printc(a);*/
	TH1 = 0xff;
	TL1 = 0x00;
    TR1=1;

	
}
uchar a;

unsigned char key(void)
  {
  unsigned char temp,key=0;
 P2|=0x0f;
 P2_6=0;
 P2_7=1;
 temp=P2;
 if ((temp&0x30)!=0x30)
  {Delay1ms(70);
   if ((temp&0x30)!=0x30)
   {
    temp=temp&0x30;
    if (temp==0x20) key=2;
    else if (temp==0x10) key=4;
    else  key=0;
   }	 
  }
 Delay1ms(50);
 P2|=0x0f;
 P2_7=0;
 P2_6=1;
 temp=P2;
 if ((temp&0x30)!=0x30)
  {Delay1ms(70);
   if ((temp&0x30)!=0x30)
   {
    temp=temp&0x30;
    if (temp==0x20) key=1;
    else if (temp==0x10) key=3 ;
    else key=0;
   }
  }
return key;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?