AT93C46/56/57/66 EEPROM 芯片通用读写程序
扫描二维码
随时随地手机看文章
AT93C46/56/57/66 EEPROM 芯片通用读写程序
;模块包含:READ(读),WRITE(写),WRAL(片写),ERASE(擦除),ERAL(片擦除),
;EWEN(擦写允许),EWDS(擦写禁止).
;此模块适用于:AT93C46/56/57/66EEPROM芯片,8位(ORG=0)或16位(ORG=1)的读、写、
;擦除等操作。
;8位或16操作,只需置标志位SIZE为"0"或为"1"和设置NADDR的位即可,非常方便实用。
;93C4693C5693C5793C66
;----------------------------------------------------------------------------
;Databits:816816816816
;Addressbits:76988798
;----------------------------------------------------------------------------
NADDREQU7;8-bitdata,地址为7位
;NADDREQU6;16-bitdata,地址为6位
SIZEEQUF0;0=8-bitdata,1=16-bitdata标志位
DATA_LOEQU2AH;数据低字节
DATA_HIEQU2BH;数据高字节
ADDR_LOEQU2CH;地址低字节
ADDR_HIEQU2DH;地址高字节
DATA01EQU30H;数据缓存区首址
CSBITP1.0;AT93Cxx片选端
SKBITP1.1;时钟信号输入端
DIBITP1.2;串行数据输入端
DOBITP1.3;串行数据输出端
DSEGAT20H
ORG60H;stackorigin
STACK:DS20H;stackdepth
CSEG
ORG0000H;
JMPON_RESET
ORG0003H
reti
ORG000BH
reti
ORG0013H
reti
ORG001BH
reti
ORG0023H
reti
ORG0080H
USING0;选择工作寄存器0
ON_RESET:
MOVSP,#(STACK-1)
CLRCS;LOW
CLRSK;LOW
SETBDI;HIGH
SETBDO;HIGH
CLRSIZE;SPECIFY8-BITDATA
;SETBSIZE;SPECIFY16-BITDATA
JBSIZE,DATA16;SIZE=1时,为16-bit操作
AJMPDATA8
;==========================================================
;8-bitByte(SIZE/ORG=0)程序操作演示
DATA8:
CALLByte_read;读出数据,以便观察
CALLEWEN;擦写允许
MOVADDR_LO,#0;地址
MOVDATA_LO,#33H;数据
CALLWRITE;指定地址写
CALLByte_read
CALLERAL;片擦除(全部单元置"1")
CALLByte_read
;8-bit片写,将芯存储器全部写入55H的数据
;CALLEWDS;擦写禁止
MOVDATA_LO,#55H;片写数据(片写之前最好片擦除)
CALLWRAL;片写
AJMPDATA8
;==========================================================
;==========================================================
;16-bitWord(SIZE/ORG=1)程序操作演示
DATA16:
CALLWord_read;读8个单元数据,观察
CALLEWEN;擦写允许
CALLERAL;片擦除(全部单元置"1")
CALLWord_read
MOVADDR_LO,#0;向指定地址写数据
MOVDATA_LO,#55H;DATA,数据低字节
MOVDATA_HI,#0AAH;DATA,数据高字节
CALLWRITE;指定地址写
CALLWord_read
;将芯片存储器全部写入0AAH(高)和55H(低)的数据
MOVDATA_LO,#55H;DATA
MOVDATA_HI,#0AAH;DATA
CALLWRAL;
CALLWord_read
;CALLEWDS;擦写禁止
;将指定单元的内容擦除(置为"1")
MOVADDR_LO,#0;
CALLERASE;将指定单元(00H01H)擦为"1"
AJMPDATA16
;==========================================================
;读Read(byteifSIZE/ORG=0,wordifSIZE/ORG=1).
Byte_read:
MOVR0,#DATA01;缓存区首址
MOVADDR_HI,#0
MOVADDR_LO,#0;指向AT93CXX首址
MOVR7,#8;字节数
READ01:
CALLREAD
MOVA,DATA_LO
MOV@R0,A
INCR0
INCADDR_LO
DJNZR7,READ01
RET
;==========================================================
;读Read(wordifSIZE/ORG=1).低地址为低字节单元,高地址为高字节单元
Word_read:
MOVR0,#DATA01;缓存区首址
MOVADDR_LO,#0
MOVR7,#8;字节数
WORD01:
CALLREAD;读数据
MOVA,DATA_LO;低字节内容
MOV@R0,A
INCR0
MOVA,DATA_HI;高字节内容
MOV@R0,A
INCR0
INCADDR_LO
DJNZR7,WORD01
RET
;----------------------------------------------------------
;==========================================================
;名称:读指令(READ指令)
;功能:从指定的地址单元中把数据读出
;----------------------------------------------------------
READ:
SETBCS;片选置1
MOVDPL,#110B;起始位和操作码"110"
MOVB,#3
CALLOUTDATA
MOVDPL,ADDR_LO;低字节地址
MOVDPH,ADDR_HI;高字节地址
MOVB,#NADDR;地址位数(8-bitdata,NADDR=7)
CALLOUTDATA;输出读/写单元地址
CALLINDATA
CLRCS
RET
;==========================================================
;名称:写指令(WRITE指令)
;功能:将数据写入到指定的地址单元中
;----------------------------------------------------------
WRITE:
SETBCS;
MOVDPL,#101B;起始位和操作码"101B"
MOVB,#3;位数
CALLOUTDATA;输出数据
MOVDPL,ADDR_LO
MOVDPH,ADDR_HI
MOVB,#NADDR
CALLOUTDATA
MOVDPL,DATA_LO
JBSIZE,EE61;SIZE=0时,8bit;SIZE=1时,16bit;
MOVB,#8
JMPEE62
EE61:
MOVDPH,DATA_HI
MOVB,#16
EE62:
CALLOUTDATA
CLRCS
CALLSTATUS;延时10ms
RET
;==========================================================
;名称:片写指令(WRAL指令)
;功能:将命令中指定的数据写入整个存贮器阵列
;----------------------------------------------------------
WRAL:
SETBCS;片选置1,选中芯片
MOVDPTR,#(10001BSHL(NADDR-2))
MOVB,#(NADDR+3)
CALLOUTDATA
MOVDPL,DATA_LO
JBSIZE,EE71;SIZE=0时,8bit;SIZE=1时,16bit;
MOVB,#8
JMPEE72
EE71:
MOVDPH,DATA_HI
MOVB,#16
EE72:
CALLOUTDATA
CLRCS
CALLSTATUS;延时10ms
RET
;==========================================================
;名称:地址擦指令(ERASE指令)
;功能:将指定地址中所有数据位都为置为"1"
;----------------------------------------------------------
ERASE:
SETBCS
MOVDPTR,#111B;擦除指令操作码"111B"
MOVB,#3
CALLOUTDATA
MOVDPL,ADDR_LO;地址低位
MOVDPH,ADDR_HI;地址高位
MOVB,#NADDR;
CALLOUTDATA
CLRCS
CALLSTATUS;延时10ms
RET
;==========================================================
;名称:片擦指令(ERAL指令),
;功能:将整个存储器阵列置为"1"
;----------------------------------------------------------
ERAL:
SETBCS
MOVDPTR,#(10010BSHL(NADDR-2));左移
;ERAL指令操作码和地址为:10010B
MOVB,#(NADDR+3)
CALLOUTDATA
CLRCS
CALLSTATUS;延时子程序
RET
;==========================================================
;名称:擦/写允许(EWEN指令)
;功能:AT93CXX在上电复位后,芯片处于擦/写不允许状态,
;EWEN指令将芯片置为可编程状态,即可擦/写
;----------------------------------------------------------
EWEN:
SETBCS
MOVDPTR,#(10011BSHL(NADDR-2));将10011B向左移((NADDR-2)位
;EWEN指令:操作码的地址为:10011B
MOVB,#(NADDR+3)
CALLOUTDATA
CLRCS
RET
;==========================================================
;名称:擦/写禁止(EWDS指令)
;功能:使用该指令可对写入的数据进行保护,操作步骤与擦/写允许指令相同.
;----------------------------------------------------------
EWDS:
SETBCS
MOVDPTR,#(10000BSHL(NADDR-2))
MOVB,#(NADDR+3)
CALLOUTDATA
CLRCS
RET
;==========================================================
;延时子程序
;----------------------------------------------------------
STATUS:
PUSHB
SETBDO;FLOATPIN
SETBCS
MOVB,#220;220*50us=11ms
EE40:
PUSHB;2us
MOVB,#22;2us
DJNZB,$;2us*22
POPB;2us
JBDO,EE41
DJNZB,EE40
SETBC
JMPEE42
EE41:
CLRC
EE42:
CLRCS
POPB
RET
;==========================================================
INDATA:
SETBDO
CALLSHIN
JNBSIZE,EE21;SIZE=0时,8bit;SIZE=1时,16bit
MOVDATA_HI,A;SAVEHIGHBYTE
;SIZE=1时,16bit
CALLSHIN
EE21:;SIZE=0时,8bit
MOVDATA_LO,A;SAVELOWBYTE
RET
;==========================================================
;读一个字节子程序,读回的数据在A中
;----------------------------------------------------------
SHIN:
PUSHB
CLRSK
MOVB,#8
EE30:
SETBSK
NOP
MOVC,DO
RLCA
CLRSK
DJNZB,EE30
POPB
RET
;==========================================================
;向AT93CXX写入地址
;----------------------------------------------------------
OUTDATA:
PUSHB
MOVA,B
CLRC
SUBBA,#8
JCEE6
JZEE5
MOVB,A
CLRC
SUBBA,#8
JCEE2
JNZEE9
MOVA,DPH
JMPEE4
EE2:
PUSHB
MOVA,DPH
EE3:
RRA
DJNZB,EE3
POPB
EE4:
CALLSHOUT
MOVB,#8
EE5:
MOVA,DPL
JMPEE8
EE6:
PUSHB
MOVA,DPL
EE7:
RRA
DJNZB,EE7
POPB
EE8:
CALLSHOUT
EE9:
SETBDO
POPB
RET
;==========================================================
;写一个字节子程序
;入口:写入数据须事先存入A中.
;----------------------------------------------------------
SHOUT:
EE50:
CLRSK
RLCA
MOVDI,C
NOP;DELAYMIN400ns
SETBSK
DJNZB,EE50
CLRSK
RET
;==========================================================
;==========================================================
END