X5045讀寫子程序
;**************extern EEPROM constdefine******
WRENEQU 06H ;X5045 WRITE ENABLE
;WRDIEQU 04H ;X5045 write disable
RDSREQU 05H ;Read x5045 status register
WRSREQU 01H ;Write x5045 status register
READEQU 03H ;Read data from x5045 instruction
WRITE EQU 02H ;Write data to x5045 instruction
STATUSEQU 30H ;STATUS REGISTER INIT
;*********************************************************
;***********讀數(shù)據(jù)子程序********************
;數(shù)據(jù)最終在以R0間址的緩沖區(qū)中
RDX5_DAT: CLR A
RDX5_DAT0:MOV R7,#08H;8bit
RDX5_DAT1:CLR C
SETB SCK
NOP
NOP
NOP
NOP
NOP
CLR SCK ;產(chǎn)生下降邊沿
NOP
NOP
NOP
NOP
NOP
MOV C,SDO ;讀出數(shù)據(jù)
RLC A ;SO->Cy->ACC.0
DJNZ R7,RDX5_DAT1
MOV @R0,A ;數(shù)據(jù)暫存在緩沖區(qū)
INC R0
CLR ACC
DJNZ R1,RDX5_DAT0 ;未完繼續(xù)
CLR SCK
RET
;********寫數(shù)據(jù)子程序*******************
;********數(shù)據(jù)長度在 R1,數(shù)據(jù)在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
;**************讀狀態(tài)寄存器子程序
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的看門狗的時(shí)候,請(qǐng)把它給禁止掉。
;**************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