📄 bootload.asm
字号:
bra TestNext
Write2Blocks ; Program one HEX line (2 blocks)
rcall SetPointers
rcall WriteBlock ; Write 2 blocks (16 bytes)
rcall WriteBlock
VerifyWrite ; Verify the data
rcall SetPointers
VerifyNext ; Compare
tblrd *+
movf POSTINC2, W
xorwf TABLAT
bnz GeneralErr ; Stop if bad verify
decfsz COUNTER
bra VerifyNext
bra StartOfLine ; Go get the next line of data
; *****************************************************************************
; *****************************************************************************
WriteIDLocations
movff ADDRESS_UL, TBLPTRU
rcall SetPointers
rcall WriteBlock
bra StartOfLine
; *****************************************************************************
; *****************************************************************************
WriteConfig
movlw b'11000100' ; Setup to write fuses
movwf EECON1
rcall SetPointers
movff ADDRESS_UL, TBLPTRU
movff DATACNT, COUNTER
WriteNextConfig
movf POSTINC2, W
movwf TABLAT
tblwt *
rcall StartWrite ; Initiate a write
tblrd *+
decfsz COUNTER, F
bra WriteNextConfig
bra StartOfLine
; *****************************************************************************
; *****************************************************************************
WriteEEPROM
movlw b'00000100' ; Setup to write DataEE
movwf EECON1
rrcf ADDRESS_H, W
rrcf ADDRESS_L, W
movwf EEADR
rcall SetPointers
movlw 0x08
movwf COUNTER
WriteNextEE
movff POSTINC2, EEDATA ; Load the data
movf POSTINC2, W
rcall StartWrite ; Initiate a write
btfsc EECON1, WR ; Wait for the write to finish
bra $ - 2
incf EEADR, F
decfsz COUNTER, F
bra WriteNextEE
bra StartOfLine
; *****************************************************************************
; *****************************************************************************
; Reset pointers to program mem and data mem.
_F_SET_PNTR CODE
SetPointers
movff ADDRESS_H, TBLPTRH ; Reset pointer
movff ADDRESS_L, TBLPTRL
lfsr 2, DATA_BUFF
movlw 0x10 //长度为16字节
movwf COUNTER
return
; *****************************************************************************
; *****************************************************************************
; Write a byte to the serial port.
_F_WRT_RS232 CODE
WrRS232
btfss PIR1, TXIF ; Write only if TXREG is ready
bra WrRS232
movwf TXREG
return
; *****************************************************************************
; *****************************************************************************
; Get a character from the serial port.
_F_GET_CHAR CODE
GetChar
btfss PIR1, RCIF
bra GetChar ; Retry if no data
movf RCREG, W ; Condition the data
bcf WREG, 7
movwf RXDATA
; rcall WrRS232 ; Debug, echo data back
return
; *****************************************************************************
; *****************************************************************************
; Get a byte of data from the serial port.
_F_GET_BYTE CODE
GetByte
rcall GetChar ; Get a character
rcall Ascii2Hex ; Convert to hexdecimal
swapf RXDATA, W
movwf TEMP1
rcall GetChar ; Get the next character
rcall Ascii2Hex ; Convert to hexdecimal //字符和16进制之间的转换函数
movf TEMP1, W
iorwf RXDATA, W ; Assemble the two nibbles //功能从传口收到的字符转换成16进制数 此字节内容HEX的一个 记录长度
return
; *****************************************************************************
; *****************************************************************************
; Convert ASCII to HEX.
_F_ASCII_HEX CODE
Ascii2Hex ; Convert ASCII to Hexdecimal
movlw '0' //0-9的ACII2码为30-39
subwf RXDATA
movlw 0xF0
andwf RXDATA, W
bz A2HDone ; If no upper nibble then number only
movlw 'A'-'0'-0x0A ; else get the letter
subwf RXDATA, F
A2HDone return
; *****************************************************************************
; *****************************************************************************
; Write a block of data to program memory.
_F_WRT_BLOCK CODE
WriteBlock
movlw 0x08
Lp1 movff POSTINC2, TABLAT ; Load the holding registers
tblwt *+
decfsz WREG, F
bra Lp1
tblrd *- ; Point back into the block
movlw b'10000100' ; Setup writes
movwf EECON1
rcall StartWrite ; Write the data
tblrd *+ ; Point to the beginning of the next block
return
; *****************************************************************************
; *****************************************************************************
; Unlock and start the write or erase sequence.
_F_START_WRITE
StartWrite
movlw 0x55 ; Unlock
movwf EECON2
movlw 0xAA
movwf EECON2
bsf EECON1, WR ; Start the write
nop
return
; *****************************************************************************
; *****************************************************************************
; Automatic block aligning function with padding
;WriteBlock
; call FlushBuffer
;
; movlw 0x07 ; Determine how much of the block to write
; andwf TBLPTRL, W
;
; comf WREG, F
; andlw 0x07
; incf WREG, F
;
;Lp1 movff POSTINC2, TABLAT ; Load the holding registers
; tblwt *+
; decfsz WREG, F
; bra Lp1
;
; tblrd *- ; Point back into the block
;
; rcall StartWrite ; Write the data
;
; tblrd *+ ; Point to the beginning of the next block
;
; return
;
; *****************************************************************************
; *****************************************************************************
;FlushBuffer ; Clear any data in the holding registers
;
; movff TBLPTRL, PRODL ; Copy the LSB of the pointer
;
; clrf TBLPTRL
; setf TABLAT
; movlw 0x08 ; Clear the buffer
;Lp2 tblwt *+
; decfsz WREG, F
; bra Lp2
;
; movff PRODL, TBLPTRL ; Restore the LSB of the pointer
;
; return
; *****************************************************************************
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -