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

📄 bootload.a51

📁 AT89C51CC02RSR232引导程序C51源代码
💻 A51
📖 第 1 页 / 共 2 页
字号:
hex_block_erase:
    cjne    A,#HEX_WRITE_BLOCK_ERASE,hex_write_function_error
        mov     A,security_state
        cjne    A,#SEC_LEVEL_0,hex_block_security_protected

        mov     A,hex_buffer+1                  ; get block_erase parameter
        mov     DPH,A
        mov     DPL,#00                         ; init block adress
        cjne    A,#HEX_BLOCK0_SELECT,hex_block_erase_1
        acall   erase_block_8k
        ajmp    hex_write_function_end
    hex_block_erase_1:
        cjne    A,#HEX_BLOCK1_SELECT,hex_block_erase_2
        acall   erase_block_8k
        ajmp    hex_write_function_end
    hex_block_erase_2:
        cjne    A,#HEX_BLOCK2_SELECT,hex_block_erase_3
        acall   erase_block_16k
        ajmp    hex_write_function_end
    hex_block_erase_3:
        cjne    A,#HEX_BLOCK3_SELECT,hex_block_erase_4
        acall   erase_block_16k
        ajmp    hex_write_function_end
    hex_block_erase_4:
        cjne    A,#HEX_BLOCK4_SELECT,hex_write_function_error
        acall   erase_block_16k
        ajmp    hex_write_function_end

hex_block_security_protected:
				ajmp		hex_security_protected

hex_write_function_end:
    acall   send_point
hex_write_function_error:
    ajmp    wait_hex_line


;*F***************************************************************************
; NAME:     hex_display_function        Type= 04h
;-----------------------------------------------------------------------------
; PARAMS:   hex_buffer[1:0]: start address
;           hex_buffer[3:2]: end address
;           hex_buffer[4]:   00h: display data sub-function
;                            01h: blank check sub-function
;                            02h: display eeprom sub-function
;
; RETURN:
;
;-----------------------------------------------------------------------------
; PURPOSE:  display data eeprom or blank check
;
;*****************************************************************************
hex_display_function:
    mov     A,hex_buffer+4                  ; get function parameter
    cjne    A,#01,hex_display
    
hex_blanck_check:
    mov     DPH,hex_buffer                  ; MSB of start address
    mov     DPL,hex_buffer+1                ; LSB of start address
    mov     FCON,#SEL_USER_MOVC             ; map USER in code space

hex_blanck_check_loop:
    mov     A,#00h
    movc    A,@A+DPTR
    cjne    A,#0FFh,hex_blank_check_ko
    mov     A,DPH
    cjne    A,hex_buffer+2,hex_blanck_check_next
    mov     A,DPL
    cjne    A,hex_buffer+3,hex_blanck_check_next

hex_blank_check_end:
    mov     FCON,#DESELECT_CL               ; reset FCON
    acall   send_point
    ajmp    wait_hex_line

hex_blanck_check_next:
    inc     DPTR                            ; check next address
    ajmp    hex_blanck_check_loop

hex_blank_check_ko:
    mov     R7,DPH
    acall   send_hex_byte                   ; send MSB address
    mov     R7,DPL
    acall   send_hex_byte                   ; send LSB address 
    acall   send_cr_lf
hex_display_function_error:
    ajmp    wait_hex_line

hex_display:
$if EEPROM_ON_CHIP
    cjne    A,#02,hex_display_flash_init

hex_display_eeprom_init: 
    mov     R1,#01h
    clr     A
    ajmp    hex_display_data
$endif ;EEPROM_ON_CHIP
hex_display_flash_init:
    mov	    R1, #00h

hex_display_data:
    jnz	    hex_display_function_error   
    mov     A,security_state
    cjne    A,#SEC_LEVEL_2,hex_display_data_ok

hex_security_locked:
    mov     A,#'L'
    acall   send_char
    acall   send_cr_lf
    ajmp    wait_hex_line

hex_display_data_ok:
    mov     DPH,hex_buffer                  ; MSB of start address
    mov     DPL,hex_buffer+1                ; LSB of start address
    mov	    A,R1
    jz      hex_display_flash     		
    mov     EECON,#SEL_EEPROM_CL             ; map EEPROM in xram space
    ajmp    hex_display_data_line

hex_display_flash:
    mov     FCON,#SEL_USER_MOVC             ; map USER in code space

hex_display_data_line:
    acall   send_cr_lf
    mov     R7,DPH   
    acall   send_hex_byte                   ; send MSB of current address 
    mov     R7,DPL       
    acall   send_hex_byte                   ; send LSB of current address
    mov     A,#'=' 
    acall   send_char
    mov     R0,#DISPLAY_SIZE            ; number of data to display per line

