EEI 功能使用方法

EEI 功能使用方法
Application Note
EEI 功能使用方法
1
適用產品:SM59R16A2 / SM59R08A2
2
EEI 使用概述:
2.1 Port1 所有的引腳皆可為 GPIO,或獨立致能為 EEI 功能
2.2 由 Port1.0~Port1.7 共八支引腳,分別對應至 8 個獨立的 flag(KBF.0~ KBF.7),及共用同一個中斷
向量位置(0x5B)
2.3 可由程式設定為高電位或低電位觸發
2.4 當觸發訊號輸入至 Port1 任一引腳,其對應的旗標將會被設置為”1”,並且進入中斷副程式
2.5 EEI 功能主要可做為 4x4 矩陣式鍵盤掃描,或其它類似的應用
P1.0
P1.1
P1.2
P1.3
OR
P1.4
EEIIF: EEI interrupt
P1.5
IEEEI: EEI interrupt enable
P1.6
P1.7
Fig. Interrupts from EEI 8 inputs
3
EEI 相關暫存器:
EEI
KBLS
KBE
KBF
Description
Direct
Bit 7
EEI level selection
EEI input enable
EEI flag
93h
94h
95h
KBLS7
KBE7
KBF7
Mnemonic: KBLS
7
6
KBLS.7
KBLS.6
5
KBLS.5
Bit 6
Bit 5
Bit 4
EEI function
KBLS6 KBLS5 KBLS4
KBE6
KBE5
KBE4
KBF6
KBF5
KBF4
4
KBLS.4
3
KBLS.3
Bit 3
Bit 2
Bit 1
Bit 0
RESET
KBLS3
KBE3
KBF3
KBLS2
KBE2
KBF2
KBLS1
KBE1
KBF1
KBLS0
KBE0
KBF0
00h
00h
00h
2
KBLS.2
1
KBLS.1
Address: 93h
0
Reset
KBLS.0
00h
Specifications subject to change without notice, contact your sales representatives for the most recent information.
IRFWX-A125
1
Ver. A 2009/03
EEI 功能使用方法
Application Note
KBLS.7: EEI line 7 觸發準位設定位元
0 : 設定為低準位觸發
1 : 設定為高準位觸發
KBLS.6: EEI line 6 觸發準位設定位元
0 : 設定為低準位觸發
1 : 設定為高準位觸發
KBLS.5: EEI line 5 觸發準位設定位元
0 : 設定為低準位觸發
1 : 設定為高準位觸發
KBLS.4: EEI line 4 觸發準位設定位元
0 : 設定為低準位觸發
1 : 設定為高準位觸發
KBLS.3: EEI line 3 觸發準位設定位元
0 : 設定為低準位觸發
1 : 設定為高準位觸發
KBLS.2: EEI line 2 觸發準位設定位元
0 : 設定為低準位觸發
1 : 設定為高準位觸發
KBLS.1: EEI line 1 觸發準位設定位元
0 : 設定為低準位觸發
1 : 設定為高準位觸發
KBLS.0: EEI line 0 觸發準位設定位元
0 : 設定為低準位觸發
1 : 設定為高準位觸發
Mnemonic: KBE
7
6
KBE.7
KBE.6
5
KBE.5
4
KBE.4
3
KBE.3
2
KBE.2
1
KBE.1
Address: 94h
0
Reset
KBE.0
00h
KBE.7: EEI line 7 (P1.7)致能位元
0 : 致能為一般的出入埠(GPIO)
1 : 致能為 EEI 功能,當觸發訊號輸入時,KBF.7 = 1,會觸發中斷
KBE.6: EEI line 6 (P1.6)致能位元
0 : 致能為一般的輸出入埠(GPIO)
1 : 致能為 EEI 功能,當觸發訊號輸入時,KBF.6 = 1,會觸發中斷
KBE.5: EEI line 5 (P1.5)致能位元
0 : 致能為一般的輸出入埠(GPIO)
1 : 致能為 EEI 功能,當觸發訊號輸入時,KBF.5 = 1,會觸發中斷
KBE.4: EEI line 4 (P1.4)致能位元
0 : 致能為一般的輸出入埠(GPIO)
1 : 致能為 EEI 功能,當觸發訊號輸入時,KBF.4 = 1,會觸發中斷
KBE.3: EEI line 3 (P1.3)致能位元
0 : 致能為一般的輸出入埠(GPIO)
1 : 致能為 EEI 功能,當觸發訊號輸入時,KBF.3 = 1,會觸發中斷
KBE.2: EEI line 2 (P1.2)致能位元
0 : 致能為一般的輸出入埠(GPIO)
1 : 致能為 EEI 功能,當觸發訊號輸入時,KBF.2 = 1,會觸發中斷
Specifications subject to change without notice, contact your sales representatives for the most recent information.
IRFWX-A125
2
Ver. A 2009/03
EEI 功能使用方法
Application Note
KBE.1: EEI line 1 (P1.1)致能位元
0 : 致能為一般的輸出入埠(GPIO)
1 : 致能為 EEI 功能,當觸發訊號輸入時,KBF.1 = 1,會觸發中斷
KBE.0: EEI line 0 (P1.0)致能位元
0 : 致能為一般的輸出入埠(GPIO)
1 : 致能為 EEI 功能,當觸發訊號輸入時,KBF.0 = 1,會觸發中斷
Mnemonic: KBF
7
6
KBF.7
KBF.6
5
KBF.5
4
KBF.4
3
KBF.3
2
KBF.2
1
KBF.1
Address: 95h
0
Reset
KBF.0
00h
KBF.7: EEI line 7 flag
當觸發訊號輸入時,KBF.7 = 1,會觸發中斷;
必須由軟體清除為”0”
KBF.6: EEI line 6 flag
當觸發訊號輸入時,KBF.6 = 1,會觸發中斷;
必須由軟體清除為”0”
KBF.5: EEI line 5 flag
當觸發訊號輸入時,KBF.5 = 1,會觸發中斷;
必須由軟體清除為”0”
KBF.4: EEI line 4 flag
當觸發訊號輸入時,KBF.4 = 1,會觸發中斷;
必須由軟體清除為”0”
KBF.3: EEI line 3 flag
當觸發訊號輸入時,KBF.3 = 1,會觸發中斷;
必須由軟體清除為”0”
KBF.2: EEI line 2 flag
當觸發訊號輸入時,KBF.2 = 1,會觸發中斷;
必須由軟體清除為”0”
KBF.1: EEI line 1 flag
當觸發訊號輸入時,KBF.1 = 1,會觸發中斷;
必須由軟體清除為”0”
KBF.0: EEI line 0 flag
當觸發訊號輸入時,KBF.0 = 1,會觸發中斷;
必須由軟體清除為”0”
P1.x
KBFx
KBLSx
KBEx
Fig. Block diagram of EEI input
Specifications subject to change without notice, contact your sales representatives for the most recent information.
IRFWX-A125
3
Ver. A 2009/03
EEI 功能使用方法
Application Note
4
以下是 EEI 相對應的中斷向量表:
Table 11-1: Interrupt vectors
0003h
000Bh
Interrupt Number *(use
Keil C Tool)
0
1
IE1 – External interrupt 1
0013h
2
TF1 – Timer 1 interrupt
001Bh
3
RI0/TI0 – Serial channel 0 interrupt
TF2/EXF2 – Timer 2 interrupt
0023h
002Bh
4
5
SPIIF – SPI interrupt
004Bh
9
ADCIF – A/D converter interrupt
EEIIF – Expanded External Interrupt
IICIF – IIC interrupt
RI1/TI1 – Serial channel 1 interrupt
0053h
005Bh
006Bh
0083h
10
11
13
16
Interrupt Request Flags
Interrupt Vector Address
IE0 – External interrupt 0
TF0 – Timer 0 interrupt
*See Keil C about C51 User’s Guide about Interrupt Function description
EEI 中斷應用的參考程式:
(1) 中斷致能設置:
void Init_EEI(void)
{
//Keyboard level selector register
KBLS = 0x00;
//Detect_Lo_level;
//KBLS = 0xff;
//Detect_Hi_level;
//Keyboard input enable register
//KBE
= 0x00;
KBE = 0xff;
//enable standard I/O pin
//enable EEI.KBF to generate interrupt
IEN0 = 0x80;
//enable all interrupt
IEN1 = 0x08;
//enable EEI interrupt
KBF = 0x00;
//clear KBF flag
IRCON_EEIIF = 0;
//clear EEI flag
}
(2) 中斷副程式:
void EEI_ISR(void) interrupt 11
//INTERRUPT VECTOR ADDR 0x5B
{
KBF = 0x00;
//clear KBF flag
IRCON_EEIIF = 0;
//clear EEI flag
}
Specifications subject to change without notice, contact your sales representatives for the most recent information.
IRFWX-A125
4
Ver. A 2009/03
EEI 功能使用方法
Application Note
5
EEI 使用組合語言的範例說明
5.1 Port1 中所有的 EEI 功能全部致能
5.2 當外部觸外訊號至 Port1 時產生中斷,並將結果顯示於 Port2
6
EEI 使用組合語言的範例程式
Description
Main program
//此範例應用包括
;=========================================================================
;
;
S Y N C M O S T E C H N O L O G Y
;
;=========================================================================
;Keyboard level selector register
sfr KBLS
= 0x93;
;Keyboard input enable register
sfr KBE = 0x94;
;Keyboard interrupt flag register
sfr KBF = 0x95;
sfr P1
= 0x90;
sfr P2
= 0xA0;
sfr IEN0
= 0xA8;
sfr IEN1
= 0xB8;
;sfr
IEN2
= 0x9A;
sfr IRCON
= 0xC0;
ORG
0000H
JMP
BEGIN
ORG
005BH
JMP
EEI_INT
;==================================================
;EEI INTERRUPT INIT ROUTINE
;==================================================
BEGIN:
;
MOV
P1,
#00H
;
MOV
IEN0,
#80H
;EA =1
MOV
IEN1,
#08H
;IEEEI =1
;
MOV
IEN2,
#00H
;
MOV
KBLS,
#0FFH
;High level detect
;
MOV
KBLS,
#000H
;Low level detect
MOV
KBE,
#0FFH
;EEI all pin enable
MOV
KBF,
#00H
;EEI all flag clear
JMP START
;==================================================
;MAIN
;==================================================
START:
JMP START
;==================================================
;EEI INTERRUPT ROUTINE
;==================================================
EEI_INT:
MOV
P2,
KBF
Specifications subject to change without notice, contact your sales representatives for the most recent information.
IRFWX-A125
5
Ver. A 2009/03
EEI 功能使用方法
Application Note
MOV
ANL
RETI
KBF,
IRCON,
#00H
#08H
END
7
EEI 使用 C 語言的範例說明(4x4 按鍵掃描)
7.1 硬體以 SM59R16A2 開發板(SDB0001B)為例,或可參考開發板電路自行製作。
7.2 原本開發板的 KEYPAD.0~7 是接到 Port5.0~7,只要依序接至 Port1.0~7 即可。
7.3 副程式 Init_EEI(void)中,只有致能 Port1.4~7 為 EEI 功能,Port1.0~3 仍為 GPIO 使用。
7.4 當按下鍵盤時,即觸發中斷副程式 EEI_ISR(void),程式中將根據 KBF 及 shift 即可顯示該
數值,亦可將 main(void)中 for 迴圈寫在 timer 中,提升系統的效率。
圖. SM59R16A2 開發板 SDB0001B 4x4 鍵盤電路圖
8
EEI 使用 C 語言的範例程式(4x4 按鍵掃描)
Description
Main program
//====================================================================
//
//
S Y N C M O S T E C H N O L O G Y
//
//====================================================================
//====================================================================
//INCLUDE FILES
Specifications subject to change without notice, contact your sales representatives for the most recent information.
IRFWX-A125
6
Ver. A 2009/03
EEI 功能使用方法
Application Note
//====================================================================
#include "..\h\SM59R16A2.h"
#include "..\h\SM59R16A2_ExtraDef.h"
#include "..\MISC\delay.h"
//====================================================================
//EEI INTERRUPT FLAG, MUST CLEAR BY SOFTWARE
//====================================================================
sbit IRCON_EEIIF = IRCON^3;
unsigned char code arr[4] = {0xFE,0xFD, 0xFB, 0xF7 };
unsigned char shift=0;
//====================================================================
//EEI INTERRUPT SUBROUTINE
//INTERRUPT NUM.11 = INTERRUPT VECTOR ADDR 0x5B
//====================================================================
void EEI_ISR(void) interrupt 11
//INTERRUPT VECTOR ADDR 0x5B
{
/*KeypadTable[]={
0x11, 0x21, 0x41, 0x81,
// 1 2 3 4
0x12, 0x22, 0x42, 0x82,
// 5 6 7 8
0x13, 0x23, 0x43, 0x83,
// 9 10 11 12
0x14, 0x24, 0x44, 0x84
// 13 14 15 16
};*/
switch(KBF+shift)
// Keyboard Flag
{
case 0x11:
P2 = 1;
break;
case 0x21:
P2 = 2;
break;
case 0x41:
P2 = 3;
break;
case 0x81:
P2 = 4;
break;
case 0x12:
P2 = 5;
break;
case 0x22:
P2 = 6;
break;
case 0x42:
P2 = 7;
break;
case 0x82:
P2 = 8;
break;
case 0x13:
P2 = 9;
break;
case 0x23:
P2 = 0x10;
break;
case 0x43:
P2 = 0x11;
break;
case 0x83:
P2 = 0x12;
break;
case 0x14:
P2 = 0x13;
break;
case 0x24:
P2 = 0x14;
break;
case 0x44:
P2 = 0x15;
break;
case 0x84:
P2 = 0x16;
break;
default:
P2 = 0x00;
Specifications subject to change without notice, contact your sales representatives for the most recent information.
IRFWX-A125
7
Ver. A 2009/03
EEI 功能使用方法
Application Note
break;
}
Delay10mSec(2);
//P2 = KBF+shift;
P2 = 0x00;
KBF = 0x00;
IRCON_EEIIF = 0;
//clear status
//clear KBF flag
//clear EEI flag
}
//====================================================================
//EEI INTERRUPT INITIALIZE
//====================================================================
void Init_EEI(void)
{
//Keyboard level selector register
KBLS = 0x00;
//Detect_Lo_level;
//KBLS = 0xff;
//Detect_Hi_level;
//Keyboard input enable register
//KBE
= 0x00;
//enable standard I/O pin
//KBE
= 0xff;
//enable EEI.KBF to generate interrupt
KBE = 0xf0;
//
IEN0 = 0x80;
//enable all interrupt
IEN1 = 0x08;
//enable EEI interrupt
KBF = 0x00;
//clear KBF flag
IRCON_EEIIF = 0;
//clear EEI flag
}
void main(void)
{
Init_EEI();
P2 = 0x00;
//clear status
while(1)
{
for(shift=0;shift<4;shift++)
{
P1 = arr[shift];
}
}
}
Specifications subject to change without notice, contact your sales representatives for the most recent information.
IRFWX-A125
8
Ver. A 2009/03