/* --------------------------------------------------------------------------
1. Author: Copyright 2003.9 BY HAE-KWON HWANG
2. Homepage: TeraBank.co.kr.
3. Filename: key4_4.c
4. Version: 1.0
5. Created: 2003/09/30
6 Modified: 2004/10/13
7. License: TeraBank
8. MCU Type: ATmega128L
9. Clock Frequency: 8Mhz
10.Compiler: AvrEdit3.6(avr gcc)
----------------------------------------------------------------------------
*/
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/signal.h>
#include <avr/pgmspace.h>
#include "key4_4.h"
unsigned char Key_ScanData[4]={0xf7,0xfb,0xfd,0xfe};
//----------------4*4 key-------------------------------------------------------
void Key_Init(void)
{
Key_ScanValue=0;
Key_ScanCount=0;
Key_Temp=0;
Key_CountOld=0;
Key_Enable=0;
Key_ScanOld=0;
}
//------------------------------------------------------------------------------
void Key_Main( void )
{
if(Key_ScanCount>3)
{
Key_ScanCount=0;
}
Key_Input();
Key_ScanCount++;
}//------------------------------------------------------------------------------
void Key_ScanMain(void)//0xf7,0xfb,0xfd,0xfe
{ //7654 3210
if(0xe0==Key_Temp)//1110 0000 HIGHT
{
switch(Key_ScanCount)
{
case 0:
Key_ScanValue=0X45; Key_DisPlay(); Buzz_On();//e
break;
case 1:
Key_ScanValue=0X37; Key_DisPlay(); Buzz_On(); ;//7
break;
case 2:
Key_ScanValue=0X34; Key_DisPlay(); Buzz_On();//4
break;
case 3:
Key_ScanValue=0X31; Key_DisPlay(); Buzz_On();//1
break;
}
} //7654 3210
if(0xd0==Key_Temp)//1101 0000 HIGHT
{
switch(Key_ScanCount)
{
case 0:
Key_ScanValue=0X30; Key_DisPlay(); Buzz_On(); //0
break;
case 1:
Key_ScanValue=0X38; Key_DisPlay(); Buzz_On(); //8
break;
case 2:
Key_ScanValue=0X35; Key_DisPlay(); Buzz_On();//5
break;
case 3:
Key_ScanValue=0X32; Key_DisPlay(); Buzz_On();//2
break;
}
} //7654 3210
if(0xb0==Key_Temp)//1011 0000 HIGHT
{
switch(Key_ScanCount)
{
case 0:
Key_ScanValue=0X46; Key_DisPlay(); Buzz_On();//f
break;
case 1:
Key_ScanValue=0X39; Key_DisPlay(); Buzz_On();//9
break;
case 2:
Key_ScanValue=0X36; Key_DisPlay(); Buzz_On();//6
break;
case 3:
Key_ScanValue=0X33; Key_DisPlay(); Buzz_On();//3
break;
}
} //7654 3210
if(0x70==Key_Temp) //0111 0000 HIGHT
{
switch(Key_ScanCount)
{
case 0:
Key_ScanValue=0X44; Key_DisPlay(); Buzz_On();//d
break;
case 1:
Key_ScanValue=0X43; Key_DisPlay(); Buzz_On(); //c ;
break;
case 2:
Key_ScanValue=0X42; Key_DisPlay(); Buzz_On();//b
break;
case 3:
Key_ScanValue=0X41; Key_DisPlay(); Buzz_On();//a
break;
}
}
}
//------------------------------------------------------------------------------
void Key_Input(void)
{
if(Key_Enable==0)
{
Mem_wKey_Address=(0xf0 | Key_ScanData[Key_ScanCount]);
Key_Temp=(0xf0 & inp(Mem_rKey_Address));//상위만 읽음
if(Key_Temp !=0xf0) //KEY가 눌려짐
{
if(Key_ScanOld==Key_Temp) //정확성을 위해 2번 읽음
{
Key_Enable=1; //키 진입금지
Key_ScanMain(); //키값 읽음
Key_CountOld=Key_ScanCount; // 출력 순번값 저장1110->1101->1011->0111
Key_ScanOld=0xff;
Key_Enable=0;//키 진입허용
}
if(Key_Enable==0) //정확성을 위해 1번은 무조건 들어감
{
Key_ScanOld=Key_Temp;//1번 읽음값 현재읽은값 같게
}
}
} //상위는 1111로 바꾸고 하위에 KEY_SCAN_VALUE값을 보냄
else
{
if(Key_CountOld==Key_ScanCount)
{
Key_Temp=(0xf0 & inp(Mem_rKey_Address));
if(Key_Temp==0xf0) //키가 눌려지지 않음
{
Key_Enable=0;
}
}
}
}
//------------------------------------------------------------------------------