📄 lookup_table.asl
字号:
+ 1 ;****************************************************************;
+ 2 ; Run
+ 3 ;
+ 4 ; Function: decide the next status of Mouse's movement
+ 5 ;
+ 6 ; Motor 1 driver circuit controlled by the input1,input2.
+ 7 ; Motor 2 driver circuit controlled by the input3,input4.
+ 8 ; Motor1: input1-----PRTD.3 Motor2: input3-----PRTD.5
+ 9 ; input2-----PRTD.4 input4-----PRTD.6
+ 10
+ 11 ; Written by: Mr.ZhangJinBo
+ 12 ; Date: 2004-02-16
+ 13 ;****************************************************************;
+ 14 ;================================================================;
+ 15 ;Constant Area
+ 16 ;================================================================;
0008 17 c_mtr_tab_col equ #8 ;the total column number of the table
+ 18 ;R_IER: bit4:TB, bit3:INT1, bit2:T1, bit1:T2, bit0:INT2
001B 19 c_ier_dis_t1 equ #11011b ;disable timer1
0004 20 c_ier_en_t1 equ #00100b ;enable timer1
+ 21 ;================================================================;
+ 22 ;Data Area
+ 23 ;================================================================;
+B 00 01
+ 24 .area run_var(data)
+ 25
0000 26 m_offset_ini:: .ds 1
+ 27 ;//04-03-17// add the high 8bit of the initial offset register
0001 28 m_offset_ini_h:: .ds 1
+ 29 ;end add //04-03-17//
0002 30 m_offset:: .ds 1 ;m_offset_ini的备份值(暂时寄存器)
+ 31 ;//04-03-17// add the high 8bit of the offset register
0003 32 m_offset_h:: .ds 1 ;;m_offset_ini_h的备份值(暂时寄存器)
+ 33 ;end add //04-03-17//
+ 34
0004 35 temp_table_l:: .ds 1 ;/*04-02-20*/查表低位暂存器(临时寄存器)
0005 36 temp_table_h:: .ds 1 ;/*04-02-20*/查表高位暂存器(临时寄存器)
+ 37
0006 38 flg_motor_status:: .ds 1 ;1: flg_line(直线向前运动标志);
+ 39 ;2: flg_left(左转标志);
+ 40 ;3: flg_right(右转标志);
+ 41 ;4: flg_stop(停止标志);
+ 42
+ 43 ;m_prtd_ctrl_1_0:: .ds 1 ;/*04-02-20*/
0007 44 m_prtd_ctrl_1_1:: .ds 1 ;/*04-02-20*/
0008 45 m_prtd_ctrl_2_0:: .ds 1 ;/*04-02-20*/
0009 46 m_prtd_ctrl_2_1:: .ds 1 ;/*04-02-20*/
000A 47 m_ctrl_t1:: .ds 1
000B 48 m_ctrl_t2:: .ds 1
000C 49 m_ctrl_pulse:: .ds 2 ;/*04-02-17*/
+ 50
+ 51 ;================================================================;
+ 52 ;Code Area
+ 53 ;================================================================;
+B 00 02
+ 54 .area Lookup_code(code)
+ 55
0000 56 Lookup::
0000 F1 00 57 lda m_offset_ini ;把起始的表的初值送到暂存器
0002 FD 02 58 sta m_offset ;add the high 8bit of the offset register
0004 F1 01 59 lda m_offset_ini_h
0006 FD 03 60 sta m_offset_h
0008 F1 00 61 lda rnd_num ;rnd_num为所求得的随机数
000A A7 00 62 cmpe #0
000C 06 00 23 63 brz lookup_mtr_table
000F 64 get_offset_mtr:
000F F1 02 65 lda m_offset
0011 8B 08 66 adda #c_mtr_tab_col
0013 FD 02 67 sta m_offset ;//add the high 8bit of the offset register
0015 F1 03 68 lda m_offset_h
0017 9B 00 69 addc #0
0019 FD 03 70 sta m_offset_h
001B F1 00 71 lda rnd_num ;求表格开始值
001D 3F 72 deca
001E FD 00 73 sta rnd_num
0020 07 00 0F 74 brnz get_offset_mtr
+ 75
+ 76 ;-------------------------------------------------------------------;
+ 77 ;disable timer1 to prevent from taking wrong data out of the table,
+ 78 ;because playing sound in timer1 interrupt service routine need look
+ 79 ;up table (sound file) too.
+ 80 ;-------------------------------------------------------------------;
+ 81
0023 82 lookup_mtr_table:
+ 83
0023 F0 04 84 lda r_ier ;/*04-02-23*/ ;disable timer1
0025 CB 1B 85 anda #c_ier_dis_t1
0027 FC 04 86 sta r_ier
+ 87
0029 F3 5A 88 lda #<motor_table ;refer to the table
002B 89 02 89 adda m_offset
002D FD 04 90 sta temp_table_l
002F F3 00 91 lda #>motor_table
0031 99 03 92 addc m_offset_h
0033 FD 05 93 sta temp_table_h
+ 94 ;lda #^motor_table ;not use, if ROM size is not larger than 64K.
+ 95 ;addc #0
+ 96 ;sta r_tpp
+ 97 ;lda temp_table_h
0035 FC 02 98 sta r_tph
0037 F1 04 99 lda temp_table_l
0039 FC 01 100 sta r_tpl
+ 101 ; call read_table ;no need delay,if rom size is smaller than 64k
003B F8 102 ldv
003C FD 06 103 sta flg_motor_status ;set variable 1电机的方向
+ 104 ; call read_table
003E F8 105 ldv
003F FD 07 106 sta m_prtd_ctrl_1_1 ;set variable 2 ;/*04-02-19*/改变口的所需状态
+ 107 ; call read_table
0041 F8 108 ldv
0042 FD 08 109 sta m_prtd_ctrl_2_0 ;set variable 3 ;/*04-02-19*/
+ 110 ; call read_table
0044 F8 111 ldv
0045 FD 09 112 sta m_prtd_ctrl_2_1 ;set variable 4 ;/*04-02-19*/
+ 113 ; call read_table
0047 F8 114 ldv
0048 FD 0A 115 sta m_ctrl_t1 ;set variable 5,low timer
+ 116 ; call read_table
004A F8 117 ldv
004B FD 0B 118 sta m_ctrl_t2 ;set variable 6,total timer(low + high)
+ 119 ; call read_table
004D F8 120 ldv
004E FD 0C 121 sta m_ctrl_pulse ;set variable 7频率的个数1(行进的时间)
+ 122 ; call read_table
0050 F8 123 ldv
0051 FD 0D 124 sta m_ctrl_pulse+1 ;set variable 8频率的个树2(行进的时间)
+ 125
0053 F0 04 126 lda r_ier ;/*04-02-23*/ ;enable timer1
0055 DB 04 127 ora #c_ier_en_t1
0057 FC 04 128 sta r_ier
+ 129
0059 130 end_run:
0059 24 131 ret
+ 132
+ 133 ;-----------------------------------------------;
+ 134 ;read_table::
+ 135 ;1$:
+ 136 ; lda r_op1
+ 137 ; anda #10000000b
+ 138 ; brz 1$
+ 139 ;; ldv
+ 140 ; ret
+ 141
+ 142 ;-----------------------------------------------;
+ 143 ;the following constant is used in the table
+ 144 ;-----------------------------------------------;
+ 145
00FF 146 c_prtd_1 equ #11111111b ;prtd[0,1,2,3,4,5,6,7] all hihg level
0078 147 c_prtd3456_1 equ #01111000b ;prtd.3,prtd.4,prtd.5,prtd.6 high level
+ 148
00D7 149 c_prtd35_0 equ #11010111b ;prtd.3,prtd.5 low level (0d7h)
0050 150 c_prtd46_1 equ #01010000b ;prtd.4,prtd.6 high level (050h)
+ 151
0028 152 c_prtd35_1 equ #00101000b ;prtd.3,prtd.5 high level (028h)
00AF 153 c_prtd46_0 equ #10101111b ;prtd.4,prtd.6 low level (0afh)
+ 154
0048 155 c_prtd36_1 equ #01001000b ;prtd.3,prtd.6 high level (048h)
00CF 156 c_prtd45_0 equ #11001111b ;prtd.4,prtd.5 low level (0cfh)
+ 157
00B7 158 c_prtd36_0 equ #10110111b ;prtd.3,prtd.6 low level (0b7h)
0030 159 c_prtd45_1 equ #00110000b ;prtd.4,prtd.5 high level (030h)
+ 160
+ 161
0000 162 c_flg_left equ #0
0001 163 c_flg_right equ #1
0002 164 c_flg_backup equ #2
0003 165 c_flg_line equ #3
0004 166 c_flg_stop equ #4
+ 167
0010 168 c_ctrl_t2 equ #16 ;this can decide the control pulse frequency.(8K/16=500Hz)
0011 169 c_ctrl_fast_t1 equ #17
000D 170 c_ctrl_med_t1 equ #13
000A 171 c_ctrl_slow_t1 equ #10
000E 172 c_ctrl_swerve_t1 equ #14 ;/*04-03-05*/ the old value is 14
+ 173 ;//04-03-17// add the constant for swerve when detect obstacles
000E 174 c_ctrl_swerve_t1_ir equ #14
+ 175 ;end add //04-03-17//
0011 176 c_ctrl_stop_t1 equ #17
+ 177
+ 178 ;c_fast_1_pls_l equ #0f4h ;1s
+ 179 ;c_fast_1_pls_h equ #01h
+ 180 ;c_fast_2_pls_l equ #0e8h ;2s
+ 181 ;c_fast_2_pls_h equ #03h
+ 182 ;c_fast_3_pls_l equ #0dch ;3s
+ 183 ;c_fast_3_pls_h equ #05h
+ 184 ;c_med_1_pls_l equ #0f4h ;1s
+ 185 ;c_med_1_pls_h equ #01h
+ 186 ;c_med_2_pls_l equ #0e8h ;2s
+ 187 ;c_med_2_pls_h equ #03h
+ 188 ;c_med_3_pls_l equ #0dch ;3s
+ 189 ;c_med_3_pls_h equ #05h
+ 190 ;c_slow_1_pls_l equ #0f4h ;1s
+ 191 ;c_slow_1_pls_h equ #01h
+ 192 ;c_slow_2_pls_l equ #0e8h ;2s
+ 193 ;c_slow_2_pls_h equ #03h
+ 194 ;c_slow_3_pls_l equ #0dch ;3s
+ 195 ;c_slow_3_pls_h equ #05h
+ 196
00F4 197 c_fast_1_pls_l equ #0f4h ;1s
0000 198 c_fast_1_pls_h equ #00h
00E8 199 c_fast_2_pls_l equ #0e8h ;2s
0002 200 c_fast_2_pls_h equ #02h
00DC 201 c_fast_3_pls_l equ #0dch ;3s
0003 202 c_fast_3_pls_h equ #03h
00F4 203 c_med_1_pls_l equ #0f4h ;1s
0000 204 c_med_1_pls_h equ #00h
00E8 205 c_med_2_pls_l equ #0e8h ;2s
0002 206 c_med_2_pls_h equ #02h
00DC 207 c_med_3_pls_l equ #0dch ;3s
0003 208 c_med_3_pls_h equ #03h
00F4 209 c_slow_1_pls_l equ #0f4h ;1s
0000 210 c_slow_1_pls_h equ #00h
00E8 211 c_slow_2_pls_l equ #0e8h ;2s
0002 212 c_slow_2_pls_h equ #02h
00DC 213 c_slow_3_pls_l equ #0dch ;3s
0003 214 c_slow_3_pls_h equ #03h
+ 215
00A0 216 c_20_pls_l equ #0a0h ;=160, 0.32s
0000 217 c_20_pls_h equ #00h
00C3 218 c_40_pls_l equ #0c3h ;=195, 0.39s
0000 219 c_40_pls_h equ #00h
00E6 220 c_60_pls_l equ #0e6h ;=230, 0.46s
0000 221 c_60_pls_h equ #00h
0009 222 c_80_pls_l equ #09h ;=265, 0.53s
0001 223 c_80_pls_h equ #01h
002C 224 c_100_pls_l equ #02ch ;=300, 0.60s
0001 225 c_100_pls_h equ #01h
004F 226 c_120_pls_l equ #04fh ;=335, 0.67s
0001 227 c_120_pls_h equ #01h
0072 228 c_140_pls_l equ #072h ;=370, 0.74s
0001 229 c_140_pls_h equ #01h
0095 230 c_160_pls_l equ #095h ;=405, 0.81s
0001 231 c_160_pls_h equ #01h
00B8 232 c_180_pls_l equ #0b8h ;=440, 0.88s
0001 233 c_180_pls_h equ #01h
+ 234
+ 235 ;//04-03-17// add the constant used in the swerving movement when detect obstacles
000A 236 c_20_pls_l_ir equ #0ah ;=10, 0.02s
0000 237 c_20_pls_h_ir equ #00h
0014 238 c_40_pls_l_ir equ #014h ;=20, 0.04s
0000 239 c_40_pls_h_ir equ #00h
001E 240 c_60_pls_l_ir equ #01eh ;=30, 0.06s
0000 241 c_60_pls_h_ir equ #00h
0028 242 c_80_pls_l_ir equ #028h ;=40, 0.08s
0000 243 c_80_pls_h_ir equ #00h
0032 244 c_100_pls_l_ir equ #032h ;=50, 0.1s
0000 245 c_100_pls_h_ir equ #00h
003C 246 c_120_pls_l_ir equ #03ch ;=60, 0.12s
0000 247 c_120_pls_h_ir equ #00h
0046 248 c_140_pls_l_ir equ #046h ;=70, 0.14s
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -