外部扩展中断功能使用方法外部扩展中断功能使用方法

外部扩展中断 功能使用方法
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-A084
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-A084
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-A084
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-A084
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-A084
5
Ver. A 2008/06