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

📄 hex.a51

📁 AT89C51CC02RSR232引导程序C51源代码
💻 A51
字号:
;*A**************************************************************************
; NAME:             hex.a51
;----------------------------------------------------------------------------
; CREATED_BY:       F. FOSSE
; COMPANY:          ATMEL-WM
; CREATION_DATE:    28/04/2001
; AUTHOR:           $author: $
; REVISION:         $version: $
; DATE:             $date: $
;----------------------------------------------------------------------------
; PURPOSE:          This file contains the routines for managing hex lines
;
;****************************************************************************
; CHANGES:
;
;****************************************************************************


$TITLE      (*** HEX Format Routines ***)

HEX_MODULE          SEGMENT     CODE 
HEX_DATA            SEGMENT     DATA

HEX_IDATA           SEGMENT     IDATA

;_____ I N C L U D E S ____________________________________________________

$include (hex_cmd.inc)


;_____ M A C R O S ________________________________________________________


;_____ D E F I N I T I O N ________________________________________________

RSEG        HEX_DATA
hex_data_size:      DS  1
hex_address:        DS  2
hex_type:           DS  1

hex_buffer:         DS  16  ; this variable must be the last in the map
                            ; and overflows in the IDATA space as its size
                            ; is in fact HEX_BUFFER_SIZE.
                            ; It is defined as DATA to help accessing
                            ; parameters in the first bytes (no indirect)

RSEG        HEX_IDATA
hex_buffer_end:     DS  (HEX_BUFFER_SIZE - 16)  ; end of hex_buffer


PUBLIC      hex_data_size, hex_address, hex_type, hex_buffer


;_____ D E C L A R A T I O N ______________________________________________

PUBLIC      get_hex_line

EXTRN       CODE (get_char, get_byte)


RSEG        HEX_MODULE

;*F***************************************************************************
; NAME:     get_hex_line
;-----------------------------------------------------------------------------
; PARAMS:
;
; RETURN:   Z:      0: hex line checksum ok (ACC= 00h)
;                   1: hex line checksum ko (ACC != 00h)
;
;-----------------------------------------------------------------------------
; PURPOSE:  get one hex line and store it in memory
;           verify cheksum
;
;-----------------------------------------------------------------------------
; NOTE:     R2 register used to store checksum
;           R0 register used as data byte counter
;           R1 register used as buffer index
;           ! get_byte routine uses R6 register
;
; HEX Type Frame:
; ":"    "lenght" "offset" "record type" "data"         "Checksum"
; 1 byte 1 byte   2 bytes    1 byte    "lenght" bytes    1 byte 
;*****************************************************************************
get_hex_line:
    acall   get_char
    cjne    a,#':',get_hex_line       ; wait synchro character

    acall   get_byte
    mov     hex_data_size,A           ; store number of data in hex line
    mov     R2,A                      ; initialize checksum

    acall   get_byte
    mov     hex_address,A             ; store MSB address
    add     A,R2
    mov     R2,A                      ; store new checksum

    acall   get_byte
    mov     hex_address+1,A           ; store LSB address
    add     A,R2
    mov     R2,A                      ; store new checksum

    acall   get_byte
    mov     hex_type,A                ; store hex line type
    add     A,R2
    mov     R2,A                      ; store new checksum

    mov     A,hex_data_size
    jz      get_hex_line_checksum     ; no data in frame
    mov     R0,A                      ; R0= number of data
    clr     C
    subb    A,#HEX_BUFFER_SIZE+1
    jnc     get_hex_end               ; line too big out with error (ACC != 0)

    mov     R1,#hex_buffer            ; R1= pointer on buffer
get_hex_line_data:
    acall   get_byte
    mov     @R1,A                     ; store byte in buffer
    inc     R1
    add     A,R2
    mov     R2,A                      ; store new checksum
    djnz    R0,get_hex_line_data

get_hex_line_checksum:
    acall   get_byte                  ; read line checksum
    add     A,R2

get_hex_end:
    ret


END

⌨️ 快捷键说明

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