muyalrabbit
Newbie level 5
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
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