历史上的今天
今天是:2025年01月25日(星期六)
2018年01月25日 | 合泰单片机矩阵键盘程序
2018-01-25 来源:eefocus
合泰HOLTEK 单片机 写的,对初学者来说里面的分析思路很有帮助。
#include ht48c10-1.inc
;-------------------------------------------------------
data .section ’data’ ;== data section ==
temp db ? ;temporary data register
disp db ? ;key display register
count1 db ? ;delay loop counter
mask db ? ;mask register
matrix db ? ;key matrix register
;-------------------------------------------------------
code .section at 0 ’code’ ;== program section ==
org 00h ;
jmp start ;
org 04h ;external interrupt subroutine
reti ;for guarantee
org 08h ;timer/event 0 interrupt subroutine
reti ;for guarantee
org 0ch ;timer/event 1 interrupt subroutine
reti ;for guarantee
start: ;
clr iNTC ;initialize registers
clr tmrc ;to guarantee performance
clr tmr ;(interrupts)
set PAC ;(ports)
set pbc ;(input mode)
set pCC ;
main:
set pac ;(1);set port A to input mode
clr pbc ;set port B to output mode
clr pa ;zero port A (latch=0)
set pb ;off LEDs
keyloop: ;
MOV a,0feh ;(2);sCAN first row of keys
MOV matrix,a ;hold scan code
MOV pac,a ;pa.0 output 0 (latch)
MOV a,pa ;read input state
cpl acc ;;distill input state
and a,0f0h ;;
sz acc ;if any input?
jmp get_key ;yes. get input info
MOV a,0fdh ;(2);no. scan second row
MOV matrix,a ;hold scan code
MOV pac,a ;pa.1 output 0 (latch)
MOV a,pa ;read input state
cpl acc ;;distill input state
and a,0f0h ;;
sz acc ;if any input?
jmp get_key ;yes. get input info
MOV a,0fbh ;(2);no. scan third row
MOV matrix,a ;hold scan code
MOV pac,a ;pa.2 output 0 (latch)
MOV a,pa ;read input state
cpl acc ;;distill input state
and a,0f0h ;;
sz acc ;if any input?
jmp get_key ;yes. get input info
MOV a,0f7h ;(2);no. scan fourth row
MOV matrix,a ;hold scan code
MOV pac,a ;output pa.3 0 (latch)
MOV a,pa ;read input state
cpl acc ;;distill input state
and a,0f0h ;;
sz acc ;if any input?
jmp get_key ;yes. get input info
jmp keyloop ;repeat from keyloop
get_key: ;get input key info
call delays ;debounce
MOV a,pa ;test port A
or a,0fh ;
cpl acc ;
sz acc ;any key hold?
jmp go_on ;yes. go on (some key is pressed)
jmp keyloop ;no. return to scan key again
go_on:
call key_in ;(3) ;calculate table index
tabrdl disp ;(10);load display data
MOV a,disp ;;output data to port B
MOV pb,a ;(11);;
jmp keyloop ;repeat keyloop
key_in proc ;get key number
MOV a,pa ;;hold port A state
MOV temp,a ;(4) ;;
get_release: ;wait for the key to be released
MOV a,pa ;;test port A state
cpl acc ;;
and a,0f0h ;;
sz acc ;(6) ;if release?
jmp get_release ;no. keep up waiting
MOV a,0fh ;yes. calculate key number
andm a,matrix ;(7) ;mask low nibble of scan code
MOV a,0 ;keep table index at register A
get_row: ;calculate row number
rrc matrix ;;check each bit to get row number
snz status.0 ;;
jmp get_next ;if bingo goto get_next
clr c ;
add a,4h ;(8) ;table index +4 (4 keys a row)
jmp get_row ;continue calculating
get_next: ;
MOV tblp,a ;hold table index at register TBLP
MOV a,0efh ;
MOV mask,a ;; mask = 0111 1111
MOV a,0fh ;
orm a,temp ;; temp = XXXX 1111
get_column: ;calculate column number
MOV a,temp ;load temp
xor a,mask ;;test column number
snz z ;;
jmp index ;no. test next column
ret ;yes. return (TBLP)
index: ;next column
inc tblp ;(9) ;table index +1
set c ;
rlc mask ;shift mask left (LSB=1)
jmp get_column ;repeat get_column
key_in endp
delays proc ;delay subroutine
MOV a,0ffh ;load counter
MOV count1,a ;
d1:
sdz count1 ;count down count1
jmp d1
ret
delays endp
上一篇:HT1380实时时钟程序
史海拾趣
|
在移动运营商寻求非语音业务收入增长时,终端用户对高级多媒体应用范围和业务的需求也在飞速增长。那些期望从其他来源获取收入增长的运营商在可下载游戏、应用程序和音轨等方面已取得成功。移动电视提供了一个潜在的盈利业务,这是当前很多运营商考 ...… 查看全部问答> |
|
error: A1355U: A Label was found which was in no AREA (keil3.22(for arm)) 2410h.sct(5): error: A1355U: A Label was found which was in no AREA LR_ROM1 0x00000000 { ; load region错再此行,但不知为何 ER_ROM1 0x00000000 0x0100000 { ...… 查看全部问答> |
|
关于应急灯设计,给大家几点参考建议: 对于LED应急灯,设计之前应明确几点基本功能. 1:根据壳体情况,如果是便携的应急灯,实际上就是一个可充电手电筒,以下按固定应急灯功能讨论. & ...… 查看全部问答> |
|
RM0008 Rev11 第843页: Bit 16 for OUT endpoint 0, bit 18 for OUT endpoint 3 是否 Bit 16 for OUT endpoint 0 Bit 17 for OUT endpoint 1 Bit 18 for OUT endpoint 2 ??? 怎么理解??? 0008.jpg (32.17 ...… 查看全部问答> |




