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.

[51] How i can write and read eeprom 24c64 with at 89c52 ?

Status
Not open for further replies.

ares1998

Newbie level 1
Joined
Apr 13, 2016
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
18

Code ASM - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
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

 
Last edited by a moderator:

Hi,

Your code has some issues.
First is, that there is no description what you want to achieve.

Code:
start:
       mov p1,#0ffh   ; initializing port 1 as input
       lcall none
       sjmp start
none:ret
      lcall write
      lcall read
      lcall none
;********** Write Routine*******
This is an endless loop doing nothing. Go through it step by step.

It seems to be a bit bang I2C implementation.
Doesn't the microcontroller contain a hardware I2C?

Klaus
 

It seems to be a bit bang I2C implementation.
Doesn't the microcontroller contain a hardware I2C?

Unfortunately not, the AT89C52 offers only the basic features of an 8051/8052 variant.

@ ares1998

Besides the points mentioned by Klaus, Atmel does offer an appnote which discusses the software implementation of I2C or as Atmel refers to it as a Two Wire Interface (TWI) for interfacing the 24CXX line of serial EEPROMs.


I've attached both the appnote and assembly source code.


BigDog
 

Attachments

  • TWI-AT89.zip
    65.7 KB · Views: 56

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top