📄 key_bak.c
字号:
}
}
}
if (((Khead + 1) % KEY_BUFF_SIZE) != Ktail) /* Key buffer not full */
{
KeyBuffer[Khead] = work;
Khead = (Khead + 1) % KEY_BUFF_SIZE;
}
if(MainMode != X_OFF) /* Not in the lock mode */
{
if ( bellcnt != 0xFF ) /* Not the long bell */
bellcnt = 30;
g_LCDBLCnt = 1000*sysflag->LCD_BL_Time; /* If press a key, set the LCD backlight time again */
}
}
#if KB == KB_59N24
const byte keyScanCode[] = {/*0x3e, 0x3d,0x3b,0x37,0x2f,0x1f,0x3f,0x3f};*/
// ~0x01,~0x02,~0x04,~0x08,~0x10,~0x20,~0x40,~0x80
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 15
};
#elif KB == KB_38
const byte keyScanCode[] = {/*0x3e, 0x3d,0x3b,0x37,0x2f,0x1f,0x3f,0x3f};*/
0, 1, 2, 3, 4, 14
};
#else
#endif
/******************************************************************************
* Describe: Keyboard scan ISR
* Input : void
* Output: void
* return: void
* For every 5 mSeconds interval interrupt.
* 03-8-14 11:26
******************************************************************************/
#pragma INTERRUPT/E KeyScan
void KeyScan(void)
{
word chk;
word work;
word j;
#if 1// KB == KB_TS
key_scan_buf[0] = KEY_INPUT_PORT ^ 0xFF;
k_digit = 0;
CTL_KEY_SCAN = 0;
key_check();//只是检查控制锁
#else
#if KB == KB_59N24
key_scan_buf[k_digit] = KEY_INPUT_PORT ^ 0xFF;
k_digit++;
if (k_digit >= MAX_KEY_SCAN_CNTR)
k_digit = 0;
// 关闭VFD显示.
ClsVfd();
// Next Scanning. (保留最高位 for DSR)
KEY_SCAN_PORT &= 0x10;
KEY_SCAN_PORT |= keyScanCode[k_digit];
#elif KB == KB_38
key_scan_buf[k_digit++] = KEY_INPUT_PORT ^ 0xFF; /* Read key scanning data */
if ( k_digit >= MAX_KEY_SCAN_CNTR )
k_digit = 0;
KEY_SCAN_PORT = keyScanCode[k_digit]; /* Next scanning */
#endif
if (k_digit == 0)
{
chk = key_check(); /* Check the key input acccording to the scanning buffer */
if (chk != 0)
{
work = key_wka;
key_wka = chk;
if (work == key_wka) /* two time is same */
{
// //=========== debug start.
// Wr_Byte_Uart(PORT0, chk);
// //=========== debug end.
if(Rcode(work) == KD_FEED)
key_fd = 1; /* When FEED key press, set the feed flag */
else
key_fd = 0;
if (work != key_wkb)
{
key_off = 0; /* any key depress, wait key off */
key_wkb = work;
key_data = work;
key_rngset( work ); /* ring buffer set */
}
else
{
if (key_off != 0)
{
key_off = 0;
key_wkb = work;
key_data = work;
key_rngset( work ); /*ring buffer set*/
}
}
key_wka = KEY_END;
}
}
}
#endif
#ifdef SCANNER /* Support the scanner function */
{
void Sc_Scan(void);
static BYTE cntr = 0;
if ( cntr ++ >= 12 )
{
cntr = 0;
Sc_Scan();
}
}
#endif /* End SCANNER */
if (bellsub)
{
bellsub--;
}
else
{
if ( bellcnt != 0 )
{
bellsub = 3;
if ( bellcnt != 0xFF ) bellcnt --;
BuzzerOn();
}
else
{
BuzzerOff();
}
}
if (PS2_ChkKeyIn(&work) == OK)
{
key_rngset(work);
}
}
void InitBuzzer(void)
{
BUZZER_DIR = 1;
BuzzerOff();
}
/******************************************************************************
* Describe: Initial Keyboard scan port and timer.
* Input : void
* Output: void
* return: void
******************************************************************************/
void InitialKey(void)
{
// initial key scan and read port
KEY_INPUT_DIR = 0x00; // input
prc2 = 1; /*Enable change the directory of Port 9*/
CTL_KEY_SCAN_DIR = 1;
pur3 = 0xFF;
BUZZER_DIR = 1; // output
CloseBuzzer();
// initial key scan variable before start key scanning
Khead = Ktail = 0;
key_off = 1;
k_digit = 0;
key_wka = 0xFF;
key_wkb = 0xFF;
bellcnt = 0;
ta3mr = 0x40; // f8, disable gate, timer mode
ta3 = 1.5 * 1000 * FOSC / 8; // 10M xtal, 800ns * 1250 * 3 = 3 ms
ta3ic = 0x03;
ta3s = 1; // Start timer A3
InitBarCode();
Rst_Ts_Key();
}
/*****************************************************************************
* Check the key ring buffer whether it is empty.
*
* TRUE -- there is some keys in buffer.
* FALSE -- for no keys.
*
*****************************************************************************/
byte Key_Poll_Chk(void)
{
if ( Khead == Ktail )
return(FALSE);
else
return(TRUE);
}
/*--------------------------------------------------------------------------*
* Clear the key buffer
*--------------------------------------------------------------------------*/
void Clr_Key_Buff(void)
{
disint();
Khead = Ktail = 0;
enint();
#ifdef SCANNER /* Support the scanner function */
SC_ClrFlag();
#endif /* End SCANNER */
}
/*-----------------------------------------------------------------------*
* Check the key buffer contain the key code or not.
* When call this function, will clear the key buffer
* at the same time.
*-----------------------------------------------------------------------*/
byte Key_Buff_Chk(word key_code)
{
while(Key_Poll_Chk() == TRUE)
{
if(GetKey() == key_code)
{
Clr_Key_Buff();
return (OK);
}
}
return (NG);
}
/* Make a virtual key in the key buffer */
// Note: When the FF_Key_Tabl table inexist this key, this function will do none.
void Make_Virtual_Key(word key_code)
{
word i;
i = key_logi_get(FF_Key_Tabl, key_code, MAX_KEY_CNT);
if(i == 0xFF)
return;
if(((Khead + 1) % KEY_BUFF_SIZE) != Ktail) /* Key buffer not full */
{
KeyBuffer[Khead] = key_logic[i];
Khead = (Khead + 1) % KEY_BUFF_SIZE;
}
}
/* Get the scan control lock */
word Get_Scan_Lock(void)
{
return (key_scan_buf[MAX_KEY_SCAN_CNTR - 1]);
}
/* Sure judged by the phisics position key */
byte Phy_Sure(void)
{
word phy_key;
DEBUG_SET(
return OK;
)
while(1)
{
while(KBPress() == 0);
phy_key = KBCheck();
Clr_Key_Buff();
#if KB == KB_59N24
if(phy_key == 0x41) /* SUBTTL */
return (OK);
else if(phy_key == 0x39) /* SUBTTL */
return (OK);
else if(phy_key == 0x50)
return (NG);
#elif KB == KB_38
if(phy_key == 0x1f) /* SUBTTL */
return (OK);
else if(phy_key == 0x02)
return (NG);
#else
#endif
}
return NG;
}
//inline void OpenBuzzer(void)
//{
// BUZZER = 1;
//}
//
//inline void CloseBuzzer(void)
//{
// BUZZER = 0;
//}
/* Changed the logical position key */
void Modi_Key(word logi_posi, word key_code)
{
FF_Key_Tabl[logi_posi - 1] = key_code;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -