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

📄 mouse_main.asl

📁 一款智能老鼠的玩具源代码
💻 ASL
📖 第 1 页 / 共 2 页
字号:
+                     1 ;****************************************************************;
+                     2 ; MOUSE-hourse
+                     3 ; Version 1.0
+                     4 ;
+                     5 ; MCU Body: KB 89C21(89R21)
+                     6 ; ROM size: 16K Bytes
+                     7 ; RAM size: 512 Bytes
+                     8 ; Interrupt: three timer and two external interrupt
+                     9 ; Clock: Dual,Fast,Slow clock (4M, set temporarily)
+                    10 ; Operating Mode: Dual,Fast,Slow,Idle,Sleep
+                    11 ; Built-in WATCH DOG TIMER
+                    12 ; 16 bi-directional I/O pins
+                    13 ;
+                    14 ; Written by: lixy
+                    15 ; Date: 2004-02-16 
+                    16 ; chagen by :he qingrang
+                    17 ; date: 2004-06-25
+                    18 ;****************************************************************;
+                    19 
+                    20 ;================================================================;
+                    21 ;CONSTANT AREA
+                    22 ;================================================================;
00EF                 23 c_sp		equ 	#0efh		;the sp address
00FF                 24 c_ram		equ	#0ffh		;the maximum ram size
0000                 25 c_t1h		equ	#00h		;set timer1 frequency 8KHz,(slow clock)32K/8K-1=3=0003h
0003                 26 c_t1l		equ	#03h     
0022                 27 c_t2h		equ	#22h		;set timer2 frequency 300Hz,(fast clock)4M/1.5/300-1=8888=22b8h
00B8                 28 c_t2l		equ	#0b8h
001C                 29 c_op1		equ	#00011100b	;R_OP1: bit7:DRDY, bit6:STOP, bit5:SLOW, bit4:INTE
+                    30 					;       bit3:T2E,  bit2:T1E,  bit1:Z,    bit0:C
+                    31 ;c_ier		equ	#00110b		;R_IER: bit4:TB,   bit3:INT1, bit2:T1,   bit1:T2,  bit0:INT2
0007                 32 c_ier		equ	#00111b		;R_IER: bit4:TB,   bit3:INT1, bit2:T1,   bit1:T2,  bit0:INT2
+                    33 
0004                 34 c_ier_en_t1	equ	#00100b		;R_IER: bit4:TB,   bit3:INT1, bit2:T1,   bit1:T2,  bit0:INT2
0002                 35 c_ier_en_t2	equ	#00010b		;R_IER: bit4:TB,   bit3:INT1, bit2:T1,   bit1:T2,  bit0:INT2
0001                 36 c_ier_en_int2	equ	#00001b		;R_IER: bit4:TB,   bit3:INT1, bit2:T1,   bit1:T2,  bit0:INT2
0003                 37 c_init_point_h	equ	#03h
00E7                 38 c_init_point_l	equ	#0e7h           ;999=03e7H
0006                 39 c_fail_loop	equ	#6		;when fail,play fail voice and lcd flash times
0078                 40 c_point_dec_intvl	equ	#120	;120/300=400ms
0014                 41 c_play_v_normal_intvl	equ	#20     ;(c_point_dec_intvl/300)*c_play_voice_intvl
000A                 42 c_play_v_fast_intvl	equ	#10
0032                 43 c_fast_voice		equ	#50	;<255 and >50,fast voice
+                    44 
+                    45 ;================================================================;
+                    46 ;DATA AREA
+                    47 ;================================================================;
+B 00 01

+                    48 	.area	main_var(data)
+                    49 
0000                 50 flg_new_random::	.ds	1	;the flag of generating new random number
+                    51                                         ;"0" not generate new random number
+                    52                                         ;"1" generate new random number in free movement course 
+                    53                                         ;"2" generate new random number when received IR
0001                 54 cnt_point::		.ds	2       ;point counter,it will decrease 1 each interval
0003                 55 cnt_fail_loop::		.ds	1
0004                 56 cnt_play_v_intvl::	.ds	1	;play voice interval,(c_point_dec_intvl/300)*cnt_play_v_intvl,
+                    57 ;================================================================;
+                    58 ;CODE AREA
+                    59 ;================================================================;
+B 00 02

