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

📄 drv_key.c

📁 一款SmartPhone的驱动代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/************************************************************************
 *									*
 *	Copyright (C) SEIKO EPSON CORP. 2000				*
 *									*
 *	File name: touch_drv.c							*
 *	  This is touch panel interface demonstration program.		*
 *									*
 *									*
 *	Revision history						*
 *		2000.07.15	Kurt Shen	Start.			*
 *									*
 ************************************************************************/

#include "sysMCU.h"

#include "sysROS33.h"
#include "sysGUI.h"

void delay();
void init_key(void);
void int_key(void);
unsigned short bKeyStatus;			// Key status: 0 - up , 1 - down

unsigned char k5_data,keytemp;

unsigned char rucK5PortData;
unsigned char gucKeyCode;

void init_key(void)
{
	// Set the corresponding GPIO using as the keys
	// Set P30-p35 as the output port 
	*(volatile unsigned char *)IO_CFP3_ADDR &= 0xe0;//IO_CFPALL_IOP; 	// set P30-P34 as GPIO port
	*(volatile unsigned char *)IO_IOC3_ADDR |= 0x1f;					// set P30-P34 as out port
	*(volatile unsigned char *)IO_P3D_ADDR  &= 0xe0;					// set P30-P34 is LOW 

	// Set k50-k54 as the input port
	*(volatile unsigned char *)IN_CFK5_ADDR = IO_CFPALL_IOP;			//set k50-k54 as input port
	
	//Select k50-k54 as input pin for key interrupt generation,FPK0 interrupt
	*(volatile unsigned char *)IN_SPPK_ADDR &=0xfc;
	*(volatile unsigned char *)IN_SPPK_ADDR |=IN_SPPK0_K54_K50;
	
	//set the condition for input key interrupt genetation,falling edge
	*(volatile unsigned char *)IN_SCPK0_ADDR |=0x1f;
	
	//set the condition for input key interrupt genetation,enable interrupt
	*(volatile unsigned char *)IN_SMPK0_ADDR |=0x1f;
	
	//set the priotity of key interrupt
	*(volatile unsigned char *)INT_PK0_PK1_ADDR &=0x0f0;
	*(volatile unsigned char *)INT_PK0_PK1_ADDR |=INT_PRIL_LVL3;
	
	//set key input0 interrupt enable
	*(volatile unsigned char *)INT_EP0_EK_ADDR |=INT_EK0;
/*
	
	//P2 setting, P20,P21, as IO ports
	*(volatile unsigned char *)0x402D8 &= 0x0FC;
	//P1 setting, P15,P16, as IO ports
	*(volatile unsigned char *)0x402D4 &= 0x9F;
	
	//P2 input_output selection(for IO ports only), P20, P21, output
	*(volatile unsigned char *)0x402DA |= 0x03;
	//P1 input_output selection(for IO ports only), P15,P16, output
	*(volatile unsigned char *)0x402D6 |= 0x60;
	
	// P20 = P21 ='L'
	*(volatile unsigned char *)0x402D9 &= 0x0FC;
	// P15 = P16 ='L'
	*(volatile unsigned char *)0x402D5 &= 0x9F;
	
	
	//[0x402c0] set K50, K51,K52,K53,K54=KEYI0,KEYI1,KEYI2,KEYI3 KEYI4
	*(volatile unsigned char *)IN_CFK5_ADDR &= 0xe0;	// select K5 function: K50, K51,K52,K53,K54
	//[0x402c9]
	*(volatile unsigned char *)IN_SEP_ADDR &= 0xe0;
	//[0x402ca]
	*(volatile unsigned char *)IN_SPPK_ADDR &= 0x0fc;	//set FPK0 interrupt input port K5
	//[0x402cc]
	*(volatile unsigned char *)IN_SCPK0_ADDR |= 0x1F;	//set K50-K54 input comparison register 0 
	//[0x402ce]
	*(volatile unsigned char *)IN_SMPK0_ADDR |= 0x1F;	//set K50-K54 interrupt mask enable
	//[0x40262]
	*(volatile unsigned char *)INT_PK0_PK1_ADDR &= 0x0f0;
	*(volatile unsigned char *)INT_PK0_PK1_ADDR |= INT_PRIL_LVL4;	//set Key input0 interruput level 4
	//[0x40280]
	*(volatile unsigned char *)INT_FP0_FK_ADDR |= 0x10;		// reset Key input0 interrupt flag
	//[0x40270]
	*(volatile unsigned char *)INT_EP0_EK_ADDR |= 0x10;		// enable Key input0 interrupt
	
	//[0x402c6]
//	*(volatile unsigned char *)IN_SPT0_SPT3_ADDR |= 0x55;	//select K50,K51,K52,K53,K54 input pin for port interrupt
//	*(volatile unsigned char *)IN_SPT0_SPT3_ADDR &= 0x55;
	//[0x402c7]
//	*(volatile unsigned char *)IN_SPT4_SPT7_ADDR |= 0x01;
//	*(volatile unsigned char *)IN_SPT4_SPT7_ADDR &= 0x0fd;
	//[0x402c8]
	//*(volatile unsigned char *)IN_SPP_ADDR &= 0x0e0;		//set FPT0-FPT4 high level triger
	*/
}

