📄 keyboard_band.txt
字号:
mov KeyIn_L,#0FFh ;Config Key return lines as Input
Ready4Next_L: NEXT_ROW ; Advance row
nop
nop
inc r1
djnz r2,NextRow_L
ajmp ScanAllKeys2
NextRow_L: ajmp ScanUpr_L
;***** Scan Upper half of the keybed
ScanAllKeys2: mov dptr,#RowSelectTab
mov RowIdx,#0 ;Init offset into RowSelectTab
NEXT_ROW ;Select Initial row
mov r2,#ROWS_H/2 ;Init row counter, 2 rows read on each pass
; Check Next 8 Keys
; This Code Expanded Inline For Speed , e' spaghetti moltissimo
ScanUpr_H: mov a,KeyIn_H ; Sample new key state upper
NEXT_ROW ; Advance row
anl AR1,#01111111b
xch a,@r1 ; Save new : get old
xrl a,@r1 ; check for changes
jnz ScanLwr_H ; Capture lower if not same
mov a,KeyIn_H ; Sample new key state lower
; NEXT_ROW ; Advance row
mov KeyInLower,a
orl AR1,#10000000b
xch a,@r1 ; Save new : get old
xrl a,@r1 ; check for changes
jnz ProcKeys_H ; Process switches if not the same
jmp Ready4Next_H
ScanLwr_H: mov a,KeyIn_H ; Capture lower if upper different
; NEXT_ROW ; Advance row
orl AR1,#10000000b
mov @r1,a
ProcKeys_H: mov KeyOut_H,#0FFh ; Deselect rows during event processing
mov KeyOut_L,#0FFh
mov a,@r1 ; Get key in values to process
mov KeyInLower,a
anl AR1,#01111111b
mov a,@r1
mov KeyInUpper,a
mov a,r1 ; Calculate key address
add a,#-OldKeyStatUpper ; from Row pointer
swap a ; Multiply by 8
rr a
add a,#CountersHIGH
mov r0,a
TestKey 0 ; Go check keys
inc r0 ; Next Key
TestKey 1
inc r0
TestKey 2
inc r0
TestKey 3
inc r0
TestKey 4
inc r0
TestKey 5
inc r0
TestKey 6
inc r0
TestKey 7
mov dptr,#RowSelectTab ;Reset [dptr] back to RowSelectTab
jnb ST9_ACK,$ ;Ensure ST9 has finished reading previous byte
mov KeyIn_L,#0FFh ;Config Key return lines as Input
Ready4Next_H: NEXT_ROW ; Advance row
nop
nop
inc r1
djnz r2,NextRow_H
ajmp ScanAllKeys
NextRow_H: ajmp ScanUpr_H
; End Of Main Loop
; ***********************************************************************
; * *
; * Test Code to Check I/O ports MP:13/May/03 *
; * *
; ***********************************************************************
TestScan: mov IE,#0 ; Kill interupts
; mov Keyout_H,#HIGH ROW_0 ;Select initial row
; mov KeyOut_L,#LOW ROW_0
mov r2,#ROWS_L ;Init row counter
mov dptr,#RowSelectTab
mov r3,#0 ;Index into Row Select tab
tscn1: NEXT_ROW ;Select next row
mov r1,#080h ;Delay whilst reading value back
tscn2: mov a,KeyIn_L
djnz r1,tscn2
djnz r2,tscn1 ;Loop till all rows scanned
sjmp TestScan
;tscn0: mov Keyout_H,#011101111b ;Select initial row
; mov KeyOut_L,#011111111b
;tscn1: mov r2,KeyIn_L
; djnz r1,tscn1
;
; mov Keyout_H,#011111111b ;Select initial row
; mov KeyOut_L,#011110111b
;tscn2: mov r2,KeyIn_L
; djnz r1,tscn2
; sjmp tscn0
; ***********************************************************************
; * *
; * Increment Velocity Curve MP:2/Jun/03 *
; * *
; * Enter [] *
; * Exit [] *
; * Alters [] *
; * *
; * Notes Deselects scan rows, needs to be re-asserted *
; ***********************************************************************
IncVelCurve: jnb VEL_CURVE,ivcx ;Exit if no request for new velocity curve
mov KeyOut_H,#0FFh ;Deselect rows during event processing
mov KeyOut_L,#0FFh
mov a,VelCurve ;Increment velocity curve value
inc a
cjne a,#VEL_CURVES,$+3
jc ivc1 ;[c] set if < Max vel curve
mov a,#0
ivc1: mov VelCurve,a ;Store new velocity curve value
add a,#VEL_CURVE_0 ;Add in initial vel curve number
TX ;Send vel curve value to ST9
;WaitVelAck: jb VEL_CURVE,WaitVelAck ;Wait for ST9 to acknowledge the velocity curve
jnb ST9_ACK,$ ;Ensure ST9 has finished reading previous byte
mov KeyIn_L,#0FFh ;Config Key return lines as Input
ivcx: ret
; ***************************************
; * *
; * State Action Table *
; * *
; ***************************************
HandleState:
anl a,#11110000b
mov dptr,#StateActionTable
jmp @a+dptr ; Goto Handler
; These are taken from truth table at start of prog
StateActionTable:
ajmp InstantKeyOn ; State A
dw 1,2,3,4,5,6,7
ajmp GotoStateB
dw 1,2,3,4,5,6,7
NOACTION
dw 1,2,3,4,5,6,7
NOACTION
dw 1,2,3,4,5,6,7
ajmp GotoStateC ; State B
dw 1,2,3,4,5,6,7
NOACTION
dw 1,2,3,4,5,6,7
ajmp Illegal
dw 1,2,3,4,5,6,7
ajmp KeyOnDebounce
dw 1,2,3,4,5,6,7
NOACTION ; State C
dw 1,2,3,4,5,6,7
ajmp GotoStateD
dw 1,2,3,4,5,6,7
ajmp Illegal
dw 1,2,3,4,5,6,7
ajmp GotoStateA
dw 1,2,3,4,5,6,7
NOACTION ; State D
dw 1,2,3,4,5,6,7
NOACTION
dw 1,2,3,4,5,6,7
ajmp Illegal
dw 1,2,3,4,5,6,7
ajmp GotoStateA
; Enter These Routines With [R0] = Key Pointer
; State Entrys Are As Follows
; GotoStateA Reset Timer To Zero
; GotoStateB Start Timer
; GotoStateC Read Timer
; GotoStateD No Operation
;***** Both Switches Released, Send Note Off
GotoStateA:
mov a,R0 ; Convert Pointer Into
add a,#LOWESTNOTE-NOTE_0
setb ACC.NOTE_FLAG_
TX
mov a,#NOTE_OFF
TX
KeyOnDebounce:
mov @r0,#StateA ; Goto State A but no GateOff
ret
;***** Initial switch pressed, start timer
GotoStateB:
mov a,#StateB ; Put into state B
orl a,r3 ; Save HIGH
mov @r0,a
orl AR0,#80h
mov @r0,AR4 ; Save Low
anl AR0,#7Fh
ret
GotoStateD:
mov @r0,#StateD
ret
; Send Error Message To Main Processor
Illegal:
mov a,r0
add a,#LOWESTNOTE-NOTE_0
setb ACC.NOTE_FLAG_
TX
mov a,#NOTE_FLAG ; 2 Notes in a row will flag Error condition
TX
ret
;***** Both Switches Pressed, both were previously off, so generate max vel
InstantKeyOn:
mov a,r0 ; Note number
add a,#LOWESTNOTE-NOTE_0
setb ACC.NOTE_FLAG_
TX
mov dptr,#CounterToVelocity ; Use initial value from velocity table
sjmp ValueOk
;***** Both Switches Pressed, Send Note On
GotoStateC:
mov DPH,#HIGH CounterToVelocity ; Assume vel timer is short and is in 1st 256 bytes of the table
mov a,r0
add a,#LOWESTNOTE-NOTE_0
setb ACC.NOTE_FLAG_
TX
orl AR0,#80h
clr c
mov a,@r0 ; Get OLD value LOW
anl AR0,#7fh ; Point to OLD value HIGH
subb a,r4 ; Calc LOW ( Old - New )
mov DPL,a
mov a,@r0
subb a,r3 ; Calc HIGH ( Old - New )
anl a,#00111111b ; Kill state select flags
jz ValueOk ; Skip if timer < 256
dec a ; don't want it to have a jump at the crossover point
cjne a,#8,$+3 ; If timer high > 8, set min velocity
jc LongVel ; [c] set if < 8
mov a,#7 ; Set Min velocity value.
mov DPL,#255
LongVel: rr a ; Divide by 8, shift into top bits.
rr a
rr a
mov B,a
mov a,DPL
anl a,#11111000b
rr a ; Divide by 8, shift into bottom bits.
rr a
rr a
orl a,B
mov DPL,a
mov DPH,#HIGH (CounterToVelocity+256) ; Read from second half of the table
; Handles timer values < 256
ValueOk: mov @r0,#StateC ; Put into StateC
mov a,VelCurve
rl a ; Curve x 2, cos of 512 byte tabs
add a,DPH
mov DPH,a
mov a,#0
movc a,@a+dptr
; mov a,VelCurve ;##### DEBUG - Output vel curve num + 1
; add a,#VEL_CURVE_0 ;Add in initial vel curve number
; anl a,07Fh
TX
ret
;##### DEBUG code to output timer high as velocity
; mov b,DPL ; Output result high to see how big counter can get
; mov c,b.7
; rlc a
; inc a ; Start counting from 1
; TX
; ret
; Table to select rows on the key scan ports
RowSelectTab:
dw 1111111111111101b ;P1.1
dw 1111111111111110b ;P1.0
dw 1111111111110111b ;P1.3
dw 1111111111111011b ;P1.2
dw 1111111111011111b ;P1.5
dw 1111111111101111b ;P1.4
dw 1111111101111111b ;P1.7
dw 1111111110111111b ;P1.6
dw 1101111111111111b ;P3.5
dw 1110111111111111b ;P3.4
dw 0111111111111111b ;P3.7
dw 1011111111111111b ;P3.6
dw 0FFFFh ;On last key read, it'll select this row as the next one.
;***** Include Velocity tables
CSEG AT 0C00h ;Allows room for upto 10 curves with 512 byte tabs
CounterToVelocity:
;$include (VelTab88.inc)
VEL_E:
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -