⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lookup_table.asm

📁 一款智能老鼠的玩具源代码
💻 ASM
字号:
;****************************************************************;
; Run
;
; Function: decide the next status of Mouse's movement
;
; Motor 1 driver circuit controlled by the input1,input2.
; Motor 2 driver circuit controlled by the input3,input4.
; Motor1: input1-----PRTD.3    Motor2: input3-----PRTD.5
;         input2-----PRTD.4            input4-----PRTD.6

; Written by: Mr.ZhangJinBo
; Date: 2004-02-16
;****************************************************************;
;================================================================;
;Constant Area
;================================================================;
c_mtr_tab_col		equ	#8		;the total column number of the table
;R_IER: bit4:TB, bit3:INT1, bit2:T1, bit1:T2, bit0:INT2
c_ier_dis_t1		equ	#11011b		;disable timer1
c_ier_en_t1		equ	#00100b		;enable timer1
;================================================================;
;Data Area
;================================================================;
       .area       run_var(data)

m_offset_ini::		.ds	1
;//04-03-17// add the high 8bit of the initial offset register
m_offset_ini_h::	.ds	1
;end add //04-03-17//
m_offset::		.ds	1	;m_offset_ini的备份值(暂时寄存器)
;//04-03-17// add the high 8bit of the offset register
m_offset_h::		.ds	1	;;m_offset_ini_h的备份值(暂时寄存器)
;end add //04-03-17//

temp_table_l::		.ds	1	;/*04-02-20*/查表低位暂存器(临时寄存器)
temp_table_h::		.ds	1	;/*04-02-20*/查表高位暂存器(临时寄存器)

flg_motor_status::	.ds	1	;1: flg_line(直线向前运动标志);
					;2: flg_left(左转标志);
					;3: flg_right(右转标志);
					;4: flg_stop(停止标志);
					
;m_prtd_ctrl_1_0::	.ds	1	;/*04-02-20*/
m_prtd_ctrl_1_1::	.ds	1	;/*04-02-20*/
m_prtd_ctrl_2_0::	.ds	1	;/*04-02-20*/
m_prtd_ctrl_2_1::	.ds	1	;/*04-02-20*/
m_ctrl_t1::		.ds	1
m_ctrl_t2::		.ds	1
m_ctrl_pulse::		.ds	2	;/*04-02-17*/

;================================================================;
;Code Area
;================================================================;
       .area       Lookup_code(code)

Lookup::
	lda	m_offset_ini		;把起始的表的初值送到暂存器
	sta	m_offset		;add the high 8bit of the offset register
	lda	m_offset_ini_h
	sta	m_offset_h
	lda	rnd_num			;rnd_num为所求得的随机数
	cmpe	#0
	brz	lookup_mtr_table
get_offset_mtr:	
	lda	m_offset
	adda	#c_mtr_tab_col
	sta	m_offset		;//add the high 8bit of the offset register
	lda	m_offset_h
	addc	#0
	sta	m_offset_h
	lda	rnd_num			;求表格开始值
	deca
	sta	rnd_num
	brnz	get_offset_mtr
	
;-------------------------------------------------------------------;
;disable timer1 to prevent from taking wrong data out of the table,
;because playing sound in timer1 interrupt service routine need look
;up table (sound file) too.
;-------------------------------------------------------------------;	

lookup_mtr_table:

	lda	r_ier		;/*04-02-23*/ ;disable timer1
	anda	#c_ier_dis_t1
	sta	r_ier
	
	lda	#<motor_table		;refer to the table
	adda	m_offset
	sta	temp_table_l
	lda	#>motor_table
	addc	m_offset_h
	sta	temp_table_h
	;lda	#^motor_table		;not use, if ROM size is not larger than 64K.
	;addc	#0
	;sta	r_tpp
	;lda	temp_table_h
	sta	r_tph
	lda	temp_table_l
	sta	r_tpl
;	call	read_table           	;no need delay,if rom size is smaller than 64k
	ldv
	sta	flg_motor_status	;set variable 1电机的方向
;	call	read_table
	ldv
	sta	m_prtd_ctrl_1_1		;set variable 2	;/*04-02-19*/改变口的所需状态
;	call	read_table
	ldv
	sta	m_prtd_ctrl_2_0		;set variable 3	;/*04-02-19*/
;	call	read_table
	ldv
	sta	m_prtd_ctrl_2_1		;set variable 4	;/*04-02-19*/
;	call	read_table
	ldv
	sta	m_ctrl_t1		;set variable 5,low timer
;	call	read_table
	ldv
	sta	m_ctrl_t2		;set variable 6,total timer(low + high)
;	call	read_table
	ldv
	sta	m_ctrl_pulse		;set variable 7频率的个数1(行进的时间)
;	call	read_table
	ldv
	sta	m_ctrl_pulse+1		;set variable 8频率的个树2(行进的时间)

	lda	r_ier		;/*04-02-23*/ ;enable timer1
	ora	#c_ier_en_t1
	sta	r_ier

end_run:
	ret

;-----------------------------------------------;
;read_table::
;1$:
;	lda	r_op1
;	anda	#10000000b
;	brz	1$
;;	ldv
;	ret

;-----------------------------------------------;	
;the following constant is used in the table
;-----------------------------------------------;

c_prtd_1		equ	#11111111b	;prtd[0,1,2,3,4,5,6,7] all hihg level
c_prtd3456_1		equ	#01111000b	;prtd.3,prtd.4,prtd.5,prtd.6 high level

c_prtd35_0		equ	#11010111b	;prtd.3,prtd.5 low level (0d7h)
c_prtd46_1		equ	#01010000b	;prtd.4,prtd.6 high level (050h)

c_prtd35_1		equ	#00101000b	;prtd.3,prtd.5 high level (028h)
c_prtd46_0		equ 	#10101111b	;prtd.4,prtd.6 low level (0afh)

c_prtd36_1		equ	#01001000b	;prtd.3,prtd.6 high level (048h)
c_prtd45_0		equ	#11001111b	;prtd.4,prtd.5 low level (0cfh)

c_prtd36_0		equ	#10110111b	;prtd.3,prtd.6 low level (0b7h)
c_prtd45_1		equ	#00110000b	;prtd.4,prtd.5 high level (030h)


c_flg_left		equ	#0
c_flg_right		equ	#1
c_flg_backup		equ	#2
c_flg_line		equ	#3
c_flg_stop		equ	#4

c_ctrl_t2		equ	#16		;this can decide the control pulse frequency.(8K/16=500Hz)
c_ctrl_fast_t1		equ	#17
c_ctrl_med_t1		equ	#13
c_ctrl_slow_t1		equ	#10
c_ctrl_swerve_t1	equ	#14		;/*04-03-05*/ the old value is 14 
;//04-03-17// add the constant for swerve when detect obstacles
c_ctrl_swerve_t1_ir	equ	#14
;end add //04-03-17//
c_ctrl_stop_t1		equ	#17

;c_fast_1_pls_l		equ	#0f4h		;1s
;c_fast_1_pls_h		equ	#01h
;c_fast_2_pls_l		equ	#0e8h		;2s
;c_fast_2_pls_h		equ	#03h
;c_fast_3_pls_l		equ	#0dch		;3s
;c_fast_3_pls_h		equ	#05h
;c_med_1_pls_l		equ	#0f4h		;1s
;c_med_1_pls_h		equ	#01h
;c_med_2_pls_l		equ	#0e8h		;2s
;c_med_2_pls_h		equ	#03h
;c_med_3_pls_l		equ	#0dch		;3s
;c_med_3_pls_h		equ	#05h
;c_slow_1_pls_l		equ	#0f4h		;1s
;c_slow_1_pls_h		equ	#01h
;c_slow_2_pls_l		equ	#0e8h		;2s
;c_slow_2_pls_h		equ	#03h
;c_slow_3_pls_l		equ	#0dch		;3s
;c_slow_3_pls_h		equ	#05h

