X5045读写子程序
;**************extern EEPROM const define******
WREN EQU 06H ;X5045 WRITE ENABLE
;WRDI EQU 04H ;X5045 write disable
RDSR EQU 05H ;Read x5045 status register
WRSR EQU 01H ;Write x5045 status register
READ EQU 03H ;Read data from x5045 instruction
WRITE EQU 02H ;Write data to x5045 instruction
STATUS EQU 30H ;STATUS REGISTER INIT
;*********************************************************
;***********读数据子程序********************
;数据最终在以R0间址的缓冲区中
RDX5_DAT: CLR A
RDX5_DAT0: MOV R7,#08H ;8bit
RDX5_DAT1: CLR C
SETB SCK
NOP
NOP
NOP
NOP
NOP
CLR SCK ;产生下降边沿
NOP
NOP
NOP
NOP
NOP
MOV C,SDO ;读出数据
RLC A ;SO->Cy->ACC.0
DJNZ R7,RDX5_DAT1
MOV @R0,A ;数据暂存在缓冲区
INC R0
CLR ACC
DJNZ R1,RDX5_DAT0 ;未完继续
CLR SCK
RET
;********写数据子程序*******************
;********数据长度在 R1,数据在RO指向的地址中
WRITE_CD: CLR A
CLR C
WRITE_CD0: MOV A,@R0
MOV R7,#08H
WRITE_CD1: CLR SCK
RLC A
MOV SDI,C
CPL SCK ;SCK FOR 1 DATA IS valideation
CLR C
DJNZ R7,WRITE_CD1
INC R0 ;NEXT BYTE
DJNZ R1,WRITE_CD0
CLR SDI
RET
;**************读状态寄存器子程序
READ_STATUS: CLR A
CLR C
CLR CS
MOV A,#RDSR ;Read status register instruction
MOV R7,#08H ;
READ_ST1: CLR SCK
RLC A ;FRIST FOR MSB BIT
MOV SDI,C
SETB SCK ;Make the rising edge of clock
CLR C
DJNZ R7,READ_ST1
MOV R7,#08H
READ_ST2: CLR C
SETB SCK ;DATA FROM X5045 TO CPU by the fulling edge
NOP
NOP
NOP
NOP
NOP
CPL SCK
NOP
NOP
NOP
NOP
NOP
MOV C,SDO
RLC A ;SO->Cy->ACC.0
DJNZ R7,READ_ST2
MOV 30H,A ;DATA SAVE TO "X5045" BUFFER
CLR SCK
SETB CS
RET
另外,如果不用X5045的看门狗的时候,请把它给禁止掉。
;**************STATUS REGISTER INIT*****
ST_INIT: LCALL READ_STATUS
MOV A,30H
JB ACC.0,$-5 ;X5045 IS BUSY THEN TURN CONTIUE TO READ
MOV R0,#30H
MOV @R0,#WRSR ;WRITE STATUS REGISTER INSTRUCTION
MOV R1,#01H
CLR CS ;X5045 CHIP IS SELECTED
LCALL WRITE_CD
MOV R0,#30H
MOV @R0,#STATUS
MOV R1,#01H
LCALL WRITE_CD ;WRITE DATA TO X5045
SETB CS
RET
上一篇:X5045读写一体化C51程序包
下一篇:89C51单片机智能语音拨号报警系统的设计
推荐阅读最新更新时间:2024-03-16 15:20