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.

Interfacing 89c52 with AT24c64

Status
Not open for further replies.

Jenifer a

Newbie level 6
Newbie level 6
Joined
Jul 23, 2013
Messages
14
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
118
Hi to All...

I need to interface AT24c64(EEPROM) with 89c52 using assebly language,
I need to write asm code for the following

1. load address in 89c52

2. load new address in AT24c64

3. load some values in that new address of eeprom

4. read the stored values

5.display the stored values

Can anyone hell me please... please give me your sample code regarding this...

Thanks in advance..
 

Hi...

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


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



Thanks in advance...
 
Last edited by a moderator:

Try to implement this C code in asm. You need I2C to commuicate with eeprom 24LCxxx.


Code C - [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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#include<reg51.h>
#include<stdio.h>
#include<intrins.h>
 
#define ACK      1
#define NO_ACK   0
 
 
 
unsigned char i;
unsigned char EData[5];
unsigned char Data;
void InitSerial(void);
void DelayMs(unsigned int);
void WriteI2C(unsigned char);
void Start(void);
void Stop(void);
void ReadBYTE(unsigned int);
void WriteBYTE(unsigned int);
unsigned char ReadI2C(bit);
 
sbit SCL = P2^0;    // connect to SCL pin (Clock)
sbit SDA = P2^1;    // connect to SDA pin (Data)
 
 
 
//---------------------------------------
// Main program
//---------------------------------------
void main(void)
{
    InitSerial();        // Initialize serial port
    putchar(0x0C);        // clear hyper terminal
    DelayMs(5);
    WriteBYTE(0x0000);
    WriteI2C('A');        //Write Data's Here
    WriteI2C('B');
    WriteI2C('C');
    WriteI2C('D');  
    WriteI2C('E');
    WriteI2C('F');  
    Stop(); 
    DelayMs(10);
 
    ReadBYTE(0x0000);
    EData[0] = ReadI2C(NO_ACK);   
    EData[1] = ReadI2C(NO_ACK);   
    EData[2] = ReadI2C(NO_ACK);   
    EData[3] = ReadI2C(NO_ACK);   
    EData[4] = ReadI2C(NO_ACK);   
    EData[5] = ReadI2C(NO_ACK);
 
    for(i=0;i<6;i++)
    {
    printf("value = %c\n",EData[i]);   // display data        */
    DelayMs(100);
    }
 
    while(1);
}
 
 
//-------------------------------
// start I2C
//-------------------------------
void Start(void)
{
   SDA = 1;
    SCL = 1;
    _nop_();_nop_();
    SDA = 0;
    _nop_();_nop_();
    SCL = 0;
    _nop_();_nop_();
}
 
//-------------------------------
// stop I2C
//-------------------------------
void Stop(void)
{
    SDA = 0;   
    _nop_();_nop_();
    SCL = 1;
    _nop_();_nop_();
    SDA = 1;
}
 
//-------------------------------
// Write I2C
//-------------------------------
void WriteI2C(unsigned char Data)
{  
 
    for (i=0;i<8;i++)
    {
       SDA = (Data & 0x80) ? 1:0;
         SCL=1;SCL=0;
         Data<<=1;
    }
 
  SCL = 1;
    _nop_();_nop_();
    SCL = 0;
 
}
 
//-------------------------------
// Read I2C
//-------------------------------
unsigned char ReadI2C(bit ACK_Bit)
{
   
   Start();
    WriteI2C(0xA1);
  
 
   SDA = 1;
    for (i=0;i<8;i++)
    {
         SCL   = 1;      
         Data<<= 1;
         Data = (Data | SDA);    
         SCL   = 0;
         _nop_();
    }
  
   if (ACK_Bit == 1)
    SDA = 0; // Send ACK     
    else    
    SDA = 1; // Send NO ACK               
 
    _nop_();_nop_();
    SCL = 1;    
    _nop_();_nop_();
    SCL = 0;
    Stop();
    return Data;
}
 
//-------------------------------
// Read 1 byte form I2C
//-------------------------------
void ReadBYTE(unsigned int Addr)
{
    Start();
    WriteI2C(0xA0);
    WriteI2C((unsigned char)(Addr>>8)&0xFF);
    WriteI2C((unsigned char)Addr&0xFF);
}
 
//-------------------------------
// Write 1 byte to I2C
//-------------------------------
void WriteBYTE(unsigned int Addr)
{
    Start();
    WriteI2C(0xA0);
    WriteI2C((unsigned char)(Addr>>8)&0xFF);    // send address high
    WriteI2C((unsigned char)Addr&0xFF);             // send address low
}
 
 
//---------------------------------------
// Delay mS function
//---------------------------------------
void DelayMs(unsigned int count)
{ // mSec Delay 11.0592 Mhz
   unsigned int i;                    // Keil v7.5a
   while(count)
    {
       i = 115;
         while(i>0) i--;
       count--;
   }
}

 

sry i dont know c. i gone through your program but i didnt get it...
 

Implement this C code in asm. SCL and SDA are alias for some port pins. See the code it is just setting SDA and SCL high or low using setb SCL or clr SCL like that. There are nop instructions inbetween. There is a loop to send or receive 8 bits of data. So, try to implement it in asm. Once I2C code is written in asm then it can be used to read and write to eeprom.


Code C - [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
//-------------------------------
// start I2C
//-------------------------------
void Start(void)
{
   SDA = 1;
    SCL = 1;
    _nop_();_nop_();
    SDA = 0;
    _nop_();_nop_();
    SCL = 0;
    _nop_();_nop_();
}
 
//-------------------------------
// stop I2C
//-------------------------------
void Stop(void)
{
    SDA = 0;   
    _nop_();_nop_();
    SCL = 1;
    _nop_();_nop_();
    SDA = 1;
}
 
//-------------------------------
// Write I2C
//-------------------------------
void WriteI2C(unsigned char Data)
{  
 
    for (i=0;i<8;i++)
    {
       SDA = (Data & 0x80) ? 1:0;
         SCL=1;SCL=0;
         Data<<=1;
    }
 
  SCL = 1;
    _nop_();_nop_();
    SCL = 0;
 
}
 
//-------------------------------
// Read I2C
//-------------------------------
unsigned char ReadI2C(bit ACK_Bit)
{
   
   Start();
    WriteI2C(0xA1);
  
 
   SDA = 1;
    for (i=0;i<8;i++)
    {
         SCL   = 1;      
         Data<<= 1;
         Data = (Data | SDA);    
         SCL   = 0;
         _nop_();
    }
  
   if (ACK_Bit == 1)
    SDA = 0; // Send ACK     
    else    
    SDA = 1; // Send NO ACK               
 
    _nop_();_nop_();
    SCL = 1;    
    _nop_();_nop_();
    SCL = 0;
    Stop();
    return Data;
}

 

sorry... i cannot understand what u have done in write routine because am not familiar with c codes.... thank you...
 

Write routine is like this


start loop and run 8 times (for 8 bits)

AND data (byte to be written to i2c bus) with 0x80 (data can be in R3 or any register)

If result of AND is true then setb SDA else clr SDA

setb SCL
clr SCL

shift data 1 bit (If data byte is in R3 then you shift R3 to left 1 bit)

after loop

setb SCL
nop
nop
clr SCL
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top