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-0229 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-0229 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-0229 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-0229 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-0229 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-0229 6 Ver. A 2010/08