?? f51mble3.a51
字號(hào):
mov WDTC, #00001111b ; enable reset, clear flag, refresh & start WDT
;************************************************************************
;* *
;* LOOP ROUTINE *
;* *
;************************************************************************
;* MCU sends a Query cmd(F7h) to notify the host PC that it's ready to *
;* receive pseudo IAP command and then waits indefinitely for commands. *
;* *
;************************************************************************
loop: mov a, #0F7h ; store Query cmd(0F7H ) at ACC
jnb TI, $ ; wait until end of last byte transmitting
mov SBUF, a ; send Query cmd to serial port
clr TI ; busy on transmitting...
mov B, #0 ; invalid IAP command
waitpc: jnb RI, waitpc ; wait until incoming byte is ready
mov a, SBUF ; transfer the received byte into ACC
clr RI ; ready to get next byte
mov CMD, a ; copy ACC into CMD
setb WDTC.1 ; refresh watchdog timer!
;************************************************************************
;* *
;* HAND-SHAKING ROUTINE (Pseudo IAP CMD: 05h & 55h) *
;* *
;************************************************************************
;* 1. Check the hand-shaking cmd sequence(05h & 55h) and report the *
;* status byte to host PC. *
;* 2. Continue the BSL loop routine if invalid cmd detected. *
;* *
;************************************************************************
cjne a, #05h, cmd60 ; jump to cmd60 if cmd != 05h
setb WDTC.1 ; refresh watchdog timer!
lcall INBYTE ; read a byte from serial port
cjne a, #55h, loop ; continue the loop routine if invalid
mov a, SFCF ; read SFCF to check status of MAP_EN(bit 1,0)
anl a, #00000011b ; combine SECD(bit 7,6,5) & MAP_EN(bit 1,0)
orl a, SFST ; into one byte and send to host PC
lcall OUTBYTE ; send the status byte to serial port
clr WDTC.0 ; stop WDT for valid cmd
mov WDTD, #-200 ; change to 2 seconds for Watchdog Timer
mov WDTC, #00001111b ; enable reset, clear flag, refresh & start WDT
sjmp loop ; continue the BSL loop routine
;************************************************************************
;* *
;* REPORT CHIP-ID & FW-ID ROUTINE (Pseudo IAP CMD: 60h) *
;* *
;************************************************************************
;* Host pc ask the MCU to report Chip ID and Fw ID: *
;* 1. Send the Device code: E2h for SST89C58 or E4h for SST89C54 *
;* 2. Send the fw version ID: 11h for fw v1.1 *
;* 3. Send the fw revision ID: 'E' *
;* *
;************************************************************************
cmd60: cjne a, #60h, cmd62
setb WDTC.1 ; refresh watchdog timer!
mov a, #SST89C58_ID ; Device ID of SST89C58: E2h
lcall OUTBYTE ; send Device ID to PC
mov a, #FW_Ver
lcall OUTBYTE ; send fw version to PC
mov a, #FW_Rev
lcall OUTBYTE ; send fw revision to PC
sjmp loop ; jump to loop routine
;************************************************************************
;* *
;* RUN USERCODE ROUTINE (Pseudo IAP CMD: 62h & 62h) *
;* *
;************************************************************************
;* Host PC sends this cmd to Run User Code: *
;* 1. MCU must receive two consecutive bytes: 62h & 62h. *
;* 2. Jump to resetval routine to restore SFRs reset values and to *
;* execute user code at 0000h in block 0 of flash. *
;* *
;************************************************************************
cmd62: cjne a, #62h, nop_cmd ; jump to nop_cmd routine if not 62h
lcall INBYTE ; read one more byte from serial port
cjne a, #62h, loop ; Invalid cmd sequence if 2nd byte != 62h
jnb TI,$ ; wait until last byte transmitted over
ljmp resetval ; jump to resetval routine & run usercode
;************************************************************************
;* *
;* BRANCH TO OTHER PSEUDO IAP CMD ROUTINES *
;* *
;************************************************************************
nop_cmd:cjne a, #61h, cmd2
setb WDTC.1 ; refresh watchdog timer!
ljmp loop ; CMD 61H = NOP cmd
cmd2: cjne a, #SFCM_SE, cmd3
lcall byte3
mov SFDT, #55h
lcall sector_e ; sector erase
ljmp loop
cmd3: cjne a, #SFCM_PB, cmd4
lcall byte3
lcall program_b ; program byte
ljmp loop
cmd4: cjne a, #SFCM_BP, cmd5
lcall byte3
lcall burst_p ; burst program
ljmp loop
cmd5: cjne a, #SFCM_VB, wrongcmd
lcall byte3
lcall verify_b ; verify byte
ljmp loop
wrongcmd:
ljmp loop ; continue the BSL loop routine
nop
nop
nop
sjmp $ ; software trap
;************************************************************************
byte3: lcall INBYTE ; wait 3 bytes from PC
mov ADRHI, a ; 1) input high address byte
mov DPH, a
lcall INBYTE ; 2) input low address byte
mov ADRLO, a
mov DPL, a
lcall INBYTE ; 3) input count
mov COUNT, a
mov r0, #0 ; clear r0 with no timeout
ret
;************************************************************************
nop
nop
nop
sjmp $ ; software trap
;************************************************************************
;* *
;* SERIAL COMMUNICATION SUBROUTINE (Polling Algorithm) *
;* *
;************************************************************************
OUTBYTE: ; Transmit a byte thru serial port
jnb TI, $ ; wait until end of last byte transmitting
mov SBUF, a ; store the data byte at SBUF
clr TI ; busy on transmitting...
setb WDTC.1 ; refresh watchdog timer!
ret
;========================================================================
nop
nop
nop
sjmp $ ; software trap
;========================================================================
INBYTE: ; Receive a byte from serial port
jnb RI,$ ; wait untill incoming byte is ready
mov a, SBUF ; transfer the received byte into ACC
clr RI ; ready to get next byte
setb WDTC.1 ; refresh watchdog timer!
ret
;========================================================================
nop
nop
nop
sjmp $ ; software trap
;========================================================================
;************************************************************************
; *
; Name: SECTOR ERASE ROUTINE (IAP CMD: 0Bh) *
; *
; ENTRY: (1) Starting Address (on a Sector Boundary) *
; R4 = Address Byte High *
; R5 = Address Byte Low *
; (2) Sector Count (in R6) *
; *
; RETURNS: ACC *
; *
; DESTROYED: ACC,B,R0,R1,R2,R3,R4,R5,R6 *
; *
; This routine erases the sector(s) requested, beginning from the *
; starting address provided. Notification is returned to the PC indi- *
; cating success (ACC.2 = 0) or failure (ACC.2 = 1) of this operation. *
; *
;************************************************************************
sector_e:
mov B, #SFCM_SE
mov a, CMD
cjne a, #SFCM_SE, error1
mov a, SFDT
cjne a, #55h, error2
nxtsctr:mov a, ADRHI
clr c
subb a, #0f0h
jnc error3
orl SFCF, #0C0h ; set VIS & IAPEN bits = 1
mov SFAH, ADRHI ; load high order address byte
mov SFAL, ADRLO ; load low order address byte
mov SFCM, B ; issue sector erase command
mov CMD, #04h ; mask Flash_Busy bit in done?
lcall done? ; wait for the sector erase operation
jb acc.2, exit2 ; if timeout err detected, terminate
djnz COUNT, newaddr
exit2: lcall OUTBYTE
anl SFCF, #00111111b ; VIS=IAPEN=0
mov SFDT, #0 ; any value other than 55h
mov SFAH, #0abh ; point to off-chip memory
mov SFAL, #0cdh
mov B, #0 ; invalid IAP command
ret
error1: mov a, #0C1h ; cmd is not valid Sector-Erase (0Bh)
sjmp exit2
error2: mov a, #0C2h ; SFDT is not valid 55h ( double-guard )
sjmp exit2
error3: mov a, #0C3h ; sector address points to Block1
sjmp exit2
newaddr:mov a, ADRLO
add a, #128 ; sector size of Block0 is 128
mov ADRLO, a ; low-byte address updated for next sector
mov a, ADRHI
addc a, #0
mov ADRHI, a ; high-byte address updated for next sector
sjmp nxtsctr
;========================================================================
nop
nop
nop
sjmp $ ; software trap
;========================================================================
;************************************************************************
; *
; Name: PROGRAM BYTE ROUTINE (IAP CMD: 0Eh) *
; *
; INPUTS: (1) Starting Address: *
; DPH = Address Byte High *
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -