Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

interface at24c02 serial eeprom

Status
Not open for further replies.

bhanot.manik90

Junior Member level 1
Joined
Jul 21, 2010
Messages
19
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,457
guys,,i want to interface at24c02 eeprom with at89s52 mc ,, can any one plz guide me about coding this in assembly language???
 

understand the I2c protocol read 24c02 eeprom data sheet and develop the code for it.
Or post your code if you have any problem.

---------- Post added at 16:23 ---------- Previous post was at 16:19 ----------

;==========================================================
; Pin Definations
;==========================================================
eeprom_scl_pin equ a4h ;scl p2.4
eeprom_sda_pin equ a5h ;sda p2.5
;==========================================================
; Main Program starts from here
;==========================================================
mov memory_address1,#00h
mov memory_address2,#00h
mov eeprom_data,#05
call write_data

mov memory_address1,#00h
mov memory_address2,#00h
call read_data
mov 5dh,3ch

loop jmp loop
;=========================================================
; Sub routines starts from here
;=========================================================
write_data call eeprom_start
mov a,#a0h
call send_data
mov a,memory_address1 ;location address
call send_data
mov a,memory_address2 ;location address
call send_data
mov a,eeprom_data ;data to be send
call send_data
call eeprom_stop
ret
;=========================================================
read_data call eeprom_start
mov a,#a0h
call send_data
mov a,memory_address1 ;location address
call send_data
mov a,memory_address2 ;location address
call send_data
call eeprom_start
mov a,#a1h
call send_data
call get_data
call eeprom_stop
ret
;=========================================================
eeprom_start setb eeprom_sda_pin
nop
setb eeprom_scl_pin
nop
nop
clr eeprom_sda_pin
nop
clr eeprom_scl_pin
ret
;=========================================================
eeprom_stop clr eeprom_sda_pin
nop
setb eeprom_scl_pin
nop
nop
setb eeprom_sda_pin
nop
clr eeprom_scl_pin
ret
;=========================================================
send_data mov r7,#00h
send rlc a
mov eeprom_sda_pin,c
call clock
inc r7
cjne r7,#08,send
setb eeprom_sda_pin
jb eeprom_sda_pin,$
; call eeprom_delay
call clock
ret
;=========================================================
get_data
mov r7,#00h
setb eeprom_sda_pin
get mov c,eeprom_sda_pin
call clock
rlc a
inc r7
cjne r7,#08,get
setb eeprom_sda_pin
call clock
mov 3ch,a
ret
;=========================================================
clock setb eeprom_scl_pin
nop
nop
clr eeprom_scl_pin
ret
;=========================================================
eeprom_delay mov 33h,#11 ;delay of 3 msec
eeprom_delay_1 mov 32h,#ffh
djnz 32h,$
djnz 33h,eeprom_delay_1
ret
;=====================================================
; Program ENDS here
;=====================================================
 
can anyone please let me know what could be the problem or error in this code (interfacing of serial eeprom at24c02 with at89s52)...i want the output to be read in hyper terminal,,so i have written the following program for that,,,plz anyone here check this out and let my know the errors in the code,,I shall be very very thankful..::::

$mod51

org 0h
main:
sda equ P2.1
scl equ P2.2

mov dpl,#00h
mov dph,#00h
mov r5,#'3'


eeprom_write:
lcall i2c_start
lcall eeprom_write_addr
lcall ack

mov a,dpl
lcall i2c_write
lcall ack

mov a,dph
lcall i2c_write
lcall ack

mov a,r5
lcall i2c_write
lcall ack

lcall i2c_stop
lcall delay


eeprom_read:
lcall i2c_start
lcall eeprom_write_addr
lcall ack

mov a,dpl
lcall i2c_write
lcall ack

lcall i2c_start

lcall eeprom_read_addr
lcall ack
lcall i2c_read
lcall no_ack

lcall i2c_stop

lcall serial


eeprom_read_addr:
mov a,#10100001b
lcall i2c_write
ret

eeprom_write_addr:
mov a,#10100000b
lcall i2c_write
ret

i2c_read:
mov r0,#8
read: setb sda
nop
setb scl
nop
mov c,sda
rrc a
clr scl
djnz r0,read

mov r6,a
ret

i2c_write:
mov r1,#8

write:
rlc a
mov sda,c
lcall clock
djnz r1,write
ret


i2c_start:
setb scl
nop
setb sda
nop
clr sda
nop
clr scl
nop
ret

i2c_stop:
setb scl
nop
clr sda
nop
setb sda
nop
clr scl
ret

clock: setb scl
nop
clr scl
nop
ret

ack: setb sda
nop
setb scl
nop
cc: jb sda,cc
clr scl
ret

no_ack: setb sda
nop
setb scl
nop
dd: jnb sda,dd
clr scl
nop
ret

delay:

loopB: mov r2,#200
loopA: mov r3,#250

nop
nop
nop
aa: djnz r3,aa
bb: djnz r2,bb


;////////////////////////////////
; INDICATE FOR SERIAL TRANSMISSION

serial: MOV TMOD,#20H ; TIMER 1 MODE 2
MOV TH1,#-3 ; FOR Baud rate
MOV SCON,#50h

main1: setb tr1 ;START TIMER

mov sbuf,r6
here:jnb ti,here
clr ti ;clear TI flag

sjmp main1
end
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top