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

📄 jmon2.asm

📁 运用单片机实现时序输出,daddadasdad
💻 ASM
📖 第 1 页 / 共 2 页
字号:
	;
fpoke
	call ppoke ;send id
	call gethexword
	movlw h'01' ;one word array
	movwf wctr
	movlw xbuff
	movwf fsr
	call lflash ;write array
	bsf status,rp1  ;bank 2
	decfsz eeadr,f	;fix address
	goto pfloop
	decf eeadrh,f  ;fix roll through page
	goto pfloop
;-----------------------------------------------------------------------------
;peekdata displays ram
;
peekdata
	movlw 'D'
	call sertx	;send D for data
	call reqaddr
	call gethexword

dloop	movlw h'01'
	andwf xbuff+1,f ;limit to 1ff,highbyte of data address
	btfsc xbuff+1,0
	;
	bsf status,irp ;bit7 is hi bit (baniksel 2,3)
	;
	bcf status,rp1 ;clear bank bits
	bcf status,rp0 ;bank0
	call sendcrlf
	movfw xbuff+1 ;show address, high
	call sendbyte
	movfw xbuff ;show address, low
	movwf fsr ;indirect address in index
	call sendbyte
	movlw '-'
	call sertx ;returns bank0
	;
	;btfsc xbuff+1,0 ;fix bank,if msb bit0=1 bank 2or3
	;bsf status,rp1 ;so set bit
	;btfsc xbuff,7 ;other bank bit is bit7,msbit low
	;bsf status,rp0
	;
	movfw indf ;get data byte to display
	call sendbyte ;show it and loop or poke or escape
	;
	call getkey ;will jump out to runmon if 'esc'
	xorlw 'p' ;poke this data address
	btfss status,z
	goto nopoke  ;any other key increments the address and loops
	call ppoke
	call gethexbyte
	movwf indf
	goto dloop
nopoke
	incfsz xbuff,f
	goto dloop
	incf xbuff+1,f	;data address rolls over
	goto dloop
;=============================================================================
;loader receives a hex file, and programs flash memory with appropriate
;relocations and translations
;
loader
	call reqfile
	;
	call serrx ;receive usart chr
        xorlw ':'   ;go if a file starts
        btfss status,z
        goto runmonx ;give it up on any key other than ':'
	;
	bcf status,rp1 ;banksel flag ;initialize the flags for new code
        bcf flag,vctr ;no user reset in code
        ;
        call loadstatusaddr	;point codeflag word
        movlw h'3f'
        movwf eedath
        movlw h'ff' ;full house means no code ready
        movwf eedata
        call flashwrite	;store codeflag,no program ready until load done
        goto gethdr ;skip procfile at first colon
        ;
;-----------------------------------------------------------------------------
;procfile  receives a hex file, one line at a time and writes each line to
;flash as it is received. This might require adjustment of terminal line delay
;to allow the '877 time for the flash writes between lines. All errors are
;noted, but not identified. loop back from linedone
;
procfile
        call getkey
        xorlw ':' ;if it's a colon, a new line is starting(colon=h'3a')
        btfsc status,z
        goto gethdr          ;proc line
        goto procfile	;wait for valid line indicator(:)
;-----------------------------------------------------------------------------
;parse line header for wordcount, bytecount, address and type
;until eof (type 01)line is received
;
gethdr
  ;process first eight bytes of line
	call prompt
	movlw ':'
        call sertx ;send the colon,just to look official
        clrf checksum ;line checksum is zero to start cumulative count
        ;
        call gethexbyte ;first byte is the line bytecount
        addwf checksum,f ;add to cumulative checksum
        andlw h'1f' ;mask out possible overcount
        movwf wcount
        clrc ;clear carry bit
        rrf wcount,f ;divide by 2 to get number of words in line
        ;
        call gethexbyte ;2nd byte is upper half program address
        addwf checksum,f ;accumulate checksum
        movwf addrfh
	;
        call gethexbyte ;3rd byte is low half of address
        addwf checksum,f
        movwf addrfl
        bcf status,c
        rrf addrfh,f ;/2 to get word address
        rrf addrfl,f
	;
        call gethexbyte ;4th byte is record type
        addwf checksum,f
        xorlw h'01'
        btfsc status,z  ;is eof?
        goto filedone	;finish
	;
        movf hexbyte,w
        btfss status,z ;good line is type 00
        goto procfile ;if not, go wait for next line colon
	;
        movlw h'e0'
        addwf addrfh,w ;if address>=h'2000',they are likely the config and id
        btfsc status,c ;code that can only be programmed,not flash written
        goto procfile ;ignore, get next line
;-----------------------------------------------------------------------------
;get data and checksum from line into the xbuffer
;set up loop to load data array
;
        movlw xbuff
        movwf fsr ;set pointer to start of array
        movf wcount,w
        movwf wctr ;set wctr to number of words in line
getdata
        call gethexbyte ;get low data byte
        addwf checksum,f
        movwf indf ;save in array
        incf fsr,f ;point to high byte
	;
        call gethexbyte ;get high data byte
        addwf checksum,f
        movwf indf ;save in array
        incf fsr,f  ;point to next low byte
	;
        decfsz wctr,f ;count words
	goto getdata  ;and loop until line done
	;
        call gethexbyte  ;get checksum
	addwf checksum,f
        movf checksum,w  ;should be=zero
        btfss status,z
        goto erxnn ;flag fault and start new line
        	;wcount has number of words in the line
        	;checksum has been passed
        	;xbuff holds hex data words from line
;-----------------------------------------------------------------------------
;take care of vector relocation at <user> when line 00 comes in
addrtst
	btfsc flag,vctr ;reset vector code received already
	goto addrfix ;skip tests if vector is flagged done
	;
        movf addrfh,w  ;if addrfh is zero,it could be the reset vector
        btfss status,z ;it must be relocated first, or there is a fatal
        goto addrfix	;is not reset vector address
        ;
        movlw addrfl
        sublw h'04' ;
        btfsc status,c ;no carry means address < 4
        goto addrfix
	;
        bsf flag,vctr  ;flag installed vector,and relocate the reset
        movlw low (user+1) ;to write usr reset vector
        movwf addrfl   ;relocate addresses 0-3
	;
        movlw high (user+1) ;new location high address
        movwf addrfh         ;store high address
		 ;get data and program the line to flash - this should
		; be a maximum of three words(line bytecount should be h'06')
	goto flsetup  ;get next line
;-----------------------------------------------------------------------------
;addrfix makes sure reset code has been received and relocated first
;sends an error if no reset, or if upload trys to write over monitor code
;
addrfix
	btfss flag,vctr ;reset vector code received already
	goto erxnn ;fatal line error quits line if it has not
	;
	movfw addrfh ;coveted address hibyte
	btfsc status,z ;if high addr=0, protect reset vector
	goto addrfxx
	movwf temp  ;store the hiaddr for calculation
	;
	movfw addrfl ;get the desired address lobyte
	addwf wcount,w ;see if we'll overflow into next page
	btfsc status,c ;increment the lusted for hiaddr if overflow
	incf temp,f ;projected high address is in temp register
	;
        movlw  high monitor ;get high byte of resident flash address
        subwf temp,w ;subtract it from hoped for high address
        btfsc status,c ;don't write if address is in monitor
	;
	goto erxnn ;fatal line error quits line(address>monitor)
	goto flsetup ;go write
	;
addrfxx		;protect boot vector at 0000-0003
	;
        movfw  addrfl ;get low byte of address
        sublw h'04' ;subtract addrfl from h'04'
        btfsc status,z	;equal is ok
        goto flsetup ;go write
        btfss status,c ;no crry is trying to write in vector memory
        goto flsetup ;go write
        goto erxnn  ;fatal line error
;-----------------------------------------------------------------------------
;setup address and data and write array data into flash
;
flsetup
	movlw xbuff	;buffer has program words
        movwf fsr  ;point array
        movf wcount,w
        movwf wctr  ;set wctr
	;
        movf addrfh,w ;get high address
        bsf status,rp1 ;banksel eeadrh
        movwf eeadrh ;load high address
        bcf status,rp1 ;banksel addrfl
        movf addrfl,w ;get low address
        bsf status,rp1 ;banksel eeadr
        movwf eeadr ;load low address,all is ready to move to flash
	call lflash ;go put data array in program memory
	;
linedone
        movlw   '*'  ;line has been programmed so
        call sertx ;transmit success
        goto procfile ; go get next line hex file
;-----------------------------------------------------------------------------
;file has been loaded,change the status indicator,run the program if no loading
;errors, otherwise go back to the menu,may require a line delay in terminal tx
;
filedone
        call serrx
        xorlw h'0d' ; hit the cr yet?
        btfsc status,z
        goto filex ; got the cr, finish the report
        xorlw h'0d' ; need to echo, restore the char
        call sertx ; do the echo
        goto filedone ; loop until cr
filex
        call loadstatusaddr ;load address of codeflag word
        clrf eedath ;load data to indicate program exists
        clrf eedata ;load data to indicate program exists
        call flashwrite
        call sendcrlf
        goto runmon ;return to menu
;=============================================================================
;send a fault flag, and stop processing line(the nn can become a marked error)
;but this has been kept rudimentary to save codespace
;
erxnn
	movlw '-'
	call sertx
	movlw 'X'
	call sertx
	goto procfile
;=============================================================================
	include <subs2.inc>
;=============================================================================
                end

⌨️ 快捷键说明

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