/* --------------------------------------------------------------------------
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; Lcd_PutChar(6,1,'E'); Buzz_On();
break;
case 1:
Key_ScanValue=0X37; Lcd_PutChar(6,1,'7'); Buzz_On(); ;
break;
case 2:
Key_ScanValue=0X34; Lcd_PutChar(6,1, '4'); Buzz_On();
break;
case 3:
Key_ScanValue=0X31; Lcd_PutChar(6,1, '1'); Buzz_On();
break;
}
} //7654 3210
if(0xd0==Key_Temp)//1101 0000 HIGHT
{
switch(Key_ScanCount)
{
case 0:
Key_ScanValue=0X30; Lcd_PutChar(6,1,'0'); Buzz_On();
break;
case 1:
Key_ScanValue=0X38; Lcd_PutChar(6,1,'8'); Buzz_On();
break;
case 2:
Key_ScanValue=0X35; Lcd_PutChar(6,1,'5'); Buzz_On();
break;
case 3:
Key_ScanValue=0X02; Lcd_PutChar(6,1,'2'); Buzz_On();
break;
}
} //7654 3210
if(0xb0==Key_Temp)//1011 0000 HIGHT
{
switch(Key_ScanCount)
{
case 0:
Key_ScanValue=0X46; Lcd_PutChar(6,1,'F'); Buzz_On();
break;
case 1:
Key_ScanValue=0X39; Lcd_PutChar(6,1,'9'); Buzz_On();
break;
case 2:
Key_ScanValue=0X36; Lcd_PutChar(6,1,'6'); Buzz_On();
break;
case 3:
Key_ScanValue=0X33; Lcd_PutChar(6,1,'3'); Buzz_On();
break;
}
} //7654 3210
if(0x70==Key_Temp) //0111 0000 HIGHT
{
switch(Key_ScanCount)
{
case 0:
/*Key_ScanValue=0X44;*/ Lcd_PutChar(6,1,'D'); Buzz_On(); EEPROM_eSave();
break;
case 1:
Key_ScanValue=0X43; Lcd_PutChar(6,1,'C'); Buzz_On(); ;
break;
case 2:
Key_ScanValue=0X42; Lcd_PutChar(6,1,'B'); Buzz_On();
break;
case 3:
Key_ScanValue=0X41; Lcd_PutChar(6,1,'A'); Buzz_On();
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;
}
}
}
}
//------------------------------------------------------------------------------