void enable_key()
{
	//set key input0 interrupt enable
 	*(volatile unsigned char *)INT_FP0_FK_ADDR |= INT_EK0;
	*(volatile unsigned char *)INT_EP0_EK_ADDR |=INT_EK0;
}

void int_key0(void)
{
/*	asm("pushn	%r15");			// save r1,r2...r15
	asm("ld.w	%r9,%psr");		// EI,enable interrupt 
	asm("or 	%r9,0x10");
	asm("ld.w	%psr,%r9");

  	//check No 1,4,7,Menu,*   set P15 = 0, other = 1
	*(volatile unsigned char *)IO_P2D_ADDR |= 0x03;	// set P15 = 0
	*(volatile unsigned char *)IO_P1D_ADDR &= 0x0DF;
	*(volatile unsigned char *)IO_P1D_ADDR |= 0x40;
  	
  	rucK5PortData = *(volatile unsigned char *)IN_K5D_ADDR & 0x1F;	// [0x402c1]
 	while (1)
 	{
 		delay();
 		if (rucK5PortData == (*(volatile unsigned char *)IN_K5D_ADDR & 0x1F))
 			break;
 		else
 			rucK5PortData = *(volatile unsigned char *)IN_K5D_ADDR & 0x1F;	// [0x402c1]
 	}
	switch( rucK5PortData )
 	{
 		case 0x1E:
 			gucKeyCode = 1;//DOWNKEY;		//K50
 			break;
 		case 0x1D:
 			gucKeyCode = 2;//CANCELKEY;		//K51
 			break;
 		case 0x1B:
 			gucKeyCode = 3;//NO4KEY;		//K52
 			break;
 		case 0x17:
 			gucKeyCode = 4;//NO5KEY;		//K53
 			break;
 		case 0x0F:
 			gucKeyCode = 5;//NO6KEY;		//K54
 			break;
 		default:
 			gucKeyCode = NULL;//NULL;
 	}
	if (gucKeyCode == NULL)
	{
		//check No 2,5,8,0,Cancel,   set P21 = 0, other = 1
		*(volatile unsigned char *)IO_P2D_ADDR &= 0xfd;	// set P21 = 0
		*(volatile unsigned char *)IO_P2D_ADDR |= 0x01;
		*(volatile unsigned char *)IO_P1D_ADDR |= 0x60;
			 	
	 	rucK5PortData = *(volatile unsigned char *)IN_K5D_ADDR & 0x1F;	// [0x402c1]
	   	switch( rucK5PortData )
	 	{
	 		case 0x1E:
	 			gucKeyCode = 7;//RIGHTKEY;		//K50
	 			break;
	 		case 0x1D:
	 			gucKeyCode = 8;//MENUKEY;		//K51
	 			break;
	 		case 0x1B:
	 			gucKeyCode = 9;//NO7KEY;		//K52
	 			break;
	 		case 0x17:
	 			gucKeyCode = 10;//NO8KEY;		//K53
	 			break;
	 		case 0x0F:
	 			gucKeyCode = 11;//NO9KEY;		//K54
	 			break;
	 		default:
	 			gucKeyCode = NULL;//NULL;
	 	}
	}
	
	if (gucKeyCode == NULL)
	{
		//check No 3,6,9,#,ONOFF,   set P20 = 0, other = 1
		*(volatile unsigned char *)IO_P2D_ADDR &= 0xfe;	// set P20 = 0
		*(volatile unsigned char *)IO_P2D_ADDR |= 0x02;
		*(volatile unsigned char *)IO_P1D_ADDR |= 0x60;
	 	
	 	rucK5PortData = *(volatile unsigned char *)IN_K5D_ADDR & 0x1F;	// [0x402c1]
	   	switch( rucK5PortData )
	 	{
	 		case 0x1E:
	 			gucKeyCode = 13;//LEFTKEY;		//K50
	 			break;
	 		case 0x1D:
	 			gucKeyCode = 14;//CALLKEY;		//K51
	 			break;
	 		case 0x1B:
	 			gucKeyCode = 15;//ASTERISKKEY;		//K52
	 			break;
	 		case 0x17:
	 			gucKeyCode = 16;//NO0KEY;		//K53
	 			break;
	 		case 0x0F:
	 			gucKeyCode = 17;//SHARPKEY;		//K54
	 			break;
	 		default:
	 			gucKeyCode = NULL;//NULL;
	 	}
	}
	
	if (gucKeyCode == NULL)
	{
		//check Call,Down,Right,Left,Done,   set P16 = 0, other = 1
		*(volatile unsigned char *)IO_P2D_ADDR |= 0x03;	// set P16 = 0
		*(volatile unsigned char *)IO_P1D_ADDR &= 0x0BF;
		*(volatile unsigned char *)IO_P1D_ADDR |= 0x20;
	 	
	 	rucK5PortData = *(volatile unsigned char *)IN_K5D_ADDR & 0x1F;	// [0x402c1]
	   	switch( rucK5PortData )
	 	{
	 		case 0x1E:
	 			gucKeyCode = 20;//UPKEY;		//K50
	 			break;
	 		case 0x1D:
	 			gucKeyCode = 21;//ONOFFKEY;		//K51
	 			break;
	 		case 0x1B:
	 			gucKeyCode = 22;//NO1KEY;		//K52
	 			break;
	 		case 0x17:
	 			gucKeyCode = 23;//NO2KEY;		//K53
	 			break;
	 		case 0x0F:
	 			gucKeyCode = 24;//NO3KEY;		//K54
	 			break;
	 		default:
	 			gucKeyCode = NULL;//NULL;
	 	}
	}
	
 	//[0x40280]
	*(volatile unsigned char *)INT_FP0_FK_ADDR |= 0x10;		// reset Key input0 interrupt flag
	
	// P20 = P21 ='L'
	*(volatile unsigned char *)0x402D9 &= 0x0FC;
	// P15 = P16 ='L'
	*(volatile unsigned char *)0x402D5 &= 0x9F;

	asm("popn	%r15");			// restore r1,r2...r15
	asm("reti");
	//unsigned char tempscancode1;
	//unsigned char tempscancode2;			//added by ChenHong for anti-jitter
*/
	asm("pushn	%r15");			// save r1,r2...r15
	
	//reset FPK0 interrupt flag
 	*(volatile unsigned char *)INT_FP0_FK_ADDR |= INT_EK0;

	if (bKeyStatus) 
	{
		// 402CC
		*(volatile unsigned char *)IN_SCPK0_ADDR |= 0x1F;
		//402CE
		*(volatile unsigned char *)IN_SMPK0_ADDR |= 0x1F;
		//40280
 		//*(volatile unsigned char *)INT_FP0_FK_ADDR |= INT_EK0;
		bKeyStatus = 0;
		iset_flg(GUI_EVENTID,0x010);//added by ChenHong for Initialization
		*(volatile unsigned char *)INT_EP0_EK_ADDR |=INT_EK0;
		asm("popn	%r15");
		asm("reti");
	}

	
	//set key input0 interrupt disable
	*(volatile unsigned char *)INT_EP0_EK_ADDR &= 0xef;
	
	asm("ld.w	%r9,%psr");		// EI,enable interrupt 
	asm("or 	%r9,0x10");
	asm("ld.w	%psr,%r9");
	
//check cancel,menu,call,drop
	//func1()
	*(volatile unsigned char *)IO_P3D_ADDR &= 0x3e;
	*(volatile unsigned char *)IO_P3D_ADDR |= 0x1e;
	
	//keys = *(volatile unsigned char *)IN_K5D_ADDR;
	do{
		keytemp = *(volatile unsigned char *)IN_K5D_ADDR;
		asm("nop");
		//tempscancode2 =	*(volatile unsigned char *)IN_K5D_ADDR;
	}while(keytemp != *(volatile unsigned char *)IN_K5D_ADDR);

	keytemp&=0x0f;
	switch(keytemp)
	{
		case 0x0e:
		{
		//cancel
		k5_data = 0x0e;
		// 402CC
		*(volatile unsigned char *)IN_SCPK0_ADDR &= 0x1e;
		//402CE
		*(volatile unsigned char *)IN_SMPK0_ADDR &= 0x01;
		goto scan_over;
		}
		case 0x0d:
		{
		//menu
		k5_data = 0x1b;
		// 402CC
		*(volatile unsigned char *)IN_SCPK0_ADDR &= 0x1d;
		//402CE
		*(volatile unsigned char *)IN_SMPK0_ADDR &= 0x02;
		goto scan_over;
		}
		case 0x0b:
		{
		//call
		k5_data = 0x1a;
		// 402CC
		*(volatile unsigned char *)IN_SCPK0_ADDR &= 0x1b;
		//402CE
		*(volatile unsigned char *)IN_SMPK0_ADDR &= 0x04;
		goto scan_over;
		}
		case 0x07:
		{
		//drop
		k5_data = 0x1d;
		// 402CC
		*(volatile unsigned char *)IN_SCPK0_ADDR &= 0x17;
		//402CE
		*(volatile unsigned char *)IN_SMPK0_ADDR &= 0x08;
		goto scan_over;
		}
	}
//check No voice down,3,6,9,#
	//func2()
	*(volatile unsigned char *)IO_P3D_ADDR &= 0x3d;
	*(volatile unsigned char *)IO_P3D_ADDR |= 0x1d;
	keytemp = *(volatile unsigned char *)IN_K5D_ADDR;
	keytemp&=0x1f;
	switch(keytemp)
	{
		case 0x1e:
		{
		//voice down
		k5_data = 0x12;
		// 402CC
		*(volatile unsigned char *)IN_SCPK0_ADDR &= 0x1e;
		//402CE
		*(volatile unsigned char *)IN_SMPK0_ADDR &= 0x01;

		goto scan_over;
		}
		case 0x1d:
		{
		//3
		k5_data = 0x03;
		// 402CC
		*(volatile unsigned char *)IN_SCPK0_ADDR &= 0x1d;
		//402CE
		*(volatile unsigned char *)IN_SMPK0_ADDR &= 0x02;
		goto scan_over;
		}
		case 0x1b:
		{
		//6
		k5_data = 0x06;
		// 402CC
		*(volatile unsigned char *)IN_SCPK0_ADDR &= 0x1b;
		//402CE
		*(volatile unsigned char *)IN_SMPK0_ADDR &= 0x04;

		goto scan_over;
		}
		case 0x17:
		{
		//9
		k5_data = 0x09;
		// 402CC
		*(volatile unsigned char *)IN_SCPK0_ADDR &= 0x17;
		//402CE
		*(volatile unsigned char *)IN_SMPK0_ADDR &= 0x08;
		goto scan_over;
		}
		case 0x0f:
		{
		//#
		k5_data = 0x0b;
		// 402CC
		*(volatile unsigned char *)IN_SCPK0_ADDR &= 0x0f;
		//402CE
		*(volatile unsigned char *)IN_SMPK0_ADDR &= 0x10;
		goto scan_over;
		}
	}
	
	
//check No middle voice 2,5,8,0
	//func3()
	*(volatile unsigned char *)IO_P3D_ADDR &= 0x3b;
	*(volatile unsigned char *)IO_P3D_ADDR |= 0x1b;
	keytemp = *(volatile unsigned char *)IN_K5D_ADDR;
	keytemp&=0x1f;
	switch(keytemp)
	{
		case 0x1e:

⌨️ 快捷键说明

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