⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scan key.c

📁 74L164的键盘的扫描程序大家评价一下吧
💻 C
字号:
#include <AT89X55.H>
#include <8255.h>
#include <ABSACC.H>
#include <T1.h>
#include <LCD.h>
#include <74LS164.h>
#include <ScanKey.h>
bit _20ms_Flag;
bit _1s_Flag;
unsigned char KeyState;



void system_time_20ms (void) interrupt 1
{	static unsigned char _20ms_times;

	TR0=0;

	TH0=T0_H;
	TL0=T0_L;						//50MS

	TR0=1;	
	
	_20ms_Flag=1;
	_20ms_times+=1;
	if (_20ms_times==50)
	{_20ms_times=0;
	_1s_Flag=1;
	}
}






















/*
*********************************************************************************************
*                                       	Scan_Key_CLK_Init	
*
* Description: Scan_Key_CLK_Init
*
* Arguments  : 
*			   			   
* Returns    : none
*
* Notes      : 
*			
**********************************************************************************************
*/

void Scan_Key_CLK_Init (void)
{	
	unsigned char cLoop;
	E12864=0;												//Disable lcd

	PBYTE[_8255_A]=0x1;										//A=B=1

								
	for(cLoop=0;cLoop< 8;cLoop++)
	{
		_74LS164_CLK();		
 	}
/*			CLK UP=8		//CLK UP=8	QA=QB=QC=QD=QE=QF=QG=QH=1			*/	

	
	PBYTE[_8255_A]=0x0;										//A=B=0		_8
	_74LS164_CLK();
	PBYTE[_8255_A]=0x1;										//A=B=0		_8
/****************************************************************************/
/*		Ready to Shift			QA=0 			QB=QC=QD=QE=QF=QG=QH=1		*/	

}

























/*
*********************************************************************************************
*                                       	Scan_Key
*
* Description: Find Key table
*
* Arguments  : 
*			   			   
* Returns    : Key table
*
* Notes      : 
*			
**********************************************************************************************
*/
unsigned char Scan_Key (void)
{
	bit Key_temp; 
	unsigned char cLoop,Key_Table=0x00;

	Scan_Key_CLK_Init();




		for(cLoop=0;cLoop< 8;cLoop++)
			{
				Key_temp = Key_Input;
				_74LS164_CLK();
				Key_Table <<=1;
				Key_Table |= Key_temp;
			}


	return (Key_Table);				

}















/*
*********************************************************************************************
*                                       	Key press	
*
* Description:  Key press
*
* Arguments  : 1) Prevent dithering
*			   2) Key Click
*			   3) Key up
*			   			   
* Returns    : Key_Table
*
* Notes      : 1) If not Key up, input will be ignore
*			   
* 
**********************************************************************************************
*/
unsigned char Key_Press (unsigned char KeyS)
{unsigned char key_table_temp;
 key_table_temp=Scan_Key ();

    
	switch (KeyS)
	{	case 0:
			if (key_table_temp!=0xFF) 
			KeyState=1;
			else
			KeyState=0;
			key_table_temp=0xFF;
			break;
		case 1:
			if (key_table_temp==0xFF) 
			KeyState=0;
			else
			KeyState=2;
			break;
		case 2:
			if (key_table_temp==0xFF) 
			KeyState=0;
			key_table_temp=0xFF;
			break;
		default:
			KeyState=0;
			key_table_temp=0xFF;
	}
 return (key_table_temp);
}

⌨️ 快捷键说明

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