📄 at45d041a读写程序模块.asm
字号:
clr sck
clr cs
nop
nop
nop
mov a,#0d2h ;送读flashrom指令
acall sent_one_byte
acall adjust_addr
mov a,pagehigh
acall sent_one_byte
mov a,pagelow
acall sent_one_byte
mov a, byte_add_low
acall sent_one_byte
acall sent_one_byte ;sent don't care bit
acall sent_one_byte
acall sent_one_byte
acall sent_one_byte
nop
nop
nop
mov r2,read_data_len
mov r0,#read_data_addr
main_pag_lop: acall read_one_byte
mov @r0,a
inc r0
djnz r2,main_pag_lop
setb cs
ret
;-----------------------------------------------------
; name: main_to_buffer
; funct: 把页主存中的数据读到buffer1 or buffer2中
; calls: sent_one_byte
; InPare: pagehigh, pagelow , buf_choice
; OutPare:
; register usage: r1,A,C
;----------------------------------------------------
main_to_buffer:
acall read_status ;读取busy,
mov a,status
rlc a
jnc main_to_buffer
clr sck
clr cs
nop
nop
nop
mov a,#53h ;选择buffer1
jnb buf_choice,main_buf_lop
mov a,#85h ;选择buffer2
main_buf_lop: acall sent_one_byte
acall adjust_addr
mov a,pagehigh
acall sent_one_byte
mov a,pagelow
acall sent_one_byte
acall sent_one_byte ;don't care
setb cs
ret
;-----------------------------------------------------
; name: buffer_read
; funct: 把buffer1 or buffer2中的数据读到MCU
; calls: sent_one_byte,read_one_byte
; InPare: buf_choice, read_data_len, read_data_addr
; byte_add_high , byte_add_low
; OutPare: none
; register usage: r1,A,C
;----------------------------------------------------
buffer_read:
acall read_status ;读取busy,
mov a,status
rlc a
jnc main_to_buffer
clr sck
clr cs
nop
nop
nop
mov a,#0d4h ;选择buffer1
jnb buf_choice,buffer_rd
mov a,#0d6h ;选择buffer2
buffer_rd: acall sent_one_byte
acall adjust_addr
acall sent_one_byte
mov a,byte_add_high
acall sent_one_byte
mov a,byte_add_low
acall sent_one_byte
acall sent_one_byte
mov r2,read_data_len
mov r0,#read_data_addr
buffer_rd_lop:
acall read_one_byte
mov @r0,a
inc r0
djnz r2,buffer_rd_lop
setb cs
ret
;-----------------------------------------------------
; name: page_erase
; funct: 擦除一页
; calls: sent_one_byte,adjust_addr
; InPare: pagehigh, pagelow
; OutPare:
; register usage: r1,A,C
;----------------------------------------------------
page_erase:
acall read_status ;读取busy,
mov a,status
rlc a
jnc page_erase
clr sck
clr cs
nop
nop
nop
mov a,#81h
acall sent_one_byte
acall adjust_addr
mov a,pagehigh
acall sent_one_byte
mov a,pagelow
acall sent_one_byte
acall sent_one_byte
setb cs
ret
;-----------------------------------------------------
; name: block_erase
; funct: 擦除一块
; calls: sent_one_byte
; InPare: block_addr
; OutPare: none
; register usage: r1,r2,A,C
;----------------------------------------------------
block_erase:
call read_status ;读取busy,
mov a,status
rlc a
jnc block_erase
clr sck
clr cs
nop
nop
nop
mov a,block_addr ;调整块地址
swap a
mov r2,a
anl a,#0f0h
mov block_addr,a
mov a,r2
anl a,#0fh
mov r2,a
mov a,#50h ;发送擦除块命令
acall sent_one_byte
mov a,r2 ;发送擦除块高位地址
acall sent_one_byte
mov a,block_addr ;发送擦除块低位地址
acall sent_one_byte
acall sent_one_byte
ret
;-----------------------------------------------------
; name: read_status
; funct: 把flashrom 中status register
; calls: sent_one_byte , read_one_byte
; InPare: none
; OutPare: status
; register usage: r1,A,C
;----------------------------------------------------
read_status:
clr sck
clr cs
nop
nop
mov a,#0d7h
acall sent_one_byte
acall read_one_byte
mov status,a
setb cs
ret
;-----------------------------------------------------
; name: compare
; funct: 把flashrom 中的指定页数据与buffer1 or buffer2作比较
; calls: sent_one_byte , read_one_byte
; InPare: buf_choice
; OutPare: data_fault
; register usage: r0,r1,r2,A,C
;----------------------------------------------------
compare:
clr sck
clr cs
nop
nop
nop
mov a,#60h
jnb buf_choice,comp
mov a,#61h
comp: acall sent_one_byte
mov a,pagehigh
acall sent_one_byte
mov a,pagelow
acall sent_one_byte
nop
nop
acall sent_one_byte
setb cs
comp_lop: acall read_status
mov a,status
rlc a
jnc comp_lop
rlc a
jnc comp_ret
setb data_fault
comp_ret: ret
;-----------------------------------------------------
; name: adjust_addr
; funct: 调整页地址、页内字节地址、buffer地址
; calls: none
; InPare: pagehigh, pagelow, byte_add_high, byte_add_low
; OutPare: pagehigh, pagelow, byte_add_high, byte_add_low
; register usage: A,C
;----------------------------------------------------
adjust_addr:
clr c
mov a,pagelow
rlc a
mov pagelow,a
mov a,pagehigh
rlc a
mov pagehigh,a
mov a,pagelow
orl a,byte_add_high
mov pagelow,a
mov byte_add_high,a
ret
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -