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

📄 mypaulm2.asm

📁 8051 monitor programm: - use external ram to run user program - use eeprom to save user program
💻 ASM
📖 第 1 页 / 共 4 页
字号:
	acall	pcstr_h	ajmp	upldmenu1f: cjne	a, #nloc_key, menu1g	mov	dptr, #nloc_cmd	acall	pcstr_h	ajmp	nlocmenu1g: cjne	a, #jump_key, menu1h	mov	dptr, #jump_cmd	acall	pcstr_h	ajmp	jumpmenu1h: cjne	a, #dump_key, menu1i	mov	dptr, #dump_cmd	acall	pcstr_h	ajmp	dumpmenu1i: cjne	a, #edit_key, menu1j	mov	dptr, #edit_cmd	acall	pcstr_h	ajmp	editmenu1j: cjne	a, #clrm_key, menu1k	mov	dptr, #clrm_cmd	acall	pcstr_h	ajmp	clrmmenu1k: cjne	a, #erfr_key, menu1l	mov	a, #has_flash	jz	menu_end	mov	dptr, #erfr_cmd	acall	pcstr_h	ajmp	erfrmenu1l: cjne	a, #intm_key, menu1m	mov	dptr, #intm_cmd	acall	pcstr_h	ljmp	intmmenu1m:    ;invalid input, no commands to run...menu_end:			;at this point, we have not found	ajmp	newline		;anything to run, so we give up.				;remember, we pushed menu, so newline				;will just return to menu.;..........................................................;---------------------------------------------------------;;dnlds1 = "Begin sending Intel HEX format file <ESC> to abort";dnlds2 = "Download aborted";dnlds3 = "Download completed";16 byte parameter table: (eight 16 bit values);  *   0 = lines received;  *   1 = bytes received;  *   2 = bytes written;  *   3 = bytes unable to write;  *   4 = incorrect checksums;  *   5 = unexpected begin of line;  *   6 = unexpected hex digits (while waiting for bol);  *   7 = unexpected non-hex digits (in middle of a line)dnld:	mov	dptr, #dnlds1		 	acall	pcstr_h		   ;"begin sending file <ESC> to abort"	mov	r0, #dnld_parm	mov	r2, #16dnld0:	mov	@r0, #0		;initialize all parameters to 0	inc	r0	djnz	r2, dnld0	  ;look for begining of line marker ':'dnld1:	acall	cin	cjne	a, #27, dnld2	;Test for escape	sjmp	dnld_escdnld2:	cjne	a, #':', dnld2b	mov	r1, #0	acall	dnld_inc	sjmp	dnld3dnld2b:	  ;check to see if it's a hex digit, error if it is	acall	asc2hex	jc	dnld1	mov	r1, #6	acall	dnld_inc	sjmp	dnld1	  ;begin taking in the line of datadnld3:	mov	a, #'.'	acall	cout	mov	r4, #0		;r4 will count up checksum	acall	dnld_ghex	mov	r0, a		;R0 = # of data bytes	acall	dnld_ghex	mov	dph, a		;High byte of load address	acall	dnld_ghex	mov	dpl, a		;Low byte of load address	acall	dnld_ghex	;Record type	cjne	a, #1, dnld4	;End record?	sjmp	dnld_enddnld4:	jnz	dnld_unknown	;is it a unknown record type???dnld5:	mov	a, r0	jz	dnld_get_cksum	acall	dnld_ghex	;Get data byte	mov	r2, a	mov	r1, #1	acall	dnld_inc	;count total data bytes received	mov	a, r2	lcall	smart_wr	;c=1 if an error writing	clr	a	addc	a, #2	mov	r1, a;     2 = bytes written;     3 = bytes unable to write	acall	dnld_inc	inc	dptr	djnz	r0, dnld5dnld_get_cksum:	acall	dnld_ghex	;get checksum	mov	a, r4	jz	dnld1		;should always add to zerodnld_sumerr:	mov	r1, #4	acall	dnld_inc	;all we can do it count # of cksum errors	sjmp	dnld1dnld_unknown:	;handle unknown line type	mov	a, r0	jz	dnld_get_cksum	;skip data if size is zerodnld_ukn2:	acall	dnld_ghex	;consume all of unknown data	djnz	r0, dnld_ukn2	sjmp	dnld_get_cksumdnld_end:   ;handles the proper end-of-download marker	mov	a, r0	jz	dnld_end_3	;should usually be zerodnld_end_2:	acall	dnld_ghex	;consume all of useless data	djnz	r0, dnld_ukn2dnld_end_3:	acall	dnld_ghex	;get the last checksum	mov	a, r4	jnz	dnld_sumerr	acall	dnld_dly	mov	dptr, #dnlds3	acall	pcstr_h		   ;"download went ok..."	;consume any cr or lf character that may have been	;on the end of the last line	jnb	ri, dnld_sum	acall	cin	sjmp	dnld_sumdnld_esc:   ;handle esc received in the download stream	acall	dnld_dly	mov	dptr, #dnlds2	 	acall	pcstr_h		   ;"download aborted."	sjmp	dnld_sumdnld_dly:   ;a short delay since most terminal emulation programs	    ;won't be ready to receive anything immediately after	    ;they've transmitted a file... even on a fast Pentium(tm)	    ;machine with 16550 uarts!	mov	r0, #0dnlddly2:mov	r1, #0	djnz	r1, *		;roughly 128k cycles, appox 0.1 sec	djnz	r0, dnlddly2	retdnld_inc:     ;increment parameter specified by R1	      ;note, values in Acc and R1 are destroyed	mov	a, r1	anl	a, #00000111b	;just in case	rl	a	add	a, #dnld_parm	mov	r1, a		;now r1 points to lsb	inc	@r1	mov	a, @r1	jnz	dnldin2	inc	r1	inc	@r1dnldin2:retdnld_gp:     ;get parameter, and inc to next one (@r1)	     ;carry clear if parameter is zero.	     ;16 bit value returned in dptr	setb	c	mov	dpl, @r1	inc	r1	mov	dph, @r1	inc	r1	mov	a, dpl	jnz	dnldgp2	mov	a, dph	jnz	dnldgp2	clr	cdnldgp2:ret;a spacial version of ghex just for the download.  Does not;look for carriage return or backspace.	 Handles ESC key by;poping the return address (I know, nasty, but it saves many;bytes of code in this 4k ROM) and then jumps to the esc;key handling.	This ghex doesn't echo characters, and if it;sees ':', it pops the return and jumps to an error handler;for ':' in the middle of a line.  Non-hex digits also jump;to error handlers, depending on which digit.	  dnld_ghex:dnldgh1:acall	cin	acall	upper	cjne	a, #27, dnldgh3dnldgh2:pop	acc	pop	acc	sjmp	dnld_escdnldgh3:cjne	a, #':', dnldgh5dnldgh4:mov	r1, #5		;handle unexpected beginning of line	acall	dnld_inc	pop	acc	pop	acc	ajmp	dnld3		;and now we're on a new line!dnldgh5:acall	asc2hex	jnc	dnldgh6	mov	r1, #7	acall	dnld_inc	sjmp	dnldgh1dnldgh6:mov	r2, a		;keep first digit in r2dnldgh7:acall	cin	acall	upper	cjne	a, #27, dnldgh8	sjmp	dnldgh2dnldgh8:cjne	a, #':', dnldgh9	sjmp	dnldgh4dnldgh9:acall	asc2hex	jnc	dnldghA	mov	r1, #7	acall	dnld_inc	sjmp	dnldgh7dnldghA:xch	a, r2	swap	a	orl	a, r2	mov	r2, a	add	a, r4		;add into checksum	mov	r4, a	mov	a, r2		;return value in acc	ret;dnlds4 =  "Summary:";dnlds5 =  " lines received";dnlds6a = " bytes received";dnlds6b = " bytes written"dnld_sum:    ;print out download summary	mov	a, r6	push	acc	mov	a, r7	push	acc	mov	dptr, #dnlds4	acall	pcstr_h	mov	r1, #dnld_parm	mov	r6, #dnlds5 & 255	mov	r7, #dnlds5 >> 8	acall	dnld_i0	mov	r6, #dnlds6a & 255	mov	r7, #dnlds6a >> 8	acall	dnld_i0	mov	r6, #dnlds6b & 255	mov	r7, #dnlds6b >> 8	acall	dnld_i0dnld_err:    ;now print out error summary	mov	r2, #5dnlder2:acall	dnld_gp	jc	dnlder3		;any errors?	djnz	r2, dnlder2	 ;no errors, so we print the nice message	mov	dptr, #dnlds13	acall	pcstr_h	sjmp	dlnd_sum_donednlder3:  ;there were errors, so now we print 'em	mov	dptr, #dnlds7	acall	pcstr_h	  ;but let's not be nasty... only print if necessary	mov	r1, #(dnld_parm+6)	mov	r6, #dnlds8 & 255	mov	r7, #dnlds8 >> 8	acall	dnld_item	mov	r6, #dnlds9 & 255	mov	r7, #dnlds9 >> 8	acall	dnld_item	mov	r6, #dnlds10 & 255	mov	r7, #dnlds10 >> 8	acall	dnld_item	mov	r6, #dnlds11 & 255	mov	r7, #dnlds11 >> 8	acall	dnld_item	mov	r6, #dnlds12 & 255	mov	r7, #dnlds12 >> 8	acall	dnld_itemdlnd_sum_done:	pop	acc	mov	r7, a	pop	acc	mov	r6, a	ajmp	newlinednld_item:	acall	dnld_gp		;error conditions	jnc	dnld_i3dnld_i2:acall	space	lcall	pint16u	acall	r6r7todptr	acall	pcstr_hdnld_i3:retdnld_i0:acall	dnld_gp		;non-error conditions	sjmp	dnld_i2;dnlds7:  = "Errors:";dnlds8:  = " bytes unable to write";dnlds9:  = " incorrect checksums";dnlds10: = " unexpected begin of line";dnlds11: = " unexpected hex digits";dnlds12: = " unexpected non-hex digits";dnlds13: = "No errors detected";---------------------------------------------------------;jump:	mov	dptr, #prompt8	acall	pcstr_h	acall	r6r7todptr	acall	phex16	mov	dptr, #prompt4	acall	pcstr_h	acall	ghex16	jb	psw.5, jump3	jnc	jump2	ajmp	abort2jump2:	acall	dptrtor6r7jump3:	acall	newline	mov	dptr, #runs1	acall	pcstr_h	acall	r6r7todptrjump_doit:  ;jump to user code @dptr (this used by run command also)	clr	a	mov	psw, a	mov	b, a	mov	r0, a	mov	r1, a	mov	r2, a	mov	r3, a	mov	r4, a	mov	r5, a	mov	r6, a	mov	r7, a	mov	sp, #8		;start w/ sp=7, like a real reset	push	acc		;unlike a real reset, push 0000	push	acc		;in case they end with a RET	jmp	@a+dptr;---------------------------------------------------------;dump:		mov	r2, #16		;number of lines to print	acall	newline2dump1:	acall	r6r7todptr	acall	phex16		;tell 'em the memory location	mov	a,#':'	acall	cout_sp	mov	r3, #16		;r3 counts # of bytes to print	acall	r6r7todptrdump2:	clr	a	movc	a, @a+dptr	inc	dptr	acall	phex		;print each byte in hex	acall	space	djnz	r3, dump2	acall	dspace		;print a couple extra space	mov	r3, #16	acall	r6r7todptrdump3:	clr	a	movc	a, @a+dptr	inc	dptr	anl	a, #01111111b	;avoid unprintable characters	cjne	a, #127, dump3b	clr	a		;avoid 127/255 (delete/rubout) chardump3b: add	a, #224	jc	dump4	clr	a		;avoid control charactersdump4:	add	a, #32	acall	cout	djnz	r3, dump3	acall	newline	acall	line_dly	acall	dptrtor6r7	acall	esc	jc	dump5	djnz	r2, dump1	;loop back up to print next linedump5:	ajmp	newline;---------------------------------------------------------;; change with hex address entering following edit commandedit:	   ;edit external ram...        mov     dptr, #edits1        acall   pcstr_h        acall   ghex16        ;mov     dptr, #edits1        acall   dptrtor6r7    ;acall   pcstr_h        acall   newline       ;acall   r6r7todptredit1:	acall	phex16	mov	a,#':'	acall	cout_sp	mov	a,#'('	acall	cout	acall	dptrtor6r7	clr	a	movc	a, @a+dptr	acall	phex	mov	dptr,#prompt10	acall	pcstr_h	acall	ghex	jb	psw.5,edit2	jc	edit2	acall	r6r7todptr	lcall	smart_wr	acall	newline	acall	r6r7todptr	inc	dptr	acall	dptrtor6r7	ajmp	edit1edit2:	mov	dptr,#edits2	ajmp	pcstr_h;---------------------------------------------------------;dir:	mov	dptr, #prompt9	acall	pcstr_h	mov	r0, #21dir0a:	acall	space	djnz	r0, dir0a	;mov	dptr, #prompt9b	acall	pcstr_h	mov	dph, #(bmem >> 8)dir1:	acall	find		;find the next program in memory	jc	dir2dir_end:ajmp	newline		;we're done if no more founddir2:	acall	dspace	mov	dpl, #32	;print its name	acall	pstr	mov	dpl, #32	;how long is the name	acall	lenstr	mov	a, #33	clr	c	subb	a, r0	mov	r0, a	mov	a, #' '		;print the right # of spacesdir3:	acall	cout	djnz	r0, dir3	mov	dpl, #0	acall	phex16		;print the memory location	mov	r0, #6	mov	a, #' 'dir4:	acall	cout	djnz	r0, dir4	mov	dpl, #4		;now figure out what type it is	clr	a	movc	a, @a+dptr	mov	r2, dph		;save this, we're inside a searchdir5:	cjne	a, #254, dir5b	mov	dptr, #type1	;it's an external command	sjmp	dir7dir5b:	cjne	a, #253, dir5cdir5bb: mov	dptr, #type4	;it's a startup routine	sjmp	dir7dir5c:	cjne	a, #35, dir5d	mov	dptr, #type2	;it's an ordinary program	sjmp	dir7dir5d:	cjne	a, #249, dir5e	sjmp	dir5bbdir5e:dir6:	mov	dptr, #type5	;who knows what the hell it isdir7:	acall	pcstr_h		   ;print out the type	mov	dph, r2		;go back and find the next one	acall	newline	mov	a, #(emem >> 8)	cjne	a, dph, dir8	;did we just print the last one?	ajmp	dir_enddir8:	inc	dph	mov	a, dph	cjne	a, #((emem+1) >> 8) & 255, dir1	ajmp	dir_end;type1=Ext Command;type4=Startup;type2=Program;type5=???;---------------------------------------------------------;run:   	acall	newline2	mov	r2, #255	;first print the menu, count items	mov	dptr, #bmem	dec	dphrun2:	inc	dph	mov	a, dph	cjne	a, #((emem+1) >> 8) & 255, run2b	sjmp	run3run2b:	acall	find	jnc	run3		;have we found 'em all??	mov	dpl, #4	clr	a	movc	a, @a+dptr	orl	a, #00000011b	cpl	a	jz	run2		;this one doesn't run... find next	acall	dspace	inc	r2	mov	a, #'A'		;print the key to press	add	a, r2	acall	cout_sp	acall	dash_sp	mov	dpl, #32	acall	pstr		;and the command name	acall	newline	ajmp	run2		;and continue doing thisrun3:	cjne	r2, #255, run4	;are there any to run??	mov	dptr, #prompt5	ajmp	pcstr_hrun4:	mov	dptr, #prompt3	;ask the big question!	acall	pcstr_h	mov	a, #'A'	acall	cout	acall	dash	mov	a, #'A'		;such user friendliness...	add	a, r2		;even tell 'em the choices	acall	cout	mov	dptr, #prompt4	acall	pcstr_h	acall	cin_filter_h	cjne	a, #27, run4aa	;they they hit <ESC>	ajmp	newlinerun4aa: mov	r3, a	mov	a, #31	clr	c	subb	a, r2	mov	a, r3	jc	run4a	acall	upperrun4a:	acall	cout	mov	r3, a	acall	newline	;check to see if it's under 32, if so convert to uppercase	mov	a, r3	clr	c	subb	a, #'A'	jc	run4		;if they typed less than 'A'	mov	r3, a		;R3 has the number they typed	mov	a, r2		;A=R2 has the maximum number	clr	c	subb	a, r3	jc	run4		;if they typed over the max	inc	r3	mov	dptr, #bmem	dec	dphrun5:	inc	dph	mov	a, dph	cjne	a, #((emem+1) >> 8) & 255, run5b	sjmp	run8run5b:	acall	find	jnc	run8		;Shouldn't ever do this jump!	mov	dpl, #4	clr	a	movc	a, @a+dptr	orl	a, #00000011b	cpl	a	jz	run5		;this one doesn't run... find next	djnz	r3, run5	;count til we find the one they want	acall	newline	mov	dpl, #64	ajmp	jump_doitrun8:	ret;---------------------------------------------------------;help:	mov	dptr, #help1txt	acall	pcstr_h	mov	r4, #help_key	mov	dptr, #help_cmd	acall	help2	mov	r4, #dir_key	;mov	 dptr, #dir_cmd	acall	help2	mov	r4, #run_key	;mov	 dptr, #run_cmd	acall	help2	mov	r4, #dnld_key	;mov	 dptr, #dnld_cmd	acall	help2	mov	r4, #upld_key	;mov	 dptr, #upld_cmd	acall	help2	mov	r4, #nloc_key	;mov	 dptr, #nloc_cmd	acall	help2	mov	r4, #jump_key	;mov	 dptr, #jump_cmd	acall	help2	mov	r4, #dump_key	;mov	 dptr, #dump_cmd	acall	help2	mov	r4, #intm_key	;mov	dptr, #intm_cmd	acall	help2	mov	r4, #edit_key	;mov	 dptr, #edit_cmd	acall	help2	mov	r4, #clrm_key

⌨️ 快捷键说明

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