[SOLVED] Writing To EEPROM AT24c512 using AT89s52

Status
Not open for further replies.

muyalrabbit

Newbie level 5
Joined
Sep 10, 2011
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,341
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
 

Code File Is Attached In Text Format For Readability
 

Attachments

  • I2C.txt
    1.8 KB · Views: 133

Help Me To Find The Problem In My Code
 

You are checking on hardware or in simulation?
I am poor at assembly language.
 

Are you using pullup resistors for the SCL & SDA lines? Increase the delay just two nop instructions will not work.
 
@Kirangowle
Iam using Proteus 7 Simulator

---------- 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)
 

I don't understand what you're doing here. What's send to SDA (P2.1)?

Code:
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
 

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

Thank You
 

do this:
MOV C,47H
MOV SDA,C
Yes, I'm not aware of a bit to bit MOV instruction of 8051. The original instruction is misunderstood as a MOV direct, direct byte move.

RLC A would be more economic method to output the bits.
 
Proteus File And Code Attached
 

Attachments

  • EEProm.zip
    14.7 KB · Views: 146
  • I2C.txt
    3.5 KB · Views: 108
  • I2C.txt
    1.8 KB · Views: 102

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…