以前一直用24C02,后来客户说用93LC46,本来觉得很简单,但折腾了一下午还没完成,郁闷啊。按 data sheet 写了以下程序,可是每次读出数据都为00H。还有D0好象一直低电平,那就一直BUSY吗?请各位大侠帮忙查查原因在哪里?今天内要解决,如何那位大侠愿意帮忙,留个联系方式。
;MCU:SAMSUNG S3C8XXX
;---------define-------
P1_CLK EQU 00000001B ;93LC46B clock
P1_CS EQU 00000010B ;chip select
P1_DI EQU 00000100B ;data input
P0_DO EQU 01000000B ;data output
P1_CLK_Clr EQU 11111110B
P1_CS_Clr EQU 11111101B
P1_DI_Clr EQU 11111011B
P0_DO_Clr EQU 10111111B
;-----------------------------------------------------
sub_init:
NOP
AND P1, #P1_CS_Clr ;clear CS
NOP
AND P1, #P1_DI_Clr ;clear DI
NOP
AND P1, #P1_CLK_Clr ;clear CLK
NOP
RET
;-----------------------------------------------------
sub_start:
AND P1, #P1_CLK_Clr ;clear CLK
NOP
OR P1, #P1_CS ;set CS
NOP
OR P1, #P1_DI ;set DI
NOP
OR P1, #P1_CLK ;set CLK
NOP
NOP
NOP
NOP
NOP
NOP
AND P1, #P1_CLK_Clr ;clear CLK
RET
;------------------------------------------------------
sub_write_command: ;input R1
NOP
LD R0, #8
entry0:
RLC R1
JR NC, entry1
OR P1, #P1_DI ;set DI
JR entry2
entry1:
AND P1, #P1_DI_Clr ;clear DI
entry2:
NOP
NOP
NOP
NOP
OR P1, #P1_CLK ;set CLK
NOP
NOP
NOP
NOP
AND P1, #P1_CLK_Clr ;clear CLK
DEC R0
JR NZ, entry0
NOP
RET
;-----------------------------------------------------
sub_erase_write_enable: ;EWEN :10011xxxx
NOP
CALL sub_start ;1xxxxxxxx
NOP
LD R1, #00110000B ;x0011xxxx
CALL sub_write_command
NOP
AND P1, #P1_CS_Clr ;clear CS
NOP
RET
;-------------------------------------- ;address R2; data R3 R4; R0 shift
sub_write: ;WRITE 101AAAAAA
NOP
CALL sub_start ;1xxxxxxxx
LD R0, #00111111B
AND R0, R2
RCF
ADD R0, #01000000B ;x01AAAAAA
LD R1, R0
CALL sub_write_command
NOP ;R3 R4:16 bit data
LD R1, R3
CALL sub_write_command
LD R1, R4
CALL sub_write_command
NOP
AND P1, #P1_CS_Clr
NOP
RET
;--------------------------------------------
sub_write_eeprom_data:
NOP
CALL sub_init
NOP
CALL sub_erase_write_enable
NOP
LD R2, #00H
CLR R3
LD R4, Data1
CALL sub_write
LD R2, #02H
CLR R3
LD R4, Data2
CALL sub_write
LD R2, #04H
CLR R3
LD R4, Data3
CALL sub_write
RET
;-------------------------------------------- ;input address R2; output data R3 R4; R0 shift
sub_read: ;READ 110AAAAAA
NOP
CALL sub_start ;1xxxxxxxx
LD R0, #00111111B
AND R0, R2
RCF
ADD R0, #10000000B ;x10AAAAAA
LD R1, R0
CALL sub_write_command
LD R1, #0
CALL sub_read_data
LD R3, R1
LD R1, #0
CALL sub_read_data
LD R4, R1
NOP
AND P1, #P1_CS_Clr ;clear CS
NOP
RET
;----------------------------------------------
sub_read_data:
NOP
LD R0, #8
sread0:
OR P1, #P1_CLK ;set CLK
NOP
NOP
NOP
NOP
NOP
NOP
AND P1, #P1_CLK_Clr ;clear CLK
TM P0, #P0_DO ;test D0
JP Z, sread1
SCF ;
JP sread2
sread1:
RCF
NOP
NOP
NOP
NOP
sread2:
RLC R1
DEC R0
JP NZ, sread0
NOP |