SM39R 系列 KBI 功能使用方法 SM39R 系列 KBI 功能使用方法 1 适用产品: 1.1 SM39R16A2/ SM39R12A2/ SM39R08A2 2 KBI 使用说明: 2.1 共有 4 个 I/O 可致能为 KBI 功能 I/O。 2.2 由 Port 0 共 4 个 I/O,分别对应至 4 个独立的旗标(KBF.0~ KBF.3),且共享同一个中断向量位置 (0x5B)。 2.3 可由程序设定为高准位或低准位触发。 2.4 当触发讯号输入至 KBI 任一引脚,其对应的旗标将会被设置为”1”,并且进入中断子程序。 2.5 KBI 功能主要可做为 2x2 矩阵式键盘扫描,或其它应用。 KBI0 Input circuitry KBI1 Input circuitry KBI2 Input circuitry KBI3 Input circuitry OR KBIIF: KBI interrupt flag IEKBI: KBI interrupt enable Fig. Interrupts from KBI 4 inputs Fig. keyboard input circuitry Specifications subject to change without notice, contact your sales representatives for the most recent information. ISSFA-0230 1 Ver. A 2010/08 SM39R 系列 KBI 功能使用方法 2.6 KBI 相关缓存器: KBI KBLS KBE KBF KBD IEN1 IRCON Description KBI level selection KBI input enable KBI flag KBI De-bounce control register Interrupt Enable 1 register Interrupt request register Mnemonic: KBLS 7 6 - Direct Bit 7 93h 94h 95h - 96h KBDEN - - B8H EXEN2 - C0H EXF2 TF2 5 - Bit 6 Bit 5 Bit 4 KBI function - 4 - Bit 3 Bit 2 Bit 1 Bit 0 RESET KBLS3 KBE3 KBF3 KBLS2 KBE2 KBF2 KBLS1 KBE1 KBF1 KBLS0 KBE0 KBF0 00H 00H 00H - - - KBD1 KBD0 00H IEIIC IELVI IEKBI IEADC IESPI IEPWM 00H IICIF LVIIF KBIIF ADCIF SPIIF PWMIF 00H 3 KBLS3 2 KBLS2 1 KBLS1 Address: 93h 0 Reset KBLS0 00H 1 KBE1 Address: 94h 0 Reset KBE0 00H KBLS.3: 触发准位设定位 (Keyboard Line 3 level selection bit) 0 : 设定为低准位触发 1 : 设定为高准位触发 KBLS.2: 触发准位设定位 (Keyboard Line 2 level selection bit) 0 : 设定为低准位触发 1 : 设定为高准位触发 KBLS.1: 触发准位设定位 (Keyboard Line 1 level selection bit) 0 : 设定为低准位触发 1 : 设定为高准位触发 KBLS.0: 触发准位设定位 (Keyboard Line 0 level selection bit) 0 : 设定为低准位触发 1 : 设定为高准位触发 Mnemonic: KBE 7 6 - 5 - 4 - 3 KBE3 2 KBE2 KBE.3: 致能位 (Keyboard Line 3 enable bit) 0 : KBI 禁能,预设为一般的出入埠(GPIO) 1 : KBI 致能,当触发讯号输入时,KBF.7 = 1,会触发中断 KBE.2: 致能位 (Keyboard Line 2 enable bit) 0 : KBI 禁能,预设为一般的出入埠(GPIO) 1 : KBI 致能,当触发讯号输入时,KBF.7 = 1,会触发中断 KBE.1: 致能位 (Keyboard Line 1 enable bit) 0 : KBI 禁能,预设为一般的出入埠(GPIO) 1 : KBI 致能,当触发讯号输入时,KBF.7 = 1,会触发中断 KBE.0: 致能位 (Keyboard Line 0 enable bit) 0 : KBI 禁能,预设为一般的出入埠(GPIO) 1 : KBI 致能,当触发讯号输入时,KBF.7 = 1,会触发中断 Specifications subject to change without notice, contact your sales representatives for the most recent information. ISSFA-0230 2 Ver. A 2010/08 SM39R 系列 KBI 功能使用方法 Mnemonic: KBF 7 6 - 5 - 4 - 3 KBF3 2 KBF2 1 KBF1 Address: 95h 0 Reset KBF0 00H KBF.3: KBI 触发旗标 (Keyboard Line 3 flag) 1: 当 KBI3 侦测到输入讯号时,KBF.3 由硬件设为”1”,并产生 KBI 中断; 0: 必须由软件清除为”0” KBF.2: KBI 触发旗标 (Keyboard Line 2 flag) 1: 当 KBI2 侦测到输入讯号时,KBF.2 由硬件设为”1”,并产生 KBI 中断; 0: 必须由软件清除为”0” KBF.1: KBI 触发旗标 (Keyboard Line 1 flag) 1: 当 KBI1 侦测到输入讯号时,KBF.1 由硬件设为”1”,并产生 KBI 中断; 0: 必须由软件清除为”0” KBF.0: KBI 触发旗标 (Keyboard Line 0 flag) 1: 当 KBI0 侦测到输入讯号时,KBF.0 由硬件设为”1”,并产生 KBI 中断; 0: 必须由软件清除为”0” Mnemonic: KBD 7 6 KBDEN - 5 - 4 - 3 - 2 - 1 KBD1 Address: 96h 0 Reset KBD0 00H KBDEN: 除弹跳功能致能位(Enable KBI de-bounce function). 预设为致能(The default KBI function is enabled). KBDEN = 0, 致能除弹跳功能 KBDEN = 1, 禁能除弹跳功能 KBD[1:0]: 除弹跳时间设定位. 若 KBDEN = “0”,则预设为 320 ms. KBD[1:0] = 00, 除弹跳时间为 320 ms. KBD[1:0] = 01, 除弹跳时间为 160 ms. KBD[1:0] = 10, 除弹跳时间为 80 ms. KBD[1:0] = 11, 除弹跳时间为 40 ms. Mnemonic: IEN1 7 6 EXEN2 - 5 IEIIC 4 IELVI 3 IEKBI 2 IEADC 1 IESPI Address: B8h 0 Reset IEPWM 00H 3 KBIIF 2 ADCIF 1 SPIIF Address: C0h 0 Reset PWMIF 00H IEKBI: KBI interrupt enable. IEKBI = 0 – Disable KBI interrupt. IEKBI = 1 – Enable KBI interrupt. Mnemonic: IRCON 7 6 EXF2 TF2 5 IICIF 4 LVIIF KBIIF: KBI interrupt flag. Must be cleared by software. Specifications subject to change without notice, contact your sales representatives for the most recent information. ISSFA-0230 3 Ver. A 2010/08 SM39R 系列 KBI 功能使用方法 2.7 以下是 KBI 相对应的中断向量表: Table 11-1: Interrupt vectors Interrupt Vector Address 0003h 000Bh Interrupt Request Flags IE0 – External interrupt 0 TF0 – Timer 0 interrupt Interrupt Number *(use Keil C Tool) 0 1 IE1 – External interrupt 1 0013h 2 TF1 – Timer 1 interrupt 001Bh 3 RI/TI – Serial channel interrupt TF2/EXF2 – Timer 2 interrupt 0023h 002Bh 4 5 PWMIF – PWM interrupt 0043h 8 SPIIF – SPI interrupt 004Bh 9 ADCIF – A/D converter interrupt 0053h 10 KBIIF – keyboard Interface interrupt 005Bh 11 LVIIF – Low Voltage Interrupt 0063h 12 IICIF – IIC interrupt 006Bh 13 Comparator interrupt 0093h 18 *See Keil C about C51 User’s Guide about Interrupt Function description KBI 中断应用的参考程序: 1. KBI I/O 全部致能,Ch.0/Ch.1 高准位侦测 Ch.2/Ch.3 低准位侦测 Description C 语言 2. De-bounce 时间为 40ms //==================================================================== // SYNCMOS TECHNOLOGY //==================================================================== #include "SM39R16A2.h" #include " SM39R16A2_KBI.h " #define KBI_VECTOR 11 //KBI Interrupt Vevtor #define d_KBLS 0x03 //KBI Low/High level detection selection (0~0x0F) #define d_KBEX 0x0F //KBI Input Enable (0~0x0F) #define d_KBDEN 0x00 //KBI De-bounce Function Enable #define d_KBDS 0x03 //KBD[1:0] KBI De-bounce Time Selection (0~3) #define d_KBIIE 0x01 //KBI Interrupt Enable bit void KBI_initialize(void) //Initialize KBI { EA=0; IEKBI=(d_KBIIE); //Disable All Interrupt Function //Enable KBI Interrupt Function KBD=(d_KBDEN<<7)|(d_KBDS); //Enable KBI De-bounce and De-bounce Time Function Specifications subject to change without notice, contact your sales representatives for the most recent information. ISSFA-0230 4 Ver. A 2010/08 SM39R 系列 KBI 功能使用方法 KBLS=(d_KBLS); //KBI Input High/Low Level Select KBE=(d_KBEX); //KBI Input Channel Enable EA=1; //Enable All Interrupt } //---------------------------------------------------------------------// void KBI_Disable(void) { IEKBI=0; //Disable KBI Interrupt KBE=0; //Disable KBI Function } //---------------------------------------------------------------------// void KBI_ISR(void) interrupt KBI_VECTOR //KBI Interrupt Subroutine { switch(KBF) //Decision Occur Channel Flag (KBF) { case 0x08: //KBI Channel 3 Occur Interrupt(KBF3) P1_3=0; break; case 0x04: //KBI Channel 2 Occur Interrupt(KBF2) P1_2=0; break; case 0x02: //KBI Channel 1 Occur Interrupt(KBF1) P1_1=0; break; case 0x01: //KBI Channel 0 Occur Interrupt(KBF0) P1_0=0; break; } KBF=0; ////KBIIF=0; //Hardware Clear KBI Flag } void main(void) //Main Function Start { KBI_initialize(); //Call KBI Initial Subroutine while(1); //KBI_Disable(); } Specifications subject to change without notice, contact your sales representatives for the most recent information. ISSFA-0230 5 Ver. A 2010/08 SM39R 系列 KBI 功能使用方法 Description 1. KBI I/O 全部致能 Ch.0~3 高准位侦测 De-bounce 时间为 320ms 2. 当外部触发讯号至 KBI I/O 时产生中断,并将结果显示于 Port1 汇编 //==================================================================== // SYNCMOS TECHNOLOGY //==================================================================== SFR KBLS = 0x93; ;Keyboard level selector register SFR KBE = 0x94; ;Keyboard input enable register SFR KBF = 0x95; ;Keyboard interrupt flag register SFR KBD = 0x96; ;de-bounce mechanism select SFR IEN0 = 0xA8; SFR IEN1 = 0xB8; SFR IRCON = 0xC0; ORG 0000H JMP BEGIN ORG 005BH JMP KBI_INT ;================================================== ;KBI INTERRUPT INIT ROUTINE ;================================================== BEGIN: MOV IEN0,#80H ;EA =1 MOV IEN1,#08H ;IEKBI =1 MOV KBD,#00H ;KBI de-bounce function and set de-bounce time is 320 ms. MOV KBLS,#0FFH ;High level detect ; MOV KBLS,#00H ;Low level detect MOV KBE, #0FFH ;KBI all pin enable MOV KBF, #00H ;KBI all flag clear JMP START ;================================================== ;MAIN ;================================================== START: JMP START ;================================================== ;KBI INTERRUPT ROUTINE ;================================================== KBI_INT: MOV P1,KBF MOV KBF, #00H ANL IRCON,#08H RETI END 新茂国际科技希望能为客户减少开发的时间及辛劳,故提供 “Codzard 范例程序产生器" 可于 新茂网站首页>下载专区> 软件下载 内下载此软件,如有任何建议,请来信告知,谢谢! 销售客服 电子信箱: [email protected] 技术支持 电子信箱: [email protected] Specifications subject to change without notice, contact your sales representatives for the most recent information. ISSFA-0230 6 Ver. A 2010/08