X25045的读写程序

时间:2013-08-08 16:42 | 来源: | 点击: 次 [去老版] [去论坛] [去网店]

核心提示:

[dvnews_page]CS EQU P1.0
SI EQU P1.2
SCK EQU P1.3
SO EQU P1.1
ADDR EQU 09H
BYTE_DATA EQU 30H
COMMAND EQU 08H
MAX_POLL EQU 0AH
----------------------------  
设置写使能锁存器
----------------------------
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
325774>

(责任编辑:JQDZW)>
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
用户名: 验证码:点击我更换图片