key.asm
资源名称:length.rar [点击查看]
上传用户:sdjqgc
上传日期:2022-08-06
资源大小:2404k
文件大小:6k
源码类别:
嵌入式/单片机编程
开发平台:
Asm
- //========================================================================================
- // Progarm: The head file for key.asm in assembly view
- // Arranged by: Andy Hsu
- // Modified by Arthur Shieh
- // Last modified date:
- // 2000/06/23: first version
- // 2000/07/20: modified
- // 2002/5/31 : Modified by Arthur Shieh to use IOA8~IOA15 for keyscan
- //
- // Functions:
- // F_Key_Scan_Initial;
- // F_Key_Scan_ServiceLoop;
- // F_Key_DebounceCnt_Down;
- //
- // call F_SP_GetCh;
- //========================================================================================
- .INCLUDE SPCE061A.inc;
- .public _F_Key_Scan_Initial
- .PUBLIC F_Key_Scan_Initial;
- .public _F_Key_Scan_ServiceLoop
- .PUBLIC F_Key_Scan_ServiceLoop;
- .PUBLIC _SP_GetCh;
- .PUBLIC _SP_GetCh_1;
- .PUBLIC F_SP_GetCh;
- .PUBLIC R_KeyStrobe;
- .public _F_KeyScan;
- .define Port_Key P_IOA_Data
- .define Port_Key_Dir P_IOA_Dir
- .define Port_Key_Attrib P_IOA_Attrib
- .define Port_Key_Buffer P_IOA_Buffer
- .define M_MASK 0x00ff
- .define M_ScanBegin 0x0001
- .define M_KeyNumber 0x0008
- //////////////////////////////////////////////////////////////////
- // RAM Define Area
- //////////////////////////////////////////////////////////////////
- .RAM
- .VAR R_DebounceReg; //for keyboard scan
- //.DEFINE C_DebounceCnt 0x0008;
- .DEFINE C_DebounceCnt 0x0006;
- .VAR R_KeyStrobe; //for keyboard scan
- .var R_KeyCounter //key down counter
- .var R_Keyflag //save the key flag
- .var R_Keyoll //save the oll data of key
- .CODE
- //////////////////////////////////////////////////////////////////
- // Function: Initialization for F_Key_Scan_ServiceLoop
- //////////////////////////////////////////////////////////////////
- _F_Key_Scan_Initial:
- F_Key_Scan_Initial:
- r1 = 0x0000; //
- [R_KeyCounter] = r1; //
- [R_Keyflag] = r1; //
- [R_Keyoll] = r1; //
- [R_KeyStrobe] = r1;
- r1 = [Port_Key_Dir]
- r2 = 0xffff
- r2^=M_MASK
- r1 = r1|r2
- [Port_Key_Dir] = r1
- r1 = [Port_Key_Attrib]
- r1 = r1|r2
- [Port_Key_Attrib] = r1
- r1 = [Port_Key_Buffer]
- r1 = r1|r2
- [Port_Key] = r1
- // r1 = C_DebounceCnt; //
- // [R_DebounceCnt] = r1; //reset debounce counter
- retf;
- //////////////////////////////////////////////////////////////////
- // Function: Get Key code from key pad(8 x 1 key pad)
- // Input: Port IOA b15-b8
- // Output: R_KeyStrobe b7-b0
- // | | | |
- // +Vcc --- x --- x ... x --- x ---
- // | | | |
- // IOA.15 IOA.8
- // Note: 1)link F_DebounceCntDown is necessary
- // Destory register: r1, r2
- //////////////////////////////////////////////////////////////////
- _F_Key_Scan_ServiceLoop:
- F_Key_Scan_ServiceLoop:
- r1 = [P_IOA_Data]; // get key data from IOA
- // r1 ^= 0xff00//M_MASK
- r2 = M_MASK
- r1 &= R2
- jnz H_KeyHight //非零转
- r2 = [R_Keyoll]
- jnz L_KeyLow //上一次的键值非零,则转
- r1 = 0
- jmp L_KS_Exit2 //退出
- L_KeyLow:
- r2 = [R_Keyflag]
- test r2,0x0001
- jnz L_KeyLow_1 //标志位非零则转
- r2 = 0
- [R_KeyCounter] = r2
- [R_Keyflag] = r2
- [R_Keyoll] = r1
- r1 = 0
- jmp L_KS_Exit2 //退出
- L_KeyLow_1:
- r2 = 0
- [R_KeyCounter] = r2
- [R_Keyflag] = r2
- r1 = [R_Keyoll] //取上一次的键值
- r2 = 0
- [R_Keyoll] = r2
- jmp L_KeyGet //到判断优先级的程序
- H_KeyHight: //当次按键非零处理
- r2 = [R_KeyCounter]
- cmp r2,C_DebounceCnt //比较
- ja H_KeyHight_1 //大于规定数,转
- r2+=1 //Counter++
- [R_KeyCounter] = r2
- jmp H_KeyHight_2
- H_KeyHight_1:
- r2 = [R_Keyflag] //flag 置位
- r2 |= 0x0001
- [R_Keyflag] = r2
- H_KeyHight_2:
- [R_Keyoll] = r1
- r1 = 0
- jmp L_KS_Exit2 //退出
- //L_KeyGet:
- // r2 = r1 //键盘优先级而做的 begin....
- // r3 = 0x0080 //Edit by xinqiang 2004.12.21
- //L_KS_Renews2: //xinqiang@sunnorth.com.cn
- // r3 = r3 lsl 1 //tel:010-62981668-2916
- // test r3,0x2000 //
- // jz L_KS_Renews12 //
- // r1 = 0 //
- // jmp L_KS_Exit2 //
- //L_KS_Renews12: //
- // r1 = r1&r3 //
- // jnz L_KS_Exit2 //
- L_KeyGet:
- jmp L_KS_Exit2
- r1 = r2 //
- // jmp L_KS_Renews2 //....end
- L_KS_Exit2:
- [R_KeyStrobe] = r1; //save stable key code to R_KeyStrobe
- retf; //
- //****************************************************************
- // Function: Get Keycode for I/O Port
- // Destory register: r1, r2
- //****************************************************************
- _SP_GetCh:
- F_SP_GetCh:
- push r2 to [SP];
- r1 = [R_KeyStrobe]; // Get Key code
- r2 = 0x0000; // Clear KeyStrobe for next key
- [R_KeyStrobe] = r2; //
- pop r2 from [SP];
- retf;
- //****************************************************************
- // Function: Get Keycode for I/O 8 Port Just for RECORD_KEY
- // Destory register: r1
- //****************************************************************
- _SP_GetCh_1:
- F_SP_GetCh_1:
- r1 = [P_IOA_Data]; // Get Key code
- r1 &= 0x0200
- retf;
- //=================================================================//
- //name:F_KeyScan
- //for user: C function unsigned int F_KeyScan(void)
- //output:Key Sand data from Key1~5 Key1>>Key2>>Key3>>Key4>>Key5
- //note: noll
- //=================================================================//
- _F_KeyScan:.proc
- F_KeyScan:
- push r2,r5 to [sp]
- r1 = [Port_Key]
- r1 ^= M_MASK
- jnz F_KeyScan_Get1
- r1 = 0
- jmp F_KeyScan_Exit
- F_KeyScan_Get1:
- call F_Delay //call key Scan delay 10~18ms
- r1 = [Port_Key]
- r1 ^= M_MASK
- jnz F_KeyScan_Get2 //check the key again
- r1 = 0
- jmp F_KeyScan_Exit
- F_KeyScan_Get2:
- r2 = r1
- r3 = r1
- r1 = 0
- r4 = M_ScanBegin //0x0001
- F_KeyScan_loop1:
- r1+=1
- r3 = r3&r4
- jnz F_KeyScan_Exit1
- cmp r1,M_KeyNumber //8
- je F_KeyScan_Exit1
- r4 = r4 lsl 1
- r3 = r2
- jmp F_KeyScan_loop1
- F_KeyScan_Exit1:
- // r1 = r3
- F_KeyScan_Exit2:
- r3 = 0x0001
- [P_Watchdog_Clear] = r3
- r2 = [Port_Key]
- r2 ^= M_MASK
- jnz F_KeyScan_Exit2
- F_KeyScan_Exit:
- pop r2,r5 from [sp]
- retf
- .endp
- F_Delay:
- push r3 ,r5 to [sp]
- r3=0x6e6d//0xDCDB
- Dely_L:
- r4 = 0x0001
- [P_Watchdog_Clear] = r4
- r3-=1
- jnz Dely_L
- pop r3,r5 from [sp]
- retf
- //========================================================================================
- // End of key.asm
- //========================================================================================