c_fast_1_pls_l		equ	#0f4h		;1s
c_fast_1_pls_h		equ	#00h
c_fast_2_pls_l		equ	#0e8h		;2s
c_fast_2_pls_h		equ	#02h
c_fast_3_pls_l		equ	#0dch		;3s
c_fast_3_pls_h		equ	#03h
c_med_1_pls_l		equ	#0f4h		;1s
c_med_1_pls_h		equ	#00h
c_med_2_pls_l		equ	#0e8h		;2s
c_med_2_pls_h		equ	#02h
c_med_3_pls_l		equ	#0dch		;3s
c_med_3_pls_h		equ	#03h
c_slow_1_pls_l		equ	#0f4h		;1s
c_slow_1_pls_h		equ	#00h
c_slow_2_pls_l		equ	#0e8h		;2s
c_slow_2_pls_h		equ	#02h
c_slow_3_pls_l		equ	#0dch		;3s
c_slow_3_pls_h		equ	#03h

c_20_pls_l		equ	#0a0h		;=160, 0.32s
c_20_pls_h		equ	#00h
c_40_pls_l		equ	#0c3h		;=195, 0.39s
c_40_pls_h		equ	#00h
c_60_pls_l		equ	#0e6h		;=230, 0.46s
c_60_pls_h		equ	#00h
c_80_pls_l		equ	#09h		;=265, 0.53s
c_80_pls_h		equ	#01h
c_100_pls_l		equ	#02ch		;=300, 0.60s
c_100_pls_h		equ	#01h
c_120_pls_l		equ	#04fh		;=335, 0.67s
c_120_pls_h		equ	#01h
c_140_pls_l		equ	#072h		;=370, 0.74s
c_140_pls_h		equ	#01h
c_160_pls_l		equ	#095h		;=405, 0.81s
c_160_pls_h		equ	#01h
c_180_pls_l		equ	#0b8h		;=440, 0.88s
c_180_pls_h		equ	#01h
	
;//04-03-17// add the constant used in the swerving movement when detect obstacles
c_20_pls_l_ir		equ	#0ah		;=10, 0.02s
c_20_pls_h_ir		equ	#00h
c_40_pls_l_ir		equ	#014h		;=20, 0.04s
c_40_pls_h_ir		equ	#00h
c_60_pls_l_ir		equ	#01eh		;=30, 0.06s
c_60_pls_h_ir		equ	#00h
c_80_pls_l_ir		equ	#028h		;=40, 0.08s
c_80_pls_h_ir		equ	#00h
c_100_pls_l_ir		equ	#032h		;=50, 0.1s
c_100_pls_h_ir		equ	#00h
c_120_pls_l_ir		equ	#03ch		;=60, 0.12s
c_120_pls_h_ir		equ	#00h
c_140_pls_l_ir		equ	#046h		;=70, 0.14s
c_140_pls_h_ir		equ	#00h
c_160_pls_l_ir		equ	#050h		;=80, 0.16s
c_160_pls_h_ir		equ	#00h
c_180_pls_l_ir		equ	#05ah		;=90, 0.18s
c_180_pls_h_ir		equ	#00h
;end add //04-03-17//	

c_pause_1_pls_l		equ	#0dch		;pause time is about 3s.
c_pause_1_pls_h		equ	#05h
c_pause_2_pls_l		equ	#0c4h		;pause time is about 5s.
c_pause_2_pls_h		equ	#09h
c_pause_3_pls_l		equ	#0ach		;pause time is about 7s.
c_pause_3_pls_h		equ	#0dh

c_stop_pls_l		equ	#088h		;stop time is about 10s.
c_stop_pls_h		equ	#013h

;-----------------------------------------------;

motor_table::

