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

📄 drv_keyboard.c

📁 The combined demo is dedicated for S1C33L05, so DMT33L05 should be used to load and run the demo. F
💻 C
字号:
//---------------------------------------------------------------------------------
//
//      Copyright (C) SEIKO EPSON CORP. 2003
//
//      GROUP			: SEE LSI
//      FILE                    : drv_keyboard.c
//      MODULE                  :
//      Function description    : This is the driver code of key board testing
//      Revision history        :
//                                Date            userName         Description
//                                2004/01/07     Angela Yuan      start
//
//      Notes                   : KeyB:KEYO[12:0]    as scan input
//                                KeyA:K50~K53, P03  as scan output
//
//---------------------------------------------------------------------------------

//---------------------------------------------------------------------------------
// Include files (#include)
//---------------------------------------------------------------------------------

#include "../include/drv_key.h"

//---------------------------------------------------------------------------------
// Global & static variables
//---------------------------------------------------------------------------------

extern   unsigned short global_variable;//This variable defined in the up system file
//unsigned short global_variable = 0x0000;  //just for grammer test
const unsigned short scanin_data[15] = {
				     			 0xfffe, //line1 is set to low,  others high
                                 0xfffd, //line2 is set to low,  others high
                                 0xfffb, //line3 is set to low,  others high
                                 0xfff7, //line4 is set to low,  others high
                                 0xffef, //line5 is set to low,  others high
                                 0xffdf, //line6 is set to low,  others high
                                 0xffbf, //line7 is set to low,  others high
                                 0xff7f, //line8 is set to low,  others high
                                 0xfeff, //line9 is set to low,  others high
                                 0xfdff, //line10 is set to low,  others high
                                 0xfbff, //line11 is set to low,  others high
                                 0xf7ff, //line12 is set to low,  others high
                                 0xefff, //line13 is set to low,  others high
                                 0x0000, //all lines are set to low
                                 0x1fff};//all lines are set to high

extern unsigned char  key_position;
extern unsigned char  IsKeyDown_in;
//---------------------------------------------------------------------------------
//  	Function name 		: timer_enable()
// 	Function description	:
//
//      Parameters
//         Input  :  none
//         Output :  none
//         I/O    :  none
//
//      Return value : none
//
//	Global variable 	: none
//---------------------------------------------------------------------------------
void timer_enable(void)
{
        //clear timer factor flag
        *(volatile unsigned char*)0x40285      =0x04;
        //reset timer
        *(volatile unsigned char*)0x40168      |=0x02;
        //enable 8 bit clock timer2 interrupt
        *(volatile unsigned char*)0x40275      |=0x04 ;
        //run 8 bit clock timer2
        *(volatile  unsigned char*)0x40168     |=0x01;

}

//---------------------------------------------------------------------------------
//  	Function name 		: timer_disable()
// 	Function description	:
//
//      Parameters
//         Input  :  none
//         Output :  none
//         I/O    :  none
//
//      Return value : none
//
//	Global variable 	: none
//---------------------------------------------------------------------------------
void timer_disable(void)
{
		//disable 8bit clock timer2 interrupt
		*(volatile unsigned char*)0x40275      &=0xfb;
		//stop 8bit clock timer2 timer
        *(volatile unsigned char*)0x40168      &=0xfe;
        //clear timer factor flag
        *(volatile unsigned char*)0x40285      =0x04;
        //reset timer
        *(volatile unsigned char*)0x40168      |=0x02;
}


//---------------------------------------------------------------------------------
//  	Function name 		: enable_keyscanint()
// 	Function description	:
//
//      Parameters
//         Input  :  none
//         Output :  none
//         I/O    :  none
//
//      Return value : none
//
//	Global variable 	: none
//---------------------------------------------------------------------------------
void enable_keyscanint(void)
{
	//reset FPT3 and FPK0 interrupt flag
	*(volatile unsigned char*)0x40280   =0x18;
	//enable FPT3 and FPK0 in ITC
	*(volatile unsigned char*)0x40270   |=0x18;
}

//---------------------------------------------------------------------------------
//  	Function name 		: disable_keyscanint()
// 	Function description	:
//
//      Parameters
//         Input  :  none
//         Output :  none
//         I/O    :  none
//
//      Return value : none
//
//	Global variable 	: none
//---------------------------------------------------------------------------------
void disable_keyscanint(void)
{
	//disable FPT3 and FPK0 in ITC
	*(volatile unsigned char*)0x40270   &=0xe7;
	//reset FPT3 and FPK0 interrupt flag
	*(volatile unsigned char*)0x40280   =0x18;
}

//---------------------------------------------------------------------------------
//  	Function name 		: line_scanin()
// 	Function description	:
//
//      Parameters
//         Input  :  unsigned short data
//         Output :  none
//         I/O    :  none
//
//      Return value : none
//
//	Global variable 	: none
//---------------------------------------------------------------------------------
void line_scanin(unsigned short data)
{
	*(volatile unsigned short*)0x400000 = data ;
}

//---------------------------------------------------------------------------------
//  	Function name 		: scanout()
// 	Function description	:
//
//      Parameters
//         Input  :  none
//         Output :  none
//         I/O    :  none
//
//      Return value : char address
//
//	Global variable 	: none
//---------------------------------------------------------------------------------
char scanout()
{
        unsigned char temp1,temp2, temp;

        temp1  = * (volatile unsigned char*)0x402c1;
        temp1 |= 0xf0;
        temp2  = * (volatile unsigned char*)0x402d1;
        temp2 |= 0xf7;
        temp2  = temp2 * 2 + 1;
        temp   = temp2 & temp1;
        return(temp);
}


//---------------------------------------------------------------------------------
//  	Function name 		: initial_KeyBoard()
// 	Function description	:
//
//      Parameters
//         Input  :  none
//         Output :  none
//         I/O    :  none
//
//      Return value : none
//
//	Global variable 	: global_variable, scanin_data
//---------------------------------------------------------------------------------
void initial_keyboard(void){
	unsigned short data;

//KEY INITIALIZATION
	/*  KeyB    as scan input 	*/
	/*  KeyA    as scan output      */
        //k5[3:0] set as gpio
        *(volatile unsigned char*)0x402c0      &=0xf0;
        //p03 set as gpio
        *(volatile unsigned char*)0x402d0      &=0xf7;
        //KEY00~12 set as gpio

        /* KeyB data all set high*/
        global_variable = 0x0000;
        global_variable = (global_variable | 0x1fff) & scanin_data[14];
        line_scanin(global_variable);

        //FPK0 interrupt port select K5[3:0]
        *(volatile unsigned char*)0x402ca       &=0xfc;
	//FPK0 interrupt mask register
	*(volatile unsigned char*)0x402ce        =0x0f;

	//FPT3 interrupt port select P03
	*(volatile unsigned char*)0x402c6       &=0x3f;
	*(volatile unsigned char*)0x402c6       |=0x80;

        //FPK0 comparison register
	*(volatile unsigned char*)0x402cc       |=0x0f;
	//FPT3 interrupt polarity register, low
	*(volatile unsigned char*)0x402c8       &=0xf7;

	//FPT3 interrupt level and edge select register: level
	*(volatile unsigned char*)0x402c9       |=0x08;

        //disable key scan interrupt
        //reset the key interrupt factor flag
	disable_keyscanint();

	//set FPT3 and FPK0 interrupt priority as 6
	*(volatile unsigned char*)0x40261       &=0x8f;
	*(volatile unsigned char*)0x40261       |=0x60;
	*(volatile unsigned char*)0x40262       &=0xf8;
	*(volatile unsigned char*)0x40262       |=0x06;

	//KO FUNCTION
	/* K5 and P03 function as GPIO */
	*(volatile unsigned char*)0x402c0       &=0xf0;
	*(volatile unsigned char*)0x402d0       &=0xf7;
	*(volatile unsigned char*)0x300040      &=0x3f;
	/* P03 input mode*/
	*(volatile unsigned char*)0x402d2       &=0xf7;

//TIMER INITIALIZATION
	//disable 8bit clock timer2 interrupt
	*(volatile unsigned char*)0x40275       &=0xfb ;
	//stop 8bit clock timer2 clocktimer
	*(volatile unsigned char*)0x40168       &=0xfe;

	//prescaler off
	*(volatile unsigned char*)0x4014e       &=0xf7;
	//prescaler division ratio
	*(volatile unsigned char*)0x4014e       |=0x07;
	//prescaler on
	*(volatile unsigned char*)0x4014e       |=0x08;


	//load comparison register data , make the 20ms interval's int
        *(volatile unsigned char*)0x40169      = 0xff;
        //reset timer
	*(volatile unsigned char*)0x40168       |=0x02;
	//timer select interrupt request, IDMA request disable
	*(volatile unsigned char*)0x40292       &=0xef;
        //timer interrupt priority set to 6
        *(volatile unsigned char*)0x40269         &=0xf8 ;
        *(volatile unsigned char*)0x40269         |=0x06;
        //clear timer factor flag
        *(volatile unsigned char*)0x40285         |=0x04;
	global_variable = (global_variable & 0xe000);
	line_scanin(global_variable);
	enable_keyscanint();
}

//---------------------------------------------------------------------------------
//  	Function name 		: GetKeyScancode()
// 	Function description	:
//
//      Parameters
//         Input  :  unsigned char * pcKeyCode
//         Output :  none
//         I/O    :  none
//
//      Return value : 1
//
//	Global variable 	: key_position
//---------------------------------------------------------------------------------
signed int GetKeyScancode(unsigned char * pcKeyCode)
{
        *pcKeyCode = key_position;
        return(1);
}

//---------------------------------------------------------------------------------
//  	Function name 		: LED()
// 	Function description	:
//
//      Parameters
//         Input  :  unsigned short led_data
//         Output :  none
//         I/O    :  none
//
//      Return value : none
//
//	Global variable 	: global_variable
//---------------------------------------------------------------------------------
void LED(unsigned short led_data){

	/*  KeyB    as scan input 	*/
	/*  KeyA    as scan output      */

        /* KeyB data all set high*/
        global_variable = (global_variable & 0x3fff) | (led_data & 0xc000);
        line_scanin(global_variable);
}

⌨️ 快捷键说明

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