设置写使能锁存器
----------------------------
WREN: CLR SCK
CLR CS
MOV A,#COMMAND
LCALL OUT
CLR SCK
SETB CS
RET
----------------------------
复位写使能锁存器
----------------------------
WRDI: CLR SCK
CLR CS
MOV A,#COMMAND
LCALL OUT
CLR SCK
SETB CS
RET
----------------------------
写状态寄存器
----------------------------
WRSR: CLR SCK
CLR CS
MOV A,#COMMAND
LCALL OUT
CLR SCK
SETB CS
LCALL POLL
RET
----------------------------
读状态寄存器
----------------------------
RDSR: CLR SCK
CLR CS
MOV A,#COMMAND
LCALL OUT
LCALL IN
CLR SCK
SETB CS
RET
----------------------------
字节写
----------------------------
WRITE: MOV DPTR,#ADDR
CLR SCK
CLR CS
MOV A,#COMMAND
MOV B,DPH
MOV C,B.0
MOV ACC.3,C
LCALL OUT
MOV A,DPL
LCALL OUT
MOV A,#BYTE_DATA
LCALL OUT
CLR SCK
SETB CS
LCALL POLL
RET
----------------------------
字节读
----------------------------
READ: MOV DPTR,#ADDR
CLR SCK
CLR CS
MOV A,#COMMAND
MOV B,DPH
MOV C,B.0
MOV ACC.3,C
LCALL OUT
MOV A,DPL
LCALL OUT
LCALL IN
CLR SCK
SETB CS
RET
----------------------------
复位看门狗
----------------------------
DOG: CLR CS
SETB CS
RET
----------------------------
写检查
----------------------------
POLL: MOV R1,#MAX_POLL
POLL1: LCALL RDSR
JNB ACC.0,POLL2
DJNZ R1,POLL1
POLL2: RET
----------------------------
传送单字节
----------------------------
OUT: MOV R0,#08H
OUT1: CLR SCK
RLC A
MOV SI,C
SETB SCK
DJNZ R0,OUT1
CLR SI
RET
----------------------------
接收单字节
----------------------------
IN: MOV R0,#08H
IN1: SETB SCK
CLR SCK
MOV C,SO
RLC A
DJNZ R0,IN1
RET