;flg_motor_status, m_prtd_ctrl_1_1, m_prtd_ctrl_2_0, m_prtd_ctrl_2_1, m_ctrl_t1,m_ctrl_t2, m_ctrl_pulse, m_ctrl_pulse+1
 db	c_flg_line, c_prtd3456_1, c_prtd35_0, c_prtd46_1, c_ctrl_med_t1, c_ctrl_t2, c_med_1_pls_l, c_med_1_pls_h	;0 前进,中速,短距离
 db	c_flg_line, c_prtd3456_1, c_prtd35_0, c_prtd46_1, c_ctrl_med_t1, c_ctrl_t2, c_med_2_pls_l, c_med_2_pls_h	;1 前进,中速,中距离
 db	c_flg_line, c_prtd3456_1, c_prtd35_0, c_prtd46_1, c_ctrl_med_t1, c_ctrl_t2, c_med_3_pls_l, c_med_3_pls_h	;2 前进,中速,长距离
 db	c_flg_line, c_prtd3456_1, c_prtd35_0, c_prtd46_1, c_ctrl_slow_t1, c_ctrl_t2, c_slow_1_pls_l, c_slow_1_pls_h	;3 前进,慢速,短距离
 db	c_flg_line, c_prtd3456_1, c_prtd35_0, c_prtd46_1, c_ctrl_slow_t1, c_ctrl_t2, c_slow_2_pls_l, c_slow_2_pls_h	;4 前进,慢速,中距离
 db	c_flg_line, c_prtd3456_1, c_prtd35_0, c_prtd46_1, c_ctrl_slow_t1, c_ctrl_t2, c_slow_3_pls_l, c_slow_3_pls_h	;5 前进,慢速,长距离(56-64)
 db	c_flg_line, c_prtd3456_1, c_prtd35_0, c_prtd46_1, c_ctrl_fast_t1, c_ctrl_t2, c_fast_1_pls_l, c_fast_1_pls_h	;6 前进,快速,短距离(-)
 db	c_flg_line, c_prtd3456_1, c_prtd35_0, c_prtd46_1, c_ctrl_fast_t1, c_ctrl_t2, c_fast_2_pls_l, c_fast_2_pls_h	;7 前进,快速,中距离
 db	c_flg_line, c_prtd3456_1, c_prtd35_0, c_prtd46_1, c_ctrl_fast_t1, c_ctrl_t2, c_fast_3_pls_l, c_fast_3_pls_h	;8 前进,快速,长距离

 db	c_flg_left, c_prtd3456_1, c_prtd45_0, c_prtd36_1, c_ctrl_swerve_t1, c_ctrl_t2, c_20_pls_l, c_20_pls_h		;9 左转,20度	   (-)
 db	c_flg_left, c_prtd3456_1, c_prtd45_0, c_prtd36_1, c_ctrl_swerve_t1, c_ctrl_t2, c_40_pls_l, c_40_pls_h		;10 左转,40度
 db	c_flg_left, c_prtd3456_1, c_prtd45_0, c_prtd36_1, c_ctrl_swerve_t1, c_ctrl_t2, c_60_pls_l, c_60_pls_h		;11 左转,60度
 db	c_flg_left, c_prtd3456_1, c_prtd45_0, c_prtd36_1, c_ctrl_swerve_t1, c_ctrl_t2, c_80_pls_l, c_80_pls_h		;12 左转,80度
 db	c_flg_left, c_prtd3456_1, c_prtd45_0, c_prtd36_1, c_ctrl_swerve_t1, c_ctrl_t2, c_100_pls_l, c_100_pls_h		;13 左转,100度
 db	c_flg_left, c_prtd3456_1, c_prtd45_0, c_prtd36_1, c_ctrl_swerve_t1, c_ctrl_t2, c_120_pls_l, c_120_pls_h		;14 左转,120度
 db	c_flg_left, c_prtd3456_1, c_prtd45_0, c_prtd36_1, c_ctrl_swerve_t1, c_ctrl_t2, c_140_pls_l, c_140_pls_h		;15 左转,140度
 db	c_flg_left, c_prtd3456_1, c_prtd45_0, c_prtd36_1, c_ctrl_swerve_t1, c_ctrl_t2, c_160_pls_l, c_160_pls_h		;16 左转,160度
 db	c_flg_left, c_prtd3456_1, c_prtd45_0, c_prtd36_1, c_ctrl_swerve_t1, c_ctrl_t2, c_180_pls_l, c_180_pls_h		;17 左转,180度	   (-)

 db	c_flg_right, c_prtd3456_1, c_prtd36_0, c_prtd45_1, c_ctrl_swerve_t1, c_ctrl_t2, c_20_pls_l, c_20_pls_h		;18 右转,20度	   (-)
 db	c_flg_right, c_prtd3456_1, c_prtd36_0, c_prtd45_1, c_ctrl_swerve_t1, c_ctrl_t2, c_40_pls_l, c_40_pls_h		;19 右转,40度
 db	c_flg_right, c_prtd3456_1, c_prtd36_0, c_prtd45_1, c_ctrl_swerve_t1, c_ctrl_t2, c_60_pls_l, c_60_pls_h		;20 右转,60度
 db	c_flg_right, c_prtd3456_1, c_prtd36_0, c_prtd45_1, c_ctrl_swerve_t1, c_ctrl_t2, c_80_pls_l, c_80_pls_h		;21 右转,80度
 db	c_flg_right, c_prtd3456_1, c_prtd36_0, c_prtd45_1, c_ctrl_swerve_t1, c_ctrl_t2, c_100_pls_l, c_100_pls_h	;22 右转,100度
 db	c_flg_right, c_prtd3456_1, c_prtd36_0, c_prtd45_1, c_ctrl_swerve_t1, c_ctrl_t2, c_120_pls_l, c_120_pls_h	;23 右转,120度
 db	c_flg_right, c_prtd3456_1, c_prtd36_0, c_prtd45_1, c_ctrl_swerve_t1, c_ctrl_t2, c_140_pls_l, c_140_pls_h	;24 右转,140度
 db	c_flg_right, c_prtd3456_1, c_prtd36_0, c_prtd45_1, c_ctrl_swerve_t1, c_ctrl_t2, c_160_pls_l, c_160_pls_h	;25 右转,160度
 db	c_flg_right, c_prtd3456_1, c_prtd36_0, c_prtd45_1, c_ctrl_swerve_t1, c_ctrl_t2, c_180_pls_l, c_180_pls_h	;26 右转,180度	    

 db	c_flg_stop, c_prtd3456_1, c_prtd_1, c_prtd3456_1, c_ctrl_stop_t1, c_ctrl_t2, c_pause_1_pls_l, c_pause_1_pls_h	;27 自动停止,时间3s (-)
 db	c_flg_stop, c_prtd3456_1, c_prtd_1, c_prtd3456_1, c_ctrl_stop_t1, c_ctrl_t2, c_pause_2_pls_l, c_pause_2_pls_h	;28 自动停止,时间5s
 db	c_flg_stop, c_prtd3456_1, c_prtd_1, c_prtd3456_1, c_ctrl_stop_t1, c_ctrl_t2, c_pause_3_pls_l, c_pause_3_pls_h	;29 按键触发停止,时间7s
 ;db	c_flg_stop, c_prtd3456_1, c_prtd_1, c_prtd3456_1, c_ctrl_stop_t1, c_ctrl_t2, c_stop_pls_l, c_stop_pls_h		;30 按键触发停止,时间10s

