外部擴展中斷功能使用方法外部擴展中斷功能使用方法

外部擴展中斷 功能使用方法
Application Note
外部擴展中斷 功能使用方法
適用產品:SM59D04G2,SM59D03G2。
應用說明:
1 針對使用新茂(SyncMOS)MCU,如有因程式設計之關係,需要使用到更多的中斷輸入時。
2 此外部擴展中斷功能共增加八個中斷輸入【P1.0~P1.7,共用中斷向量 0x33】可供選擇使用。
3 此八個輸入可單獨選擇為高位準觸發或低位準觸發【設定 KBLS 暫存器】。
4 此八個輸入可單獨選擇為外部擴展中斷或一般的輸出/輸入腳【設定 KBE 暫存器】。
使用方法:
1. 特殊功能暫存器說明:
1.1. EEI 觸發準位選擇暫存器 (KBLS,$FD):
Read/Write
Reset Value
Bit 7
KBLS7
R/W
0
KBLS6
R/W
0
KBLS5
R/W
0
KBLS4
R/W
0
KBLS3
R/W
0
KBLS2
R/W
0
KBLS1
R/W
0
Bit 0
KBLS0
R/W
0
KBLS7: EEI line 7 level selection bit
Cleared to enable a low level detection on Port line 7.
Set to enable a high level detection on Port line 7.
KBLS6: EEI line 6 level selection bit
Cleared to enable a low level detection on Port line 6.
Set to enable a high level detection on Port line 6.
KBLS5: EEI line 5 level selection bit
Cleared to enable a low level detection on Port line 5.
Set to enable a high level detection on Port line 5.
KBLS4: EEI line 4 level selection bit
Cleared to enable a low level detection on Port line 4.
Set to enable a high level detection on Port line 4.
KBLS3: EEI line 3 level selection bit
Cleared to enable a low level detection on Port line 3.
Set to enable a high level detection on Port line 3.
KBLS2: EEI line 2 level selection bit
Cleared to enable a low level detection on Port line 2.
Set to enable a high level detection on Port line 2.
KBLS1: EEI line 1 level selection bit
Cleared to enable a low level detection on Port line 1.
Set to enable a high level detection on Port line 1.
KBLS0: EEI line 0 level selection bit
Cleared to enable a low level detection on Port line 0.
Set to enable a high level detection on Port line 0.
Specifications subject to change without notice, contact your sales representatives for the most recent information.
IRFWX-A083
1
Ver. A 2008/06
外部擴展中斷 功能使用方法
Application Note
1.2. EEI 輸入狀態選擇暫存器 (KBE,$FE):
Read/Write
Reset Value
Bit 7
KBE7
R/W
0
KBE6
R/W
0
KBE5
R/W
0
KBE4
R/W
0
KBE3
R/W
0
KBE2
R/W
0
KBE1
R/W
0
Bit 0
KBE0
R/W
0
KBE7: EEI line 7 Enable bit
Cleared to enable standard I/O pin.
Set to enable KBF.7 bit in KBF register to generate an interrupt request.
KBE6: EEI line 6 Enable bit
Cleared to enable standard I/O pin.
Set to enable KBF.6 bit in KBF register to generate an interrupt request.
KBE5: EEI line 5 Enable bit
Cleared to enable standard I/O pin.
Set to enable KBF.5 bit in KBF register to generate an interrupt request.
KBE4: EEI line 4 Enable bit
Cleared to enable standard I/O pin.
Set to enable KBF.4 bit in KBF register to generate an interrupt request.
KBE3: EEI line 3 Enable bit
Cleared to enable standard I/O pin.
Set to enable KBF.3 bit in KBF register to generate an interrupt request.
KBE2: EEI line 2 Enable bit
Cleared to enable standard I/O pin.
Set to enable KBF.2 bit in KBF register to generate an interrupt request.
KBE1: EEI line 1 Enable bit
Cleared to enable standard I/O pin.
Set to enable KBF.1 bit in KBF register to generate an interrupt request.
KBE0: EEI line 0 Enable bit
Cleared to enable standard I/O pin.
Set to enable KBF.0 bit in KBF register to generate an interrupt request.
Specifications subject to change without notice, contact your sales representatives for the most recent information.
IRFWX-A083
2
Ver. A 2008/06
外部擴展中斷 功能使用方法
Application Note
1.3. EEI 中斷旗標暫存器 (KBF,$FF):
Read/Write
Reset Value
Bit 7
KBF7
R
0
KBF6
R
0
KBF5
R
0
KBF4
R
0
KBF3
R
0
KBF2
R
0
KBF1
R
0
Bit 0
KBF0
R
0
KBF7: EEI line 7 flag
Set by hardware when the port line 7 detects a programmed level. It generates a EEI
interrupt request if the KBE.7 bit in KBE register is set.
This register is read only access; the flag is automatically cleared by reading the register.
KBF6: EEI line 6 flag
Set by hardware when the port line 6 detects a programmed level. It generates a EEI
interrupt request if the KBE.6 bit in KBE register is set.
This register is read only access; the flag is automatically cleared by reading the register.
KBF5: EEI line 5 flag
Set by hardware when the port line 5 detects a programmed level. It generates a EEI
interrupt request if the KBE.5 bit in KBE register is set.
This register is read only access; the flag is automatically cleared by reading the register.
KBF4: EEI line 4 flag
Set by hardware when the port line 4 detects a programmed level. It generates a EEI
interrupt request if the KBE.4 bit in KBE register is set.
This register is read only access; the flag is automatically cleared by reading the register.
KBF3: EEI line 3 flag
Set by hardware when the port line 3 detects a programmed level. It generates a EEI
interrupt request if the KBE.3 bit in KBE register is set.
This register is read only access; the flag is automatically cleared by reading the register.
KBF2: EEI line 2 flag
Set by hardware when the port line 2 detects a programmed level. It generates a EEI
interrupt request if the KBE.2 bit in KBE register is set.
This register is read only access; the flag is automatically cleared by reading the register.
KBF1: EEI line 1 flag
Set by hardware when the port line 1 detects a programmed level. It generates a EEI
interrupt request if the KBE.1 bit in KBE register is set.
This register is read only access; the flag is automatically cleared by reading the register.
KBF0: EEI line 0 flag
Set by hardware when the port line 0 detects a programmed level. It generates a EEI
interrupt request if the KBE.0 bit in KBE register is set.
This register is read only access; the flag is automatically cleared by reading the register.
Specifications subject to change without notice, contact your sales representatives for the most recent information.
IRFWX-A083
3
Ver. A 2008/06
外部擴展中斷 功能使用方法
Application Note
2. 程式範例:
2.1. 設定 EEI 功能相對應之暫存器:
SFR
SFR
SFR
SFR
SFR
SFR
SFR
IE
IE1
IP
IP1
KBLS
KBE
KBF
=
=
=
=
=
=
=
0xA8;定義 IE 暫存器對應位址
0xA9;定義 IE1 暫存器對應位址
0xB8;定義 IP 暫存器對應位址
0xB9;定義 IP1 暫存器對應位址
0xFD;定義 KBLS 暫存器對應位址
0xFE;定義 KBE 暫存器對應位址
0xFF;定義 KBF 暫存器對應位址
2.2. 啟動 EEI 中斷功能:
2.2.1. 啟動 EEI 中斷功能【使用組合語言】
MOV
IE,#80H
;啟動選擇之中斷功能
MOV
IE1,#01H
;啟動 EEI 之中斷功能
2.2.2. 啟動 EEI 中斷功能【使用 C 語言】
IE=0x80; //啟動選擇之中斷功能
IE1=0x01: //啟動 EEI 之中斷功能
2.3. 設定中斷副程式:
2.3.1. 設定 EEI 中斷副程式【使用組合語言】
ORG
0033H;設定中斷向量為 0x0033
MOV
P0,KBF;將 EEI 中斷旗標暫存器(KBF)傳至 Port 0,以顯示 EEI 中斷是由 P1.X
;產生,並將 EEI 中斷旗標於讀出後清為”0”。
2.3.2. 設定 EEI 中斷副程式【使用 C 語言】
void KBI(void) interrupt 6
//設定中斷向量為 0x0033
{
p0=KBF;
//將 EEI 中斷旗標暫存器(KBF)傳至 Port 0,以顯示 EEI 中斷
//是由 P1.X 產生,並將 EEI 中斷旗標於讀出後清為”0”。
}
Specifications subject to change without notice, contact your sales representatives for the most recent information.
IRFWX-A083
4
Ver. A 2008/06
外部擴展中斷 功能使用方法
Application Note
2.4. 設定 EEI 之中斷模式:
2.4.1. 設定 EEI 之中斷模式【使用組合語言】
範例一:
MOV
KBLS,#00H ;設定 P1.0~P1.7 為低準位觸發
MOV
KBE,#0FFH ;設定 P1.0~P1.7 為外部擴展中斷輸入腳
範例二:
MOV
KBLS,#0FH ;設定 P1.0~P1.3 為高準位觸發;P1.4~P1.7 為低準位觸發
MOV
KBE,#55H ;設定 P1.0、P1.2、P1.4、P1.6 為外部擴展中斷輸入腳
;設定 P1.1、P1.3、P1.5、P1.7 為一般輸出輸入腳
2.4.2. 設定 EEI 之中斷模式【使用 C 語言】
範例一:
KBLS = 0x00;
//設定 P1.0~P1.7 為低準位觸發
KBE
= 0xFF; //設定 P1.0~P1.7 為外部擴展中斷輸入腳
範例二:
KBLS =
KBE
=
0x0F;
0x55;
//設定 P1.0~P1.3 為高準位觸發;P1.4~P1.7 為低準位觸發
//設定 P1.0、P1.2、P1.4、P1.6 為外部擴展中斷輸入腳
//設定 P1.1、P1.3、P1.5、P1.7 為一般輸出輸入腳
Specifications subject to change without notice, contact your sales representatives for the most recent information.
IRFWX-A083
5
Ver. A 2008/06