Hi Fallowing Is My Code To Write Value 2 At Address 0x08 Of
EEProm AT24C512 Using AT89s52.
The Code Executes And No Value Is Written On ROM
Help Me Debug This.
;CODE FOR AT89S52
;EEPROM AT24C512
;WRITING VALUE 2 AT EEPROMS 0X08
;
ORG 0H
VRBLS: ;VARIABLES
SCL EQU P2.0 ;I2C CLOCK
SDA EQU P2.1 ;I2C DATA
I2CDAT EQU 28H ;I2C DATA VARIABLE
SJMP START ;GOTO START
;I2C MODULE START
I2CSTART: ;I2C START
SETB SDA
SETB SCL
NOP
NOP
CLR SDA
NOP
NOP
CLR SCL
RET
I2CSTOP: ;I2C STOP
CLR SDA
SETB SCL
NOP
NOP
SETB SDA
NOP
NOP
RET
I2CWRBT: ;I2C WRITE A BYTE
CLR SCL ;I2C CLOCK LOW
MOV SDA,47H ;SENDING MSB OF I2CDATA
ACALL I2CCLK ;I2C CLOCK
MOV SDA,46H ;SENDING NEXT BIT OF I2CDATA
ACALL I2CCLK
MOV SDA,45H
ACALL I2CCLK
MOV SDA,44H
ACALL I2CCLK
MOV SDA,43H
ACALL I2CCLK
MOV SDA,42H
ACALL I2CCLK
MOV SDA,41H
ACALL I2CCLK
MOV SDA,40H ;SENDING LSB OF I2CDATA
ACALL I2CCLK ;12C CLOCK
RET
I2CCLK: ;I2C CLOCK
SETB SCL
NOP
NOP
CLR SCL
NOP
NOP
RET
I2CACK: ;I2C ACKNOWLEDGE
CLR SCL
SETB SCL
NOP
JNB SDA,I2CAKD
CLR SCL
RET
I2CAKD:
CLR SCL
RET
;I2C MODULE END
;EEPROM MODULE START
EEWRADD: ;EEPROM ADDRESS WITH WRITE ENABLE
MOV I2CDAT,#0A6H ;SEND DEVICE ADDRESS + ENABLE WRITE
ACALL I2CWRBT
ACALL I2CACK
RET
EERDADD: ;EEPROM ADDRESS WITH READ ENABLE
MOV I2CDAT,#0A7H ;SEND DEVICE ADDRESS + ENABLE WRITE
ACALL I2CWRBT
ACALL I2CACK
RET
;EEPROM MODULE END
START:
ACALL I2CSTART ;I2C START
ACALL EEWRADD ;I2C WRITE DEVICE ADDRESS WITH WRITE OPTION
MOV I2CDAT,#0H ;I2C EEPROM ADDRESS LOCATION (1ST BYTE)
ACALL I2CWRBT ;I2C WRITE
ACALL I2CACK ;I2C ACKNOWLEDGE
MOV I2CDAT,#08H ;12C EEPROM ADDRESS LOCATION (2nd BYTE)
ACALL I2CWRBT ;I2C WRITE
ACALL I2CACK ;I2C ACKNOWLEDGE
MOV I2CDAT,#02H ;WRITE VALUE 2 TO EEPROM
ACALL I2CWRBT ;I2C WRITE
ACALL I2CACK ;I2C ACKNOWLEGE
ACALL I2CSTOP ;I2C STOP
HERE: SJMP HERE ;STAY HERE
END
---------- Post added at 15:09 ---------- Previous post was at 14:59 ----------
@Amol_Shah
Iam Using Port2 (Pins 2.0 & 2.1). They Do Have Inbuild Pullup resistors are they not enough ?
Advice Me.
I am using Proteus 7 and viewing I2c memory module window in debug mode.
Memory Location Is Not Updated (I2C Rom Memory Location 0008 Value = FF instead of 02)
Internal pull ups are not sufficient for high speed communication. Increase the delay and use pullups of 2.2k.
MOV SDA,41H?? If i am not wrong you cannot move bit data from one bit location to another directly.
do this:
MOV C,47H
MOV SDA,C
@FVM
47h = MSB bit Address of 28h. We store the value in 28h and MOV to SDA bit by bit
---------- Post added at 16:01 ---------- Previous post was at 15:54 ----------
@Amol_Shah
I Guess Bit Mov Works
Any How Now I Asaigned Those Locations as B0-B7.
And Changed The Code as MOV SDA,B0
Assembler Failed To Assemble So I Change The Code As u Advised
Now Code Is Like Below
MOV C,B0
MOV SDA,C