+                    60 	.area	main_code(code,abs)
+                    61 
+                    62 	.org	0x00
0000 02 00 16        63 	br	start_initial
+                    64 	.org	0x06			;Int1(prtd.6) entry
0006 02 00 15        65 	br	int1_isr
+                    66 	.org	0x09			;Timer1 entry
0009 02 00 00        67 	br	t1_isr
+                    68 	.org	0x0c			;Timer2 entry
000C 02 00 00        69 	br	t2_isr
+                    70 	.org	0x0f			;Int2(prtd.7) entry
000F 02 00 00        71 	br	INT2_isr
+                    72 	.org	0x12			;Time base entry
0012 02 00 15        73 	br	tb_isr
+                    74 
0015                 75 int1_isr:
+                    76 ;t1_isr:
+                    77 ;t2_isr:
+                    78 ;int2_isr:
0015                 79 tb_isr:
0015 25              80 	reti
+                    81 
+                    82 ;----------------------------------------------------------------;
+                    83 ;Start Initial
+                    84 ;----------------------------------------------------------------;
0016                 85 start_initial:
0016 F3 EF           86 	lda	#c_sp			;set stack pointer
0018 FC 18           87 	sta	r_sp
001A F3 FF           88 	lda	#11111111b
001C FC 32           89 	sta	r_prtd			;set i/o prtd
001E F3 FF           90 	lda	#11111111b		;set prtc[0,1,2] "0" when initial, IR driver circuit worked at high level.
0020 FC 31           91 	sta	r_prtc			;set i/o prtc
0022                 92 clear_memory:				;clear sram(page0)其中包括显存(f0h-ffh)
0022 F3 00           93 	lda	#00h
0024 FC 21           94 	sta	r_dp
0026                 95 clr_m:
0026 F3 00           96 	lda	#00h
0028 FE              97 	sta	i
0029 F0 21           98 	lda	r_dp
002B A7 FF           99 	cmpe	#c_ram
002D 06 00 34       100 	brz	clr_end
0030 18             101 	incdp
0031 02 00 26       102 	br	clr_m
0034                103 clr_end:
+                   104 ;	lda	#0ffh	;display all
+                   105 ;	sta	0f0h
+                   106 ;	sta	0f1h
+                   107 ;	sta	0f2h
0034 20 01 67       108 	call	normal_clock		;set normal mode timing定义时钟初值
0037 20 01 49       109 	call	initial_reg 		;initial register定义特殊寄存器
+                   110 
003A F3 03          111   	lda	#c_init_point_h         ;lcd display initial "999"
003C FD 02          112 	sta	cnt_point+1
003E F3 E7          113 	lda	#c_init_point_l
0040 FD 01          114 	sta	cnt_point
0042 F3 1C          115 	lda	#c_op1		;#00011100b,normal mode, open interrupt,enable timer1
0044 FC 22          116 	sta	r_op1		; R_OP1: bit7:DRDY, bit6:STOP, bit5:SLOW, bit4:INTE
+                   117 
+                   118 ;----------------------------------------------------------------;
+                   119 ;Wait for nose key pressed, if nose key is pressed and released,the mouse start run
+                   120 ;----------------------------------------------------------------;
0046 20 00 00       121 	call	scan_key_start
0049 F3 02          122 	lda	#c_ier_en_t2		;enable timer2
004B FC 04          123 	sta	r_ier
+                   124 ;	lda	r_ier			;enable timer1
004D DB 04          125 	ora	#c_ier_en_t1
004F FC 04          126 	sta	r_ier
0051 DB 01          127 	ora	#c_ier_en_int2		;enable int2
0053 FC 04          128 	sta	r_ier
+                   129 	
0055                130 main:
0055 F3 80          131 	lda	#10000000b		;draw up the INT2 port
0057 D8 32          132 	ora	r_prtd
0059 FC 32          133 	sta	r_prtd     		
005B 29             134 	clrwdt				;add Watch Dog function
+                   135 ;-----------------------------------------------------------------------
+                   136 ;judge if touched sign is received, if yes, the game will over
+                   137 ;-----------------------------------------------------------------------
005C 20 00 7B       138 	call	if_gameover
+                   139 ;calculating the points and display it,play the sound
005F 20 00 BC       140 	call	cal_point
+                   141 ;-----------------------------------------------------------------------
+                   142 ;scan stall,nose,trap key
0062 20 00 00       143 	call	scan_key
+                   144 ;-----------------------------------------------------------------------
0065 20 00 00       145 	call	ir_judge		;revise ir transmit, receive and judge way
0068 F1 00          146 	lda	flg_new_random		;if the flag is not "0", read new random number to change the motor status.
006A A7 00          147 	cmpe	#0
006C 06 00 55       148         brz	main
006F 20 00 00       149 	call	set_rules
0072                150 call_random:
0072 20 00 00       151         call	read_random
0075 20 00 00       152         call	run
0078 02 00 55       153 	br	main
+                   154 	
+                   155 ;//***********************Game Over*************************************
007B                156 if_gameover::
007B F1 00          157 	lda	flg_rcv_touched
007D A7 01          158 	cmpe	#1			;touched the cheese 
007F 06 00 83       159 	brz	gameover
0082 24             160 	ret
0083                161 gameover:
0083 20 00 00       162 	call	select_sound_gameover
0086                163 gameover_song:
0086 29             164 	clrwdt
0087 F3 FF          165   	lda	#0ffh
0089 A5 00          166         cmpe	M_stopbit
008B 07 00 86       167         brnz	gameover_song
008E 20 00 00       168 	call	select_sound_gameover
0091                169 gameover_song1:
0091 29             170 	clrwdt
0092 F3 FF          171   	lda	#0ffh
0094 A5 00          172         cmpe	M_stopbit
0096 07 00 91       173         brnz	gameover_song1
0099                174 gameover_stop:
0099 F3 FF          175 	lda	#11111111b		;stop all motors and ir tx
009B FC 32          176 	sta	r_prtd			;set i/o prtd
009D FC 31          177   	sta	r_prtc			;set i/o prtc
009F F3 00          178 	lda	#00h
00A1 FC 48          179 	sta	r_voc
00A3 FC 34          180 	sta	r_pwmc
00A5 FD 00          181 	sta	status_ir_rcv   	;restore the receive status
+                   182 ;	lda	#00h
00A7 FC 38          183 	sta	r_lcdc			;disable lcd display
+                   184 ;	lda	#00000b			;disable all interrupt
00A9 FC 04          185 	sta	r_ier
00AB F3 40          186 	lda	#01000000b		;set sleep mode,close int,t1,t2,tb
00AD FC 22          187 	sta	r_op1
00AF 00             188 	nop
00B0 00             189 	nop
00B1 00             190 	nop
00B2 00             191 	nop
00B3 00             192 	nop
00B4 00             193 	nop
00B5 00             194 	nop
00B6 00             195 	nop

⌨️ 快捷键说明

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