;//04-03-17// add swerving parameter constant table when detect obstacles
 db	c_flg_left, c_prtd3456_1, c_prtd45_0, c_prtd36_1, c_ctrl_swerve_t1_ir, c_ctrl_t2, c_20_pls_l_ir, c_20_pls_h_ir		;30 左转,20度(-)
 db	c_flg_left, c_prtd3456_1, c_prtd45_0, c_prtd36_1, c_ctrl_swerve_t1_ir, c_ctrl_t2, c_40_pls_l_ir, c_40_pls_h_ir		;31 左转,40度
 db	c_flg_left, c_prtd3456_1, c_prtd45_0, c_prtd36_1, c_ctrl_swerve_t1_ir, c_ctrl_t2, c_60_pls_l_ir, c_60_pls_h_ir		;32 左转,60度
 db	c_flg_left, c_prtd3456_1, c_prtd45_0, c_prtd36_1, c_ctrl_swerve_t1_ir, c_ctrl_t2, c_80_pls_l_ir, c_80_pls_h_ir		;33 左转,80度
 db	c_flg_left, c_prtd3456_1, c_prtd45_0, c_prtd36_1, c_ctrl_swerve_t1_ir, c_ctrl_t2, c_100_pls_l_ir, c_100_pls_h_ir	;34 左转,100度
 db	c_flg_left, c_prtd3456_1, c_prtd45_0, c_prtd36_1, c_ctrl_swerve_t1_ir, c_ctrl_t2, c_120_pls_l_ir, c_120_pls_h_ir	;35 左转,120度
 db	c_flg_left, c_prtd3456_1, c_prtd45_0, c_prtd36_1, c_ctrl_swerve_t1_ir, c_ctrl_t2, c_140_pls_l_ir, c_140_pls_h_ir	;36 左转,140度
 db	c_flg_left, c_prtd3456_1, c_prtd45_0, c_prtd36_1, c_ctrl_swerve_t1_ir, c_ctrl_t2, c_160_pls_l_ir, c_160_pls_h_ir	;37 左转,160度
 db	c_flg_left, c_prtd3456_1, c_prtd45_0, c_prtd36_1, c_ctrl_swerve_t1_ir, c_ctrl_t2, c_180_pls_l_ir, c_180_pls_h_ir	;38 左转,180度

 db	c_flg_right, c_prtd3456_1, c_prtd36_0, c_prtd45_1, c_ctrl_swerve_t1_ir, c_ctrl_t2, c_20_pls_l_ir, c_20_pls_h_ir		;39 右转,20度(-)
 db	c_flg_right, c_prtd3456_1, c_prtd36_0, c_prtd45_1, c_ctrl_swerve_t1_ir, c_ctrl_t2, c_40_pls_l_ir, c_40_pls_h_ir		;40 右转,40度
 db	c_flg_right, c_prtd3456_1, c_prtd36_0, c_prtd45_1, c_ctrl_swerve_t1_ir, c_ctrl_t2, c_60_pls_l_ir, c_60_pls_h_ir		;41 右转,60度
 db	c_flg_right, c_prtd3456_1, c_prtd36_0, c_prtd45_1, c_ctrl_swerve_t1_ir, c_ctrl_t2, c_80_pls_l_ir, c_80_pls_h_ir		;42 右转,80度
 db	c_flg_right, c_prtd3456_1, c_prtd36_0, c_prtd45_1, c_ctrl_swerve_t1_ir, c_ctrl_t2, c_100_pls_l_ir, c_100_pls_h_ir	;43 右转,100度
 db	c_flg_right, c_prtd3456_1, c_prtd36_0, c_prtd45_1, c_ctrl_swerve_t1_ir, c_ctrl_t2, c_120_pls_l_ir, c_120_pls_h_ir	;44 右转,120度
 db	c_flg_right, c_prtd3456_1, c_prtd36_0, c_prtd45_1, c_ctrl_swerve_t1_ir, c_ctrl_t2, c_140_pls_l_ir, c_140_pls_h_ir	;45 右转,140度
 db	c_flg_right, c_prtd3456_1, c_prtd36_0, c_prtd45_1, c_ctrl_swerve_t1_ir, c_ctrl_t2, c_160_pls_l_ir, c_160_pls_h_ir	;46 右转,160度
 db	c_flg_right, c_prtd3456_1, c_prtd36_0, c_prtd45_1, c_ctrl_swerve_t1_ir, c_ctrl_t2, c_180_pls_l_ir, c_180_pls_h_ir	;47 右转,180度
;end add //04-03-17//
;//backup
 db	c_flg_backup, c_prtd3456_1, c_prtd35_1, c_prtd46_0, c_ctrl_slow_t1, c_ctrl_t2, c_slow_1_pls_l, c_slow_1_pls_h	        ;48 后退,慢速,短距离
;================================================================;

       

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -