📄 key_scan.asl
字号:
+ 1 ;****************************************************************;
+ 2 ; Key Scan Function
+ 3 ;
+ 4 ; Key input pin: PRTD[7]
+ 5 ; Include two part: scan key when power on;
+ 6 ; scan key in the course of movement
+ 7 ; Written by: lixy
+ 8 ; Date: 2004-02-16
+ 9 ;****************************************************************;
+ 10
+ 11 ;================================================================;
+ 12 ;Constant Area
+ 13 ;================================================================;
0001 14 c_prtd0_1 equ #00000001b
00FE 15 c_prtd0_0 equ #11111110b
0000 16 c_offset_f_ini equ #0
0008 17 c_rnd_range_f_ini equ #8
00E8 18 c_offset_stop equ #232 ;=29(row)*8(colunm)
0000 19 c_rnd_range_stop equ #0
000C 20 c_dly_dbc_h equ #0ch ;key pressed debounce delay constant
+ 21
+ 22
+ 23 ;================================================================;
+ 24 ;Data Area
+ 25 ;================================================================;
+B 00 01
+ 26 .area key_scan_var(data)
+ 27
+ 28 ;flg_key_pressed_1st:: .ds 1 ;the flag of key pressed for the first time
+ 29 ;flg_key_ok:: .ds 1 ;the flag of key pressed and released the first times when power on
+ 30 ;flg_key_scan:: .ds 1
+ 31 ;flg_key_pressed:: .ds 1 ;the flag of key pressed
0000 32 temp_dly_dbc:: .ds 2 ;key press debounce delay time variable
0002 33 flg_nose_pressed:: .ds 1 ;if it be set,not decrease 50 point untill release the nose key
0003 34 flg_touched_key:: .ds 1 ;0:this key isn't pressed
+ 35 ;1:the key is pressed with broadcast ir received,motor will stop,wait for touched ir sign
+ 36 ;2:touched if sign isn't received within 4s,will decrease 50point,then be clear
+ 37 ;================================================================;
+ 38 ;Code Area
+ 39 ;================================================================;
+B 00 02
+ 40 .area scan_key_code(code)
+ 41 ;----------------------------------------------------------------;
+ 42 ; Key Scan (for starting when power on)
+ 43 ;----------------------------------------------------------------;
0000 44 scan_key_start::
0000 29 45 clrwdt
0001 20 00 00 46 call lcd_display ;initial value is set in initial part of main program
+ 47 ;--------------/*04-02-17*/-----------------------;
+ 48 ;random number initial value counter keep counting,
+ 49 ;until key is pressed and released when powered on.
0004 F1 00 50 lda cnt_rnd_num_ini
0006 1F 51 inca
0007 FD 00 52 sta cnt_rnd_num_ini
0009 F1 01 53 lda cnt_rnd_num_ini+1
000B 9B 00 54 addc #00h
000D FD 01 55 sta cnt_rnd_num_ini+1
+ 56 ;-------------------------------------------------;
000F F3 FF 57 lda #0ffh ;stop motor and set prtd0,1,2 7 to input pin
0011 FC 32 58 sta r_prtd
0013 00 59 nop
0014 00 60 nop
0015 F0 32 61 lda r_prtd
0017 CB 01 62 anda #c_prtd0_1 ;if nose key is pressed,z=0
0019 07 00 00 63 brnz scan_key_start
001C F3 FF 64 lda #0ffh
001E FC 32 65 sta r_prtd
0020 20 01 04 66 call debounce ;key pressed debouncing
0023 F0 32 67 lda r_prtd
0025 CB 01 68 anda #c_prtd0_1
0027 07 00 00 69 brnz scan_key_start ;key invalid,re-scan
002A 70 waitkey_release:
002A 29 71 clrwdt
002B F0 32 72 lda r_prtd
002D DB 07 73 ora #00000111b ;d0 is nose,d1 is trap,d2 is stall
002F FC 32 74 sta r_prtd
0031 00 75 nop
0032 00 76 nop
0033 F0 32 77 lda r_prtd ;key valid,wait for key release
0035 CB 01 78 anda #c_prtd0_1
0037 06 00 2A 79 brz waitkey_release
003A 20 01 04 80 call debounce
003D F0 32 81 lda r_prtd
003F DB 07 82 ora #00000111b ;d0 is nose,d1 is trap,d2 is stall
0041 FC 32 83 sta r_prtd
0043 00 84 nop
0044 00 85 nop
0045 F0 32 86 lda r_prtd
0047 CB 01 87 anda #c_prtd0_1
0049 06 00 2A 88 brz waitkey_release
004C F1 01 89 lda cnt_rnd_num_ini+1 ;load random initial value(high 8bit)装载随机数的初值
004E FD 01 90 sta rnd_num_16+1
0050 F1 00 91 lda cnt_rnd_num_ini ;load random initial value(low 8bit)
0052 FD 00 92 sta rnd_num_16
0054 20 00 00 93 call generate_random
0057 F3 00 94 lda #0
0059 FD 00 95 sta cnt_point_free
+ 96 ; sta flg_rcv_barrier ;clear receive barrier flag
005B F3 01 97 lda #1
005D FD 00 98 sta flg_new_random ;need generate new random(turn left,turn right,go ahead)
005F 20 00 00 99 call select_sound_normal
0062 24 100 ret
+ 101 ;----------------------------------------------------------------;
+ 102 ; Key Scan (for stopping in the course of the movement)
+ 103 ;----------------------------------------------------------------;
0063 104 scan_key::
0063 F1 03 105 lda flg_touched_key
0065 A7 02 106 cmpe #2 ;4s after touched key,touched ir sign isn't received,the flg is 2
0067 06 00 C1 107 brz decrease_50point ;shall decrease 50 points(nose key)
006A F0 32 108 lda r_prtd
006C DB 87 109 ora #10000111b ;d0 is nose,d1 is trap,d2 is stall
006E FC 32 110 sta r_prtd
0070 00 111 nop
0071 00 112 nop
0072 00 113 nop
0073 F0 32 114 lda r_prtd
0075 CB 07 115 anda #00000111b
0077 A7 07 116 cmpe #00000111b
0079 07 00 81 117 brnz if_key_pressed
007C F3 00 118 lda #0
007E FD 02 119 sta flg_nose_pressed ;clear the nose key pressed flag
0080 24 120 ret ;no any key is pressed
0081 121 if_key_pressed:
0081 20 01 04 122 call debounce
0084 F0 32 123 lda r_prtd
0086 DB 87 124 ora #10000111b ;d0 is nose,d1 is trap,d2 is stall
0088 FC 32 125 sta r_prtd
008A 00 126 nop
008B 00 127 nop
008C F0 32 128 lda r_prtd
008E CB 07 129 anda #00000111b
0090 A7 04 130 cmpe #00000100b ;stall,Acc>0100b,c=1
0092 05 00 AE 131 brnc stall_motor
0095 CB 03 132 anda #00000011b
0097 A7 02 133 cmpe #00000010b ;trap
0099 05 00 A2 134 brnc entry_trap
009C CB 01 135 anda #00000001b
009E 06 00 B3 136 brz nose_pressed
00A1 24 137 ret
00A2 138 entry_trap:
00A2 F3 00 139 lda #0
00A4 FD 00 140 sta cnt_point
00A6 FD 01 141 sta cnt_point+1
00A8 20 00 00 142 call lcd_display
00AB 02 00 00 143 br mouse_fail
00AE 144 stall_motor:
00AE CB 02 145 anda #00000010b
00B0 06 00 A2 146 brz entry_trap
00B3 147 nose_pressed:
00B3 F1 00 148 lda flg_rcv_broadcast ;if broadcast sign is received,
00B5 A7 01 149 cmpe #1
00B7 06 00 FB 150 brz cheese_touched_key
00BA F1 02 151 lda flg_nose_pressed
00BC A7 01 152 cmpe #1
00BE 06 00 D7 153 brz if_nose_released
00C1 154 decrease_50point:
00C1 F3 00 155 lda #0
00C3 FD 03 156 sta flg_touched_key
00C5 F1 00 157 lda cnt_point
00C7 AB 32 158 suba #50 ;barrier
00C9 FD 00 159 sta cnt_point
00CB F1 01 160 lda cnt_point+1
00CD BB 00 161 subc #0
00CF FD 01 162 sta cnt_point+1 ;(cnt_point+1)cnt_point decrease 1,if the result>=0,c=1(Note)
00D1 05 00 A2 163 brnc entry_trap ;cy=0,cnt_point<0,die
00D4 20 00 00 164 call select_sound_barrier
00D7 165 if_nose_released:
00D7 F3 00 166 lda #0
00D9 FD 03 167 sta flg_touched_key
00DB 20 00 00 168 call lcd_display
00DE F0 32 169 lda r_prtd
00E0 DB 81 170 ora #10000001b ;d0 is nose,d1 is trap,d2 is stall
00E2 FC 32 171 sta r_prtd
00E4 00 172 nop
00E5 00 173 nop
00E6 F0 32 174 lda r_prtd ;judge if release the nose key
00E8 CB 01 175 anda #00000001b ;if =0(z=1),nose released,clear flg_nose_pressed
00EA 07 00 F1 176 brnz nose_released
00ED F3 01 177 lda #1 ;nose key isn't released
00EF FD 02 178 sta flg_nose_pressed
00F1 179 nose_released:
00F1 F3 01 180 lda #1
00F3 FD 00 181 sta flg_rcv_barrier
00F5 FD 00 182 sta flg_last_barrier ;there is barrier at the front,
00F7 20 00 00 183 call Run_backup
00FA 24 184 ret
+ 185
00FB 186 cheese_touched_key: ;wait for cheese touched ir sign
00FB F3 01 187 lda #1
00FD FD 03 188 sta flg_touched_key ;note:key value =2,is the key is wrong regarded as the wrong key.
+ 189 ;it shall receive the touched ir sign,if not,it is wrong.
00FF F3 FF 190 lda #11111111b ;motor will stop(r_prtd3,4,5,6, other port are input)
0101 FC 32 191 sta r_prtd
0103 24 192 ret
+ 193 ;----------------------------------------------------------------;
+ 194 ;Debounce Subroutine
+ 195 ;----------------------------------------------------------------;
0104 196 debounce:: ;key pressed debounce time = 18*256*(#cnst_dly_dbc_h)*1.5/4M = 20.16ms
0104 F3 00 197 lda #00h
0106 FD 00 198 sta temp_dly_dbc
0108 FD 01 199 sta temp_dly_dbc+1
010A 200 delay_debounce:
+ 201 ; clrwdt
010A 8B 00 202 adda #00h ;clear c
010C F1 00 203 lda temp_dly_dbc
010E 1F 204 inca
010F FD 00 205 sta temp_dly_dbc
0111 F3 00 206 lda #00h
0113 99 01 207 addc temp_dly_dbc+1
0115 FD 01 208 sta temp_dly_dbc+1
0117 A7 0C 209 cmpe #c_dly_dbc_h
0119 07 01 0A 210 brnz delay_debounce
011C 211 debounce_end:
011C 24 212 ret
+ 213
+
+Symbol Table
+
+ Run_backup **** GX
+ c_dly_dbc_h = 000C
+ c_offset_f_ini = 0000
+ c_offset_stop = 00E8
+ c_prtd0_0 = 00FE
+ c_prtd0_1 = 0001
+ c_rnd_range_f_ini = 0008
+ c_rnd_range_stop = 0000
+ 2 cheese_touched_key 00FB R
+ cnt_point **** GX
+ cnt_point_free **** GX
+ cnt_rnd_num_ini **** GX
+ 2 debounce 0104 GR
+ 2 debounce_end 011C R
+ 2 decrease_50point 00C1 R
+ 2 delay_debounce 010A R
+ 2 entry_trap 00A2 R
+ flg_last_barrier **** GX
+ flg_new_random **** GX
+ 1 flg_nose_pressed 0002 GR
+ flg_rcv_barrier **** GX
+ flg_rcv_broadcast **** GX
+ 1 flg_touched_key 0003 GR
+ generate_random **** GX
+ 2 if_key_pressed 0081 R
+ 2 if_nose_released 00D7 R
+ lcd_display **** GX
+ mouse_fail **** GX
+ 2 nose_pressed 00B3 R
+ 2 nose_released 00F1 R
+ rnd_num_16 **** GX
+ 2 scan_key 0063 GR
+ 2 scan_key_start 0000 GR
+ select_sound_barrier **** GX
+ select_sound_normal **** GX
+ 2 stall_motor 00AE R
+ 1 temp_dly_dbc 0000 GR
+ 2 waitkey_release 002A R
+
+
+Area Table
+
+ 0 . size 0 flags 0
+ 1 key_scan_var size 4 flags 2
+ 2 scan_key_code size 11D flags 1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -