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

📄 at45d041a读写程序模块.asm

📁 at45d041a读写程序模块
💻 ASM
📖 第 1 页 / 共 2 页
字号:
sdi      equ    p1.0
sdo      equ    p1.1
sck     equ    p1.2
cs      equ    p1.3
wp      equ    p1.4
reset   equ    p1.5
rdy_bus equ    p1.6
led     equ    p0.6

data_fault      bit     00h     ;比较数据有误
buf_choice      bit     01h     ;缓冲区选择标记位,=0 选buf1;=1 选buf2


byte_add_high   data    30h     ;主存页内高位字节地址
byte_add_low    data    31h     ;主存页内低位字节地址
pagehigh        data    32h     ;主存页高位地址
pagelow         data    33h     ;主存页低位地址
block_addr      data    34h     ;块地址
status          data    36h     ;状态数据缓冲区
sent_data_len   data    38h     ;发送数据长度
read_data_len   data    39h     ;读取数据长度
com_page_buf1   data    3ah
com_page_buf2   data    3bh

sent_data_addr  data    40h     ;发送数据缓冲区首址
read_data_addr  data    80h     ;读取数据缓冲区首址


org 0000h
ljmp main

org 0100h
main:       mov r0,#0ffh           ;初始化全部ram
            mov a,#00h
main_lop1:  mov @r0,a
            djnz r0, main_lop1
            mov sent_data_len,#128   ;向发送数据缓冲区写入数据
            mov r0,#sent_data_addr
            mov a,#01h
main_lop:   mov @r0,a
            inc r0
            inc a
            djnz sent_data_len, main_lop
            clr led
            clr buf_choice         ;选择buffebit_num
            mov sent_data_len,#128
            mov byte_add_high,#00h
            mov byte_add_low,#00h
            acall write_to_buffer
            mov pagehigh,#07h
            mov pagelow, #0feh
            acall write_buffer_to_page
            mov read_data_len,#128
            mov pagehigh,#07h
            mov pagelow, #0feh
            mov byte_add_high,#00h
            mov byte_add_low,#00h
            acall read_data_array
            acall compare
            sjmp $

;-----------------------------------------------------
; name:   sent_one_bit
; func:   从MCU发送一个位
; calls:  none
; Inpara: c
; outpara: none
; register usage:  c
;-----------------------------------------------------
sent_one_bit:
             clr sck
             mov sdi,c
             setb sck
             clr sck
             ret
;-----------------------------------------------------
; name:   sent_one_byte
; func:   从MCU发送一个字节
; calls:  sent_one_bit
; Inpara: A(要发送的数据)
; outpara: none
; register usage:  A, c ,r1
;-----------------------------------------------------
sent_one_byte:
              mov r1,#8         ;循环发送8个位
s_o_b_lop:    rlc a
              acall sent_one_bit
              djnz r1, s_o_b_lop
              ret
;-----------------------------------------------------
; name:   read_one_bit
; func:   从flash rom 读取一个位
; calls:  none
; Inpara: none
; outpara: c
; register usage:   c
;-----------------------------------------------------
read_one_bit:
             clr sck
             setb sck
             setb sdo
             mov c,sdo
             clr sck
             ret
;-----------------------------------------------------
; name:   read_one_byte
; func:   从flash rom 读取一个字节
; calls:  read_one_bit
; Inpara: none
; outpara: A(接收到的一个字节数据)
; register usage:  A, c, r1
;-----------------------------------------------------
read_one_byte:
              mov r1,#8
r_o_b_lop:    acall read_one_bit
              rlc a
              djnz r1, r_o_b_lop
              ret
;-----------------------------------------------------
; name:   write_buffer_to_page
; funct:  把buffer1 或 buffer2中的数据输入到选中的主存页中
; calls:  sent_one_byte , adjust_addr
; InPare: pagehigh, pagelow
; OutPare: None
; register usage:  r0,r1,a,c
;----------------------------------------------------
write_buffer_to_page:
              acall read_status      ;读取busy,
              mov a,status
              rlc a
              jnc write_buffer_to_page
              clr sck                 ;准备写入flashrom
              clr cs                  ;SPI mode0 ,片选有效
              nop
              nop
              nop
              mov a,#83h              ;选择buffer1
              jnb buf_choice,wr_buf_page
              mov a,#86h              ;选择buffer2
wr_buf_page:  acall sent_one_byte     ;送写buffer指令
              acall adjust_addr
              mov a,pagehigh          ;送主存页高4位地址
              acall sent_one_byte
              mov a,pagelow           ;送主存页8位地址
              acall sent_one_byte
              acall sent_one_byte     ;送don't care bit
              setb cs                 ;片送无效
              ret
;-----------------------------------------------------
; name:   write_to_buffer
; funct:  把MCU缓冲区数据输入到buffer1 或 buffer2中
; calls:  sent_one_byte, adjust_addr
; InPare: buf_choice, byte_add_high,byte_add_low, sent_data_addr, sent_data_len
; OutPare: None
; register usage:  r0,r1,r2,a,c
;----------------------------------------------------
write_to_buffer:
              acall read_status    ;读取busy,
              mov a,status
              rlc a
              jnc write_to_buffer
              clr sck              ;准备写buffer
              clr cs               ;SPI mode0 ,片选有效
              nop
              nop
              nop
              mov a,#84h            ;选择buffer1
              jnb buf_choice,wr_buf_lop
              mov a,#87h            ;选择buffer2
wr_buf_lop:   acall sent_one_byte   ;送写buffer指令
              acall adjust_addr
              acall sent_one_byte   ;don't care bit
              mov a,byte_add_high   ;发送don't care bit and buffer 高1位
              acall sent_one_byte
              mov a,byte_add_low    ;写入buffer地址
              acall sent_one_byte

              mov r2,sent_data_len   ;发送数据长度
              mov r0,#sent_data_addr ;发送数据缓冲区首址
wr_buf_lop1:  mov a,@r0
              acall sent_one_byte    ;开始发送数据
              inc r0
              djnz r2, wr_buf_lop1
              setb cs                ;片送无效
              ret
;-----------------------------------------------------
; name:   read_data_array
; funct:  把flashrom 中的指定页数据读到MCU的读入缓冲区中
; calls:  sent_one_byte , read_one_byte , adjust_addr
; InPare: read_data_addr, read_data_len
;         pagehigh, pagelow, byte_add_high, byte_add_low
; OutPare: None
; register usage:  r0,r1,r2,A,C
;----------------------------------------------------
read_data_array:
              acall read_status       ;读取busy,
              mov a,status
              rlc a
              jnc read_data_array
              clr sck                 ;准备写buffer
              clr cs                  ;SPI mode0 ,片选有效
              nop
              nop
              nop
              mov a,#0e8h              ;送读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

              mov r2,read_data_len
              mov r0,#read_data_addr
r_data_lop:   acall read_one_byte
              mov @r0,a
              inc r0
              djnz r2,r_data_lop
              setb cs
              ret
;-----------------------------------------------------
; name:   main_page_read
; funct:  把页主存中的数据读到MCU中
; calls:  sent_one_byte , read_one_byte
; InPare: pagehigh, pagelow , byte_addr
; OutPare:
; register usage:  r0,r1,r2,A,C
;----------------------------------------------------
main_page_read:
              acall read_status       ;读取busy,
              mov a,status
              rlc a
              jnc main_page_read

⌨️ 快捷键说明

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