📄 jmon2.asm
字号:
;V2.1 fixes indexing when reading data memory(line299) 08/23/01
;added assembly options for various clock speeds(line31) 12/25/01
;this defaults to 20MHz crystal clock (HS)
; baud rate 19200
; timer at startup from reset(line ~100)
;=============================================================================
;Jack's monitor, version 2.1
;Jack Dollhausen, May 2001,jackdoll@pullman.com
;........................................
;This version is limited to two pages of flash memory at $1e00-$1fff,
;and 3bytes at reset vector $0000.
;Once programmed into the chip, this code remains there and eliminates
;the need for the chip's program mode.
;Communicates through the '877's usart to a PC terminal.
;Commands:
; 0 - peek and poke flash memory
; 1 - peek and poke RAM registers
; 2 - peek and poke EEPROM memory
; 3 - load a program from the terminal
; 4 - run user code
; 5 - parse and load hex file lines anywhere
; 6 - hexdump eeprom data memory
; 7 - input and jump to a vector anywhere
;=============================================================================
list p=16f877,n=0
errorlevel -302
#include <jp16f877.inc>
;=============================================================================
;the programmer does config, ;it's therefore the default config for user code
__config _boden_off & _cp_off & _pwrte_on & _wdt_off & _wrt_enable_on & _hs_osc & _debug_off & _cpd_off & _lvp_off
;=============================================================================
; baud rate constants for a 4.0 mhz crystal.....................
;baud_19200 equ h'0c' ;d'12'
; baud rate constants for a 10.0 mhz crystal.....................
;baud_9600 equ h'40' ;d'64', 19200 can't compute @ 10mhz
; baud rate constants for a 20.0 mhz crystal.....................
;baud_9600 equ h'81' ;d'129'
baud_19200 equ h'40' ;d'64'
;........................................
;flag bit definition, only one flag is used in this version(1)
vctr equ 0 ;bit0=reset vector status
;=============================================================================
;variables - all in bank0,probably could save some banking code if@ h'70'
cblock h'20'
;
addrfh:1 ;flash address high byte
addrfl:1 ;flash address low byte
wcount:1 ;word count from hex file line
checksum:1 ;accumulated from incoming data during load
wctr:1 ;count down words from wcount
;........................................
flag:1 ;various flags, bit0=vctr, used to test user code loading
;........................................
hexbyte:1 ;translated from ascii usart input
temp:1 ;general purpose storage
xbuff:0x40 ;i/o buffer
;
endc
;=============================================================================
org 0
movlw high main ;reset vector, chip always jumps to monitor
movwf pclath ;user code reset vector is relocated to <user>
;when user program is (l)oaded by monitor
goto main ;go to monitor
;=============================================================================
org h'1e00' ;512 bytes for the code(1e00-1fff)
;use last two 256byte pages (version1)
monitor ;start resident code.............
pagesel $
goto $ ;trap runaway code trying to enter monitor
;-----------------------------------------------------------------------------
;user reset is here, not at 0000 hard reset!
;upload puts addr 0000 - 0004 of user code here
;enter in bank0, watch code page
;
user
clrf pclath ;goto hdw reset vector page when you jump
nop ;user code reset vector here
nop
nop
;
pagesel $ ;nothing gets past here
goto $ ;in case user reset is missing or screwy
;=============================================================================
;codeflag allows code to run on hard reset, if zero
;this is set at load time, and tested on reset
;
codeflag
da h'3fff' ;0 for valid code, h'3fff' for no code
;=============================================================================
;main idles for three or four seconds on hardware reset, waiting for a key from
;another option is to pull a port pin low on reset to signal the jump
;the serial interface. if it gets a key, the monitor runs, if no key arrives in ;time, it tests the codeflag for to see if there's a valid user program installed.
;if there's no user code it sits in an endless loop waiting for another hard reset
;
main
pagesel main ;in case of a jump to here
call serialsetup
;
bsf status,rp0 ;banksel option_reg
movlw b'10000111' ;tmr0 prescaler, 1:256
;movlw b'10000101' ;tmr0 prescaler, 1:64
movwf option_reg
bcf status,rp0 ;bank0
movlw h'ff' ;time counter to wait for key after reset
movwf wctr ;full counter gives about four seconds @ 20MHz
timeout ;waits for a key or timeout
btfsc pir1,rcif ;poll usart receive bit
goto runmon ;if key sent
btfss intcon,t0if ;wait for timer0 to timeout
goto timeout ;loop
bcf intcon,t0if
decfsz wctr,f
goto timeout
runuser
call loadstatusaddr ;load address of codeflag word
call flashread ;read data at codeflag location
bcf status,rp0 ;banksel eedata
movf eedata,f ;check for zero
btfss status,z
goto $ ;trap here if no code
goto user ;if zero then run user code
;=============================================================================
;enter here to skip code status testing (no jump to user)
;
runmon ;start running the monitor, show menu and get choice
call sendcrlf
call salute ;lets us know where we are
runmonx call prompt ;enter here if no menu necessary
;
choose ;choose action, one of eight functions
bcf status,rp1 ;banksel temp
;
bcf status,irp ;bit 7 is index (bankisel 0,1)
;
call serrx ;get choice
andlw b'00000111' ;mask 3lsb for 8functions
btfss status,z ;avoid loop of adding zero to the pc
addwf pcl,f ;compute the jump
goto peekflash ;function 0...
goto peekdata ;1
goto peekee ;2
goto loader ;3-load a new hex image into program memory
goto runx ;4-run user program(if it's there)
goto freeload ;5-freeload a hexfile at any address
goto dumpee ;6-dump eeprom to usart
goto jumpout ;7-jump to a vector outside the monitor
;=============================================================================
;dumpee does a hex dump of 256 eeprom bytes
;
dumpee
movlw 'E'
call sertx
call sertx
call sendcrlf
bsf status,rp1 ;bank2
clrf eeadr ;start at address 0
reeloop
call eeread
call sendbyte
bsf status,rp1 ;bank2
incfsz eeadr,f
goto linechk
goto runmon ;finished
linechk
movlw h'0f' ;mask low bits
andwf eeadr,w
btfsc status,z
call sendcrlf
goto reeloop
;=============================================================================
;jumpout goes to any program location, This must be poked in by hand to
;accomodate paging issues for the goto command. initialized to the monitor
;so running this command without the poked data, will just return to salute
;don't forget that the goto really refers to eleven bits in the pc
;goto:= 21+ms3bits,byte - calculated in wetware
;
jumpout
movlw 'J' ;J is for jump
call sertx
call gethexword
call getkey ;escape possible
movfw xbuff+1 ;high byte of address
movwf pclath
movfw xbuff
movwf pcl ;unconditional
;=============================================================================
;runx prints a mssg and runs loaded program
;
runx
movlw 'R' ;R is for run
call sertx
goto runuser
;=============================================================================
;freeload loads a hexfile at any address in flash -plenty of cautions here!
;;caution - this load can do damage
freeload
call reqfree
bsf flag,vctr ;set vector loaded flag to enable procfile
goto procfile ;wait for the file from the usart
;=============================================================================
;peekee displays eeprom data memory, shows consecutive locations on each
;keypress except esc key which jumps back to menu
;
peekee
movlw 'E'
call sertx ;send E for eeprom
call reqaddr
call gethexbyte
bsf status,rp1 ;bank2
movwf eeadr ;ee is addressed
eepromrd
call sendcrlf
bsf status,rp1 ;bank2
movfw eeadr
call sendbyte
movlw '-'
call sertx
call eeread
call sendbyte
;
call getkey
xorlw 'p' ;poke this address
btfss status,z
goto eeprx ;any other key increments the address and loops
call ppoke
call gethexbyte
bsf status,rp1 ;bank0 to 2
movwf eedata
call eewrite
goto eepromrd ;and loop without increment
eeprx
banksel eeadr
incf eeadr,f
goto eepromrd
;=============================================================================
;peekflash displays program memory - shows consecutive locations on each
;keypress except esc key which jumps back to menu, and 'p', which invokes
;the poke function
;
peekflash
movlw 'F'
call sertx ;send f for flash
call reqaddr
call gethexbyte
bsf status,rp1 ;banksel eeadr
andlw h'1f' ;limit high address
movwf eeadrh ;for flashread
call gethexbyte
bsf status,rp1 ;banksel eeadr
movwf eeadr
pfloop ;prints a pgm line to scrn
call sendcrlf
banksel eeadr
movfw eeadrh
call sendbyte
bsf status,rp1 ;bank0 to bank2
movfw eeadr
call sendbyte
bsf status,rp1 ;bank0 to bank2
call flashread ;returns bank3
;
movlw ' '
call sertx ;returns bank0
bsf status,rp1 ;bank0 to bank2
movfw eedath
call sendbyte
bsf status,rp1 ;bank0 to bank2
movf eedata,w
call sendbyte
bsf status,rp1 ;bank0 to bank2
;
call getkey
xorlw 'p' ;poke this address
btfsc status,z ;any other key increments the address
goto fpoke
bsf status,rp1 ;bank0 to bank2
incfsz eeadr,f
goto pfloop
incf eeadrh,f ;if low rolls to high
goto pfloop
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -