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.

Please help in programming EEPROM.

Status
Not open for further replies.

nikhildascl

Full Member level 3
Joined
Apr 15, 2012
Messages
150
Helped
15
Reputation
30
Reaction score
14
Trophy points
1,318
Location
Kerala, India
Activity points
2,115
I've written the code for EEPROM with 89c52. But it is not working. My code is given below. Please help...
Code:
		ORG 00H
SDA EQU P1.4
SCL EQU P1.5
        	
;I2C
		LCALL I2C_START
		MOV A,0xA0
		LCALL I2C_SEND
		LCALL ACK
		MOV A,0x01
		LCALL I2C_SEND
		LCALL ACK
		MOV A,#3FH		; send 3Fh
		LCALL I2C_SEND
		LCALL ACK
		LCALL I2C_STOP
		CLR P2.0
		LCALL DELAY
		;................
		LCALL I2C_START
		MOV A,0xA0
		LCALL I2C_SEND
		LCALL ACK
		MOV A,0x10
		LCALL I2C_SEND
		LCALL ACK
		MOV A,0xA1
		LCALL I2C_SEND
		LCALL ACK
		MOV A,0x00
		LCALL I2C_SEND
		LCALL ACK
		LCALL I2C_STOP
AGAIN:	SJMP AGAIN


;I2C START


I2C_START:
		SETB SDA
		LCALL DELAY
		SETB SCL
		LCALL DELAY
		CLR SDA
		LCALL DELAY
		CLR SCL
		LCALL DELAY
	    RET
;I2C STOP


I2C_STOP:
		CLR SDA
		LCALL DELAY
		SETB SCL
		LCALL DELAY
		SETB SDA
		LCALL DELAY
		CLR SCL
		LCALL DELAY
		RET
;I2C SEND BYTE


I2C_SEND:
		RLC A
		MOV SDA,C
		LCALL DELAY
		SETB SCL
		LCALL DELAY
		CLR SCL
		LCALL DELAY
		RET
;I2C RECEIVE BYTE


I2C_READ:
		SETB SDA
		LCALL DELAY
		SETB SCL
		MOVC A,@A+DPTR
		LCALL DELAY
		CLR SCL
		CLR SDA
		RET


;ACKNOWLEDGE


ACK:	
		SETB SCL
		LCALL DELAY
		LCALL DELAY
		CLR SCL
		RET	
; DELAY PROGRAM
DELAY:	
		MOV R3,#255
HERE:	MOV R4,#255
HERE2:	DJNZ R2,HERE2
		DJNZ R1,HERE
		RET
 

in your delay code, you are initialising R3 and R4.
but decrementing R2 and R1.
so it should be:

Code:
; DELAY PROGRAM
DELAY:	
		MOV R2,#255
HERE:	MOV R1,#255
HERE2:	DJNZ R2,HERE2
		DJNZ R1,HERE
		RET


---------- Post added at 09:17 ---------- Previous post was at 09:16 ----------

did you calculated the delay ? it will be very high?
 

Sorry. But now there is no problem with delay. Still the programs is not working. Is there any mistake with the I2C program??
 

[

use the delay code alone in a test routine and find/monitor with scope , the delay value.
 

Assuming your 805a works at 12 MHz and the EEPROM supports 400 kHz I2C operation, a single NOP delay would be sufficient to achieve a legal timing.

As an obvious fault, the send and receive routines are missing a loop over 8 bits. There may be more errors.

Why don't you refer to a known working I2C code for 8051?
 

I mean, is that 24C04, 24C08, 24C16 or what?
>different type needs different program.
how much size (Byte) do you need, do you want to use all of it's capacity?
How you connect pin 1, 2, 3?
>if you just want to use less then 256 bytes, you can connect pin 1, 2, 3 directly to ground. It will make you understand the concept easier.

Of course, we will help you.

And Also i saw you wrote Mov A,0x0A
I don't know what your compiler specification. For my compiler, Mov A,0Ah will store SFR data located at 0Ah to accomulator. You must use Mov A,#0Ah or maybe Mov A,#0x0A.
 
Last edited:

I mean, is that 24C04, 24C08, 24C16 or what?
>different type needs different program.
how much size (Byte) do you need, do you want to use all of it's capacity?
How you connect pin 1, 2, 3?
>if you just want to use less then 256 bytes, you can connect pin 1, 2, 3 directly to ground. It will make you understand the concept easier.

Of course, we will help you.

And Also i saw you wrote Mov A,0x0A
I don't know what your compiler specification. For my compiler, Mov A,0Ah will store SFR data located at 0Ah to accomulator. You must use Mov A,#0Ah or maybe Mov A,#0x0A.


Suppose i want to use more than 256 bytes then how i can connect a0,a1,a2 pins... i m in urgent need...
 

If you use 24CXX family, connect A0, A1, A2 to uC's ports. But, as i asked before, what EEPROM type do you use? It's important. Now, there are many families and types of EEPROM in the market, and each needs special way.

i m in urgent need...
Unfortunately, i'm also in busy right now, i don't know when i can and will be sign in again. I hope, friends here want to help you, or just use EEPROM type and code that i already posted for you on your another thread. Good luck.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top