hex_display_data_loop:
    mov	    A,R1
    jz      hex_display_flash_loop
    mov     A,#00h
    movx    A,@DPTR
    ajmp    hex_display_loop	

hex_display_flash_loop: 		
    mov     A,#00h
    movc    A,@A+DPTR

hex_display_loop:
    mov     R7,A
    acall   send_hex_byte                   ; display 1 byte
    mov     A,DPH
    cjne    A,hex_buffer+2,hex_display_data_next
    mov     A,DPL
    cjne    A,hex_buffer+3,hex_display_data_next

hex_display_data_end:
    mov	    A,R1
    jz      hex_display_flash_end
    mov     EECON,#DESE_EEPROM_CL
    ajmp    hex_display_end

hex_display_flash_end:
    mov     FCON,#DESELECT_CL               ; reset FCON

hex_display_end:
    acall   send_cr_lf
    ajmp    wait_hex_line

hex_display_data_next:
    inc     DPTR
    djnz    R0,hex_display_data_loop
    ajmp    hex_display_data_line


;*F***************************************************************************
; NAME:     hex_read_function           Type= 05h
;-----------------------------------------------------------------------------
; PARAMS:   hex_buffer[0]: 00h: read id
;                               hex_buffer[1]: 00h: macnufacturer id
;                                              01h: id 1
;                                              02h: id 2
;                                              03h: id 3
;                          07h: read bytes
;                               hex_buffer[1]: 00h: read SSB
;                                              01h: read BSB
;                                              02h: read SBV
;                                              03h: read P1_CF
;                                              04h: read P3_CF
;                                              05h: read P4_CF
;                          0Bh: read hard byte (fuse + hard security bits)
;                          0Eh: read boot id
;                               hex_buffer[1]: 00h: id 1
;                                              01h: id 2
;                          0Fh: read boot loader version
;
; RETURN:
;
;-----------------------------------------------------------------------------
; PURPOSE:  read function
;
;*****************************************************************************
hex_read_function:
    mov     A,hex_buffer                        ; get function parameter
    mov     DPL,#00h

hex_read_id:
    cjne    A,#00h,hex_read_bytes
        mov     A,hex_buffer+1                  ; get read_id parameter
    hex_read_id_manufacturer:
        cjne    A,#00h,hex_read_id_1   
        mov     DPL,#MANUF_ID_ADDRESS
        ajmp    hex_read_fuction_xrow
    hex_read_id_1:
        cjne    A,#01h,hex_read_id_2   
        mov     DPL,#DEVICE_ID1_ADDRESS
        ajmp    hex_read_fuction_xrow
    hex_read_id_2:
        cjne    A,#02h,hex_read_id_3   
        mov     DPL,#DEVICE_ID2_ADDRESS
        ajmp    hex_read_fuction_xrow
    hex_read_id_3:
        cjne    A,#03h,hex_read_function_error   
        mov     DPL,#DEVICE_ID3_ADDRESS
        ajmp    hex_read_fuction_xrow

hex_read_bytes:
    cjne    A,#07h,hex_read_hardware_byte
        mov     A,hex_buffer+1                  ; get read_bytes parameter
    hex_read_bytes_ssb:
        cjne    A,#00h,hex_read_bytes_security
        mov     DPL,#SSB_ADDRESS
        ajmp    hex_read_fuction_xrow
    hex_read_bytes_security:
        mov     A,security_state                ; level 2 = read protected
        cjne    A,#SEC_LEVEL_2,hex_read_bytes_bsb_ok
        ajmp    hex_security_locked

    hex_read_bytes_bsb_ok:
        mov     A,hex_buffer+1                  ; reload sub-function parameter
        cjne    A,#01h,hex_read_bytes_sbv_ok    ; 01h -> read BSB
        mov     DPL,#BSB_ADDRESS
        ajmp    hex_read_fuction_xrow
    hex_read_bytes_sbv_ok:
        cjne    A,#02h,hex_read_bytes_p1cf_ok    ; 02h -> read SBV
        mov     DPL,#SBV_ADDRESS
        ajmp    hex_read_fuction_xrow
    hex_read_bytes_p1cf_ok:
        cjne    A,#03h,hex_read_bytes_p3cf_ok     ; 03h -> read P1_CF
        mov     DPL,#P1_CF_ADDRESS
        ajmp    hex_read_fuction_xrow
    hex_read_bytes_p3cf_ok:
        cjne    A,#04h,hex_read_bytes_p4cf_ok     ; 04h -> read P3_CF
        mov     DPL,#P3_CF_ADDRESS
        ajmp    hex_read_fuction_xrow
    hex_read_bytes_p4cf_ok:
        cjne    A,#05h,hex_read_bytes_eb_ok     ; 05h -> read P4_CF
        mov     DPL,#P4_CF_ADDRESS
        ajmp    hex_read_fuction_xrow
    hex_read_bytes_eb_ok:
        cjne    A,#06h,hex_read_function_error; 06h -> read SBV
        mov     DPL,#EB_ADDRESS
        ajmp    hex_read_fuction_xrow

hex_read_hardware_byte:
    cjne    A,#0Bh,hex_read_boot_ids
        mov     A,security_state                ; level 2 = read protected
        cjne    A,#SEC_LEVEL_2,hex_read_hardware_byte_ok
        ajmp    hex_security_locked

    hex_read_hardware_byte_ok:
        acall   fm_read_hardware_byte
        ajmp    hex_read_function_end

hex_read_boot_ids:
    cjne    A,#0Eh,hex_read_boot_version 
        mov     A,hex_buffer+1                  ; get read_boot_ids parameter
        jnz     hex_read_boot_id_2
    hex_read_boot_id_1:
        mov     A,#BOOT_ID1_VALUE
        ajmp    hex_read_function_end

    hex_read_boot_id_2:
        cjne    A,#01h,hex_read_function_error 
        mov     A,#BOOT_ID2_VALUE
        ajmp    hex_read_function_end


hex_read_boot_version:
    cjne    A,#0Fh,hex_read_function_error 
        mov     A,#BL_VERSION
        ajmp    hex_read_function_end

hex_read_fuction_xrow:
    acall   fm_read_xrow

hex_read_function_end:
    mov     R7,A
    acall   send_hex_byte
    acall   send_point
hex_read_function_error:
    ajmp    wait_hex_line


;*F***************************************************************************
; NAME:     erase_full_chip
;-----------------------------------------------------------------------------
; PARAMS:
;
; RETURN:
;
;-----------------------------------------------------------------------------
; PURPOSE:  - erase the USER memory
;           - erase the Boot Status Byte
;           - initialize the Software Boot Vector
;           - initialize the Sofware Security Byte to level 0
; 
;*****************************************************************************
erase_full_chip:

    mov     DPTR,#BLOCK0_BASE_ADDRESS
		mov			R2, #HIGH(FLASH_NB_PAGE)
    mov     R1, #LOW(FLASH_NB_PAGE)    
		cjne		R2, #02h, erase_loop_bloc_1_time ; erase in one time for flash less than 32kb

erase_loop_bloc:
    acall   erase_loop              ; erase USER
    mov     R1,#LOW(FLASH_NB_PAGE)    

erase_loop_bloc_1_time:
    acall   erase_loop              ; erase USER


    mov     DPH,#00h
    mov     FCON,#SEL_XROW_CL       ; map XROW column latch in XRAM space

    mov     DPL,#BSB_ADDRESS
    mov     A,#0FFh
    movx    @DPTR,A                 ; erase BSB

    mov     DPL,#EB_ADDRESS
    movx    @DPTR,A                 ; erase EB

    mov     DPL,#SBV_ADDRESS
    mov     A,#BOOT_BASE_ADDRESS
    movx    @DPTR,A                 ; reset BSB

    mov     DPL,#SSB_ADDRESS
    mov     A,#SEC_LEVEL_0
    movx    @DPTR,A                 ; set SSB to level 0

    acall   fm_program_xrow         ; launch programming
    ret

    
erase_block_8k:
    mov     R1,#BLOCK_8K_NB_PAGE    ; number of page to erase
    ajmp    erase_loop

erase_block_16k:
    mov     R1,#BLOCK_16K_NB_PAGE   ; number of page to erase

erase_loop:
    mov     R0,#PAGE_SIZE           ; load column latch size
    mov     A,#0FFh                 ; init value
    mov     FCON,#SEL_USER_CL       ; map USER column latch in XRAM space

erase_fill_cl:
    movx    @DPTR,A                 ; write FFh in all CL positions
    inc     DPTR
    djnz    R0,erase_fill_cl        ; loop until column latch filled

    mov     FCON,#(FPL_S0 OR FMOD_USER_MSK)  ; launch USER programming
    mov     FCON,#(FPL_S1 OR FMOD_USER_MSK)
erase_user_busy:
    mov     A,FCON
    jb      ACC.0,erase_user_busy
    djnz    R1,erase_loop
    ret



END

⌨️ 快捷键说明

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