📄 lpc_isp_4k_v03.a51
字号:
MOV A,SBUF ;read the char
RET ;and done
;***** character echo routine *****
;
;waits until a character is received from
;the console input and echos this character
;to the console output. The received char
;is also passed to the caller in the ACC.
ECHO: ACALL CI ;get char from console
ACALL CO ;print the character
JNB ACC.6,EXECHO ;exit if not 4x,5x, or 6x Hex
CLR ACC.5 ;convert to upper case
EXECHO:
RET ;and done
;***** ASCII to HEX routine *****
;
;This routine accepts an ASCII char in the ACC
;and converts it into the corresponding hex digit.
;The routine checks to see if the char is in the
;range of '0' through '9' or in the range of 'A'
;through 'F'. If not in either range then the ASCII
;char is not a valid hex entry from the operator
;and an error flag is returned true along with the
;original ASCII char returned in the ACC.
A2HEX:
JNB ACC.6,HEX1
ADD A,#09H
HEX1: ANL A,#0FH
RET
;***** HEX to ASCII routine *****
;
;This routine receives a single hex digit
;(a four bit nibble) in the ACC and returns
;the equivilent ASCII char in the ACC.
HEX2A:
ANL A,#0FH
CLR C ;carry affects the testing
SUBB A,#0AH ;test for range of 0-9, A-F
JNC HAHIGH ;no carry then A-F range
ADD A,#3AH ;add offset for 0-9 range
RET
HAHIGH:
ADD A,#41H ;add in offset for A-F range
RET
PROCESS:
MOV A,RTYPE ;get record type
RL A ;double ACC for two byte jumps
MOV DPTR,#RECTBL ;pointer = start of table
JMP @A+DPTR ;branch on record type
RECTBL:
AJMP PROGRAM ;0 = program data bytes
AJMP RDVER ;1 = read code versions
AJMP AUXWR ;2 = misc 'write' functions
AJMP AUXRD ;3 = misc 'read' functions
AJMP ERASE ;4 = erase block or page
AJMP CRCS ;5 = sector CRC
AJMP CRCG ;6 = global CRC
AJMP SETBR ;7 = set baud rate
AJMP RESET ;8 = reset MCU
AJMP DCMD ;9 = display device data
I_WDT:
MOV WDL,#0FFH ;set to max count
ORL WDCON,#0E0H ;set pre= max
FD_WDT: MOV WFEED1,#0A5H ;
MOV WFEED2,#5AH ;
RET
RDVER:
MOV A,#ISP_VER ;get ISP version id
ACALL OUTBYT ;and print it
MOV A,#VRD ;function code
CALL PGM_MTP ;and perform the function
MOV A,R7 ;get the response
ACALL OUTBYT ;and print it
AJMP EOF ;and we're done
CSEG AT MEM_TOP-256 ;Should be 1F00h
AJMP INIT ;Boot vector entry point
ERROR:
MOV A,#'R' ;print a verify error
ACALL CO ;send an okay message
MOV A,R7 ;get status
ACALL OUTBYT ;and print
AJMP DEXIT ;and done
PROGRAM:
MOV R3,NBYTES ;get the number of bytes in record
MOV A,R3 ;get the number of bytes in record
JZ EOF ;exit if no bytes in record
MOV R5,ADR0 ;get the load address
MOV R4,ADR1 ;of the first byte in record
MOV R7,#DBYTES ;pointer to data
MOV A,#PGMU ;program user code
EXEC: MOV R0,#KEY ;address for the SOFT key
MOV @R0,#KEYVAL ;setup a valid SOFT key
CLR F1 ;specify IRAM
MOV FMCON,#SET_WE ;enable HARD write
MOV FMDATA,@R0 ;set HARD key
CALL PGM_MTP ;write the entire record & verify
JB F0,ERROR ;check if an error occured
EOF: MOV A,#'.' ;no error
RSPND1:
ACALL CO ;send an okay message
AJMP DEXIT ;and done
;***** display buffer contents routine *****
;
;This routine displays the contents of the buffer memory
;over a user specified range. The displayed output is formatted
;into a series of lines on the console. A line begins with the
;address of the first byte in the line. Line length is limited
;to a maximum of 16 bytes per line. Once this limit is reached,
;new formatted lines are used.
DCMD:
MOV R0,#DBYTES ;
MOV DPH,@R0 ;get high byte of starting address
INC R0 ;point to low byte of starting address
MOV DPL,@R0 ;get low byte of starting address
INC R0 ;point to high byte of ending address
MOV ADR1,@R0 ;get high byte of ending address
INC R0 ;point to low byte of ending address
MOV ADR0,@R0 ;get low byte of ending address
INC R0 ;point to function either display or blankcheck
JNB RI,$ ;wait till host ready to receive
CLR RI
DLINE:
CJNE @R0,#00H,DAGN ;ignore this if its not a display command
ACALL CRLF
MOV R2,#10H ;R2 = 16 bytes per line
MOV A,DPH
ACALL OUTBYT
MOV A,DPL
ACALL OUTBYT ;print the address
MOV A,#'=' ;of first byte of
ACALL CO ;the line along with
DAGN:
MOV R4,DPH
MOV R5,DPL
MOV A,#RUSR ;READ_USER
CALL PGM_MTP ;read the byte
MOV A,R7 ;get result
DPRN:
CJNE @R0,#00H,BLKCHK ;ignore this if its not a display command
ACALL OUTBYT ;and print it
SJMP CKDEND ;and then check if we've reached the end
BLKCHK:
CJNE A,#00H,BLANKERR
CKDEND:
MOV A,ADR1 ;
CJNE A,DPH,DNEXT ;check if DPH = stop high
MOV A,ADR0 ;
CJNE A,DPL,DNEXT ;check if DPL = stop low
CJNE @R0,#01H,DEXIT ;if display command use display exit
AJMP EOF ;blankcheck exit (print a period)
DEXIT:
ACALL CRLF ;print a CRLF
JNB TI,$
SETB REN ;TURN ON UART RECEIVER
AJMP LCMD ;branch to main loop
DNEXT:
INC DPTR ;more bytes so point to next byte
DNXT1:
DJNZ R2,DAGN
AJMP DLINE ;we start a new line or not
BLANKERR:
MOV A,DPH
ACALL OUTBYT ;print DPH
MOV A,DPL
ACALL OUTBYT ;print DPL
AJMP DEXIT ;and exit
AUXWR:
MOV R1,#DBYTES ;pointer for data
MOV A,@R1 ;
MOV R7,A ;get the subfunction code
INC R1 ;
MOV A,@R1 ;
MOV R5,A ;get the data to write
MOV A,#MWR ;function code
AJMP EXEC ;perform the function & check for errors
ERR: AJMP ERROR ;error vector
AUXRD:
MOV R1,#DBYTES ;pointer for data
MOV A,@R1 ;
MOV R7,A ;get the subfunction code
MOV A,#MRD ;function code
CALL PGM_MTP ;and perform the function
JB F0,ERR ;exit if an error occured
MOV A,R7 ;get the response
ACALL OUTBYT ;and print it
AJMP EOF ;and we're done
ERASE:
MOV R1,#DBYTES ;pointer for data
MOV A,@R1 ;
MOV R7,A ;get the block or page erase command
INC R1 ;
MOV A,@R1 ;
MOV R4,A ;get the high address
INC R1 ;
MOV A,@R1 ;
MOV R5,A ;get the low address
MOV A,#ERS ;function code
AJMP EXEC ;perform the function & check for errors
CRCG:
MOV A,#GCRC ;function code
AJMP DO_CRC ;and do the CRC
CRCS:
MOV R1,#DBYTES ;pointer for data
MOV A,@R1 ;
MOV R7,A ;get the sector number
MOV A,#SCRC ;function code
DO_CRC:
CALL PGM_MTP ;and perform the function
JB F0,ERR ;exit if an error occured
MOV A,R4 ;get CRC bits 31:24
ACALL OUTBYT ;and print
MOV A,R5 ;get CRC bits 23:16
ACALL OUTBYT ;and print
MOV A,R6 ;get CRC bits 15:8
ACALL OUTBYT ;and print
MOV A,R7 ;get CRC bits 7:0
ACALL OUTBYT ;and print
AJMP EOF ;and we're done
CRLF: MOV A,#0DH
ACALL CO
MOV A,#0AH
ACALL CO
RET
SETBR:
MOV A,#'.' ;respond with okay status before
ACALL CO ;changing the baud rate (i.e.- at the old baud rate)
JNB TI,$ ;wait until status char (.) sent
MOV R1,#DBYTES ;pointer for data
MOV TH1,@R1 ;get baud rate
MOV TL1,@R1 ;get baud rate
AJMP LCMD ;and we're done
OUTBYT: MOV R4,A ;"push acc"
SWAP A
ACALL HEX2A
ACALL CO
MOV A,R4 ;"pop acc"
ACALL HEX2A
ACALL CO
RET
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -