Microcontroller › 8051 › Interfacing AT24c64 with 89c52
- This topic has 6 replies, 2 voices, and was last updated 11 years, 3 months ago by
Jenifer.
-
AuthorPosts
-
July 24, 2013 at 11:08 am #2552
Jenifer
ParticipantHi to all…
Can anyone help me to write asm codes for interfacing AT24c64 with 89c52
Can anyone help me with the sample codes. It wiil be very usefull for me….
Thanks in advance
July 26, 2013 at 12:10 pm #10219umar farrok
Participantin assembly i am not very well in that i am doing program using embedded c if you are familiar with that mean i send sample code to access smartcard i2c with controller jeni
July 29, 2013 at 6:57 am #10234Jenifer
ParticipantHi farrok,
please send your code… It will help me…
July 29, 2013 at 6:59 am #10235Jenifer
ParticipantHi…
please can any one help me…
I need to interface AT24c64 with 89c52. here is my asm code… i cannot write even 00h to eeprom.
please debug my code and guide me…org 0000h
sjmp start
start:
mov p1,#0ffh ; initializing port 1 as input
lcall none
sjmp start
none:ret
lcall write
lcall read
lcall none
;********** Write Routine*******
write:
mov r3,#00h ; mem address high ; is the address in eeprom where data will start
mov r4,#00h ;mem address low
mov r1,#00h ; byte to be send to eeprom is stored in r1
lcall bytewr
ret
bytewr:
lcall eepstart ; start to write
mov a,#0a0h ; eeprom write command
lcall send
mov a,r3
lcall send
mov a,r4
lcall send
mov a,r1
lcall send
lcall stop ;stop
ret
;********Transmission of data one by one********
send:
mov r2,#08h ; data transmission for 8 bits
bck:
rlc a
jc bck1
clr p1.1 ; if carry low clear data
setb p1.0
clr p1.0
djnz r2,bck
sjmp ack
bck1:
setb p1.1 ;if carry high set data
setb p1.0
clr p1.0
djnz r2,bck
;******** acknowledgement from eeprom*********
ack: ;ack from eeprom
setb p1.0
clr p1.0
ret
;*******read data routine********
read:
mov r3,#00h
mov r4,#00h
lcall byterd
mov r1,a
ret
byterd:
lcall eepstart ; start to read
mov a,#0a0h
lcall send
mov a,r4
lcall send
lcall stop
lcall cread
ret
cread:
lcall eepstart
mov a,#0a1h ;read command
lcall send
lcall recv
mov r1,a ; store data
lcall stop ; stop
ret
;**********receving data one by one********
recv:
mov r2,#08h
setb p1.1
rec:
clr p1.0
setb p1.0
clr c
jnb p1.1,rec1
cpl c
rec1:
rlc a
djnz r2,rec
clr p1.0
ret
;******** Start routine********
eepstart:
setb p1.1 ; high to low transistion of data with high clock
clr p1.0
setb p1.0
clr p1.1
clr p1.0
ret
; ***********Stop routine********
stop:
clr p1.1 ; low to high transistion of data with high clock
setb p1.0
setb p1.1
ret
end
Thanks in advance…
August 1, 2013 at 6:39 am #10253umar farrok
Participantuse this link you will get some idea
http://www.8051projects.net/i2c-twi-tutorial/8051-i2c-implementation.php
August 1, 2013 at 6:45 am #10254umar farrok
Participantjeni try this
CODE:;***************************************
;Ports Used for I2C Communication
;***************************************
sda equ P0.0
scl equ P0.1;***************************************
;Initializing I2C Bus Communication
;***************************************
i2cinit:
setb sda
setb scl
ret;****************************************
;ReStart Condition for I2C Communication
;****************************************
rstart:
clr scl
setb sda
setb scl
clr sda
ret;****************************************
;Start Condition for I2C Communication
;****************************************
startc:
setb scl
clr sda
clr scl
ret;*****************************************
;Stop Condition For I2C Bus
;*****************************************
stop:
clr scl
clr sda
setb scl
setb sda
ret;*****************************************
;Sending Data to slave on I2C bus
;*****************************************
send:
mov r7,#08
back:
clr scl
rlc a
mov sda,c
setb scl
djnz r7,back
clr scl
setb sda
ret;*****************************************
;ACK and NAK for I2C Bus
;*****************************************
ack:
clr sda
setb scl
clr scl
setb sda
retnak:
setb sda
setb scl
clr scl
setb scl
ret;*****************************************
;Receiving Data from slave on I2C bus
;*****************************************
recv:
mov r7,#08
back2:
clr scl
setb scl
mov c,sda
rlc a
djnz r7,back2
clr scl
setb sda
ret
? Assembly Implementation:
CODE:#define SDA P0_0
#define SCL P0_1void I2CInit(){
SDA = 1;
SCL = 1;
}void I2CStart(){
SCL = 1;
SDA = 0;
SCL = 0;
}void I2CRestart(){
SCL = 0;
SDA = 1;
SCL = 1;
SDA = 0;
}void I2CStop(){
SCL = 0;
SDA = 0;
SCL = 1;
SDA = 1;
}void I2CAck(){
SDA = 0;
SCL = 1;
SCL = 0;
SDA = 1;
}void I2CNak(){
SDA = 1;
SCL = 1;
SCL = 0;
}void I2CSend(unsigned char Data){
unsigned char i;
for(i=0;i<8;i++){
SCL = 0;
if((Data&0x80)==0)
SDA = 0;
else
SDA = 1;
SCL = 1;
Data<<=1;
}
SCL = 0;
SDA = 1;
}unsigned char I2CRead(){
unsigned char i, Data=0;
for(i=0;i<8;i++){
SCL = 0;
SCL = 1;
if(SDA)
Data |=1;
Data<<=1;
}
SCL = 0;
SDA = 1;
return Data;
}
November 12, 2013 at 5:08 am #10595Jenifer
ParticipantHi Farrok…..
thank you very much sorry for the late reply……….
-
AuthorPosts
- You must be logged in to reply to this topic.