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.

EEPROM 24C08 INTERFACING WITH 89C51

Status
Not open for further replies.

mak_goel

Junior Member level 3
Joined
Nov 30, 2006
Messages
31
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,541
eeprom interfacing with 89c51

Dear All,
I am facing a problem to interface the 24c08 with 89c51 micro. Actualy i am writing in assembly code. can any body send the assembly coding for the same.

Kidly help..........

Regards
Mak
 

set de instrucciones de eeprom 89c51

Code:
;--------------- EE WRITE ---------------------------

Write_L_C:		MOV		EEAddr, #00h		; WR address ..
			MOV		R0, #3Ch
			MOV		ByteCnt,#04h		; Send 4 bytes  ..

EE_W_Loop:		MOV		EEData, @R0
			LCALL		EE_Write
			INC		R0
			INC		EEAddr
			LCALL		Delay_20ms

			DJNZ		ByteCnt, EE_W_Loop 
			RET

;--------------- EE READ ----------------------------

Read_L_C:		MOV		EEAddr, #00h		; RD address ..
			MOV		R0, #3Ch
			MOV		ByteCnt,#04h		; Get 4 bytes  ..

EE_R_Loop:		LCALL		EE_READ
			MOV		@R0, EEData
			INC		R0
			INC		EEAddr
			LCALL		Delay_20ms

			DJNZ		ByteCnt, EE_R_Loop
			RET

;--------------- EEPROM ROUTINES FOR THE 24C02, with A2 = A1 = A0 = 0 -------------------
; one byte ..
EE_WRITE:
		LCALL		EE_START				; SEND A START FLAG TO THE EEPROM ..
		MOV		A,#0A0H				; SPECIFY A WRITE EEPROM @ ADDRESS 0H ..
		LCALL		SH_OUT				; SHIFT OUT THE DEVICE ADDRESS ..
		JC		WR_ABORT				; ABORT IF NO ACK FROM EEPROM ..
		MOV		A,EEAddr				; GET EEPROM MEMORY ADDRESS ..
		LCALL		SH_OUT				; SHIFT OUT THE MEMORY ADDRESS ..
		JC		WR_ABORT				; ABORT IF NO ACK FROM EEPROM ..
		MOV		A, EEData				; GET THE DATA TO BE WRITTEN ..
		LCALL		SH_OUT				; SHIFT OUT THE DATA ..
		JC		WR_ABORT
		CLR 		C
WR_ABORT:
		LCALL		EE_STOP				; SEND STOP CONDITION TO EEPROM ..
						; WAIT FOR WRITE TIME OF THE 24C02 {10ms} ..
						; THE EEPROM TAKES 10ms TO INTERNALLY STORE THE DATA. YOU CAN EITHER ..
						; PUT THE MICROCONTROLLER IN A WAIT STATE, OR CONTINUE WITH EXECUTION,
						; KEEPING IN MIND THAT THE EEPROM DATA IS NOT STORED FOR 10ms! ..
		RET							; GO BACK TO MAIN PROGRAM ..

;--------------- READ THE EEPROM DATA - FIRST PERFORM 'DUMMY WRITE' ---------------
; one byte ..
EE_READ:
		MOV		EEData,#00H				; CLEAR OLD DATA ..
		LCALL		EE_START				; SEND A START FLAG TO EEPROM ..
		MOV		A,#0A0H				; SPECIFY A WRITE TO EEPROM @ ADDRESS 0H ..
		LCALL		SH_OUT				; PERFORM 'DUMMY WRITE' ..
		JC		RD_ABORT				; ABORT IF NO ACK ..
		MOV		A,EEAddr				; LOAD EEPROM MEMORY LOCATION FROM WHICH TO READ ..
		LCALL		SH_OUT				; WRITE EEPROM MEMORY LOCATION ..
		JC		RD_ABORT				; ABORT IF NO ACK ..
; NOW READ THE DATA! ..
		LCALL		EE_START				; SEND A START FLAG ..
		MOV		A,#0A1H				; SPECIFY A READ FROM EEPROM ..
		LCALL		SH_OUT				; SHIFT OUT EEPROM ADDRESS ..
		JC		RD_ABORT				; ABORT IF NO ACK ..
		LCALL		SH_IN					; SHIFT IN THE DATA FROM EEPROM ..
		MOV		EEData,A				; STORE THE DATA ..
		LCALL		NAK					; SEND A NAK (NO ACKNOWLEDGE) TO THE EEPROM ..
		CLR		C					; CLEAR ERROR FLAG ..
RD_ABORT:
		LCALL		EE_STOP				; ALL DONE ..
		RET

;--------------- EE_START BIT-BANGS A START SEQUENCE TO EEPROM (HI-TO-LOW SDA TRANSITION WITH SCL HIGH) ..
EE_START:
		SETB		SDAPin
		SETB		SCLPin				; SET BOTH BITS ..
		NOP							; DELAY ..
		CLR		SDAPin				; START CONDITION - SDA HI TO LOW TRANSITION ..
		NOP
		NOP							; EEPROM ACCESS TIME DELAY ..
		CLR		SCLPin
		CLR		C					; CLEAR ERROR FLAG ..
		RET							; ALL DONE ..
;--------------- EE_STOP SENDS A STOP SEQUENCE TO THE EEPROM (LOW-TO-HIGH SDA TRANSITION WITH SCL HIGH) ..
EE_STOP:
		CLR		SDAPin
		NOP
		NOP
		SETB		SCLPin
		NOP
		NOP							; SETUP TIME DELAY ..
		SETB		SDAPin				; SEND A STOP CONDITION ..
		RET

;--------------- SH_OUT SHIFTS DATA OUT TO THE EEPROM---------------------
SH_OUT:
		PUSH		B
		MOV		B,#8					; SAVE B AND LOAD BIT COUNT ..
EE_OUT:
		RLC		A					; SHIFT BIT LEFT (RLC=ROTATE LEFT THROUGH CARRY) ..
		MOV		SDAPin, C				; GET DATA BIT FROM CARRY ..
		NOP
		SETB		SCLPin				; CLOCK IN 1-BIT ..
		NOP							; CLOCK HIGH TIME ..
		CLR		SCLPIN				; CLOCK IS NOW LOW ..
		DJNZ		B, EE_OUT				; DO IT 8 TIMES ..
		SETB		SDAPin				; RELEASE SDA FOR ACK ..
		NOP
		NOP
		SETB 		SCLPin				; ACK CLOCK ..
		NOP
		MOV		C, SDAPin				; GET THE ACK ..
		CLR		SCLPin				; CLEAR THE CLOCK BIT ..
		POP		B					; RESTORE WHATEVER B WAS ..
		RET

;--------------- SH_IN SHIFT DATA IN FROM THE EEPROM-----------------------
SH_IN:
		SETB		SDAPin				; MAKE SDA AN INPUT ..
		PUSH		B
		MOV		B,#8					; SAVE B AND SET BIT COUNTER ..
EE_IN:
		NOP
		SETB		SCLPin				; SET CLOCK ..
		NOP
		NOP							; EEPROM ACCESS TIME ..
		SETB		SDAPin				; SET = 1 SO USED AS INPUT ..
		MOV		C, SDAPin				; READ 1-BIT ..
		RLC		A					; SHIFT BIT LEFT ..
		CLR		SCLPin				; CLEAR CLOCK BIT ..
		DJNZ		B, EE_IN				; GET NEXT BIT IF LESS THAN 8 BITS READ ..

		POP		B
		RET

;--------------- ACK SENDS AN EEPROM ACKNOWLDEGE----------------------
ACK:
		CLR		SDAPin
		NOP
		NOP
		SETB		SCLPin				; CLOCK THE ACK ..
		NOP
		CLR		SCLPin				; BRING CLOCK LOW ..
		RET

;--------------- NAK SENDS A NO ACKNOWLEDGE----------------------------
NAK:
		SETB		SDAPin
		NOP
		NOP
		SETB		SCLPin				; CLOCK THE NAK ..
		NOP
		CLR		SCLPin				; BRING CLOCK LOW ..
		RET

;---------------- END -----------------

Regards,
IanP
 

interfacing of 24c08 with 89c51

Thanks Mr. IAN for giving the coding. But again need of your help as below:

1) In attached scmematic U4 is EEPROM. Is it write the coonection details of the same. Pin description is wrong kindly ignore it.

2) Although u have given the complete coding but failed to uderstand as i am new in this field. Can u pl give me a complete examp. of writing the same in byte writing format.

3) Attached the 24C08 PDF. In 3/16 page device select code was given. Kimdly explain the same.

4) Kindly explain the ack & noack.

I am in realy vary difficut staze. Kindly help me.

Regards
Mak
 

24c02 and 89c51

Kindly help...............................


Regards
Mak
 

24c08 pdf

Data sheet explains these bits and pieces in details - what else can I add?

You have the code that reads/writes 4 bytes .. change the number of bytes to 1 and it will read or write just one byte ..

Regards,
IanP
 

89c51 sda pin no

Hi,
I attach files with sch for 89c2051 and 24cxx and asm file, used for led massage display,
may help you,
regards
 

89c5131 eeprom

Mr. mak_goel you first study the data sheet of the eeprom attentionally and understand it step by step, above you are give a complete code in assembly you should have no question furtherly. device code is give on page no. 4 of the data sheet with complete explaination read it and if you still have question then ask on the forum.

regards
 
  • Like
Reactions: mm_pk1

    mm_pk1

    Points: 2
    Helpful Answer Positive Rating
89c51 eeprom code

hi i am dewan from chennai.. can any one give me the cost for the 24c04.. i want t know its cost urgently
 

interfacing 24c08 with 89c51

you have not mentioned that in what currency you want the price of the chip??
in pakistan it for Rs. 80 only.

regards
 

89c51 wait state

Thanks everbody and specially thanks to Mr IanP and sorry for late response.

By using the IanP's coding, now i m able to write or read EEPROM 24C08. But still i m facing below problems:

1) You are giving the 20ms delay after each cycle (Read or write). But i have to write 96 Bytes in EEPROM in specific conditions during running programe.
Stored data(6 Bytes) to be displayed on LCD by selecting the key. It is again problem as I am taking 6x20ms=120ms to read the 6 bytes while my timer0 intrupt is setted at 10ms that cant be changed.

2) I think your coding supports to byte write mode so pl clear also that MODE/WC (Pin-7 of EEPROM) to be connected to ground or left floating.


Thanks & Regards
Mak
 

interfacing of 89c51 with eeprom

mak_goel said:
1) You are giving the 20ms delay after each cycle (Read or write). But i have to write 96 Bytes in EEPROM in specific conditions during running programe.
Stored data(6 Bytes) to be displayed on LCD by selecting the key. It is again problem as I am taking 6x20ms=120ms to read the 6 bytes while my timer0 intrupt is setted at 10ms that cant be changed.
Mak

In each byte cycle of it not over 5 ms. Free time before process in new byte ~ 1.2 us

That mean you can reduce that time to 1.5 us it enough

mak_goel said:
2) I think your coding supports to byte write mode so pl clear also that MODE/WC (Pin-7 of EEPROM) to be connected to ground or left floating.
Mak

In normal use you must pull-down in Write Protect Pin.
Recomment Pull-Down very well.


WRITE PROTECT (WP): The write protect input, when connected to GND, allows normal write
operations. When WP is connected high to VCC, all write operations to the memory are inhibited.
If the pin is left floating, the WP pin will be internally pulled down to GND if the capacitive
coupling to the circuit board VCC plane is <3 pF. If coupling is >3 pF, Atmel recommends connecting
the pin to GND. Switching WP to VCC prior to a write operation creates a software
write-protect function.
 

complete data sheet of 89c51

Thanks Katesuda,
Pl again clearify below:

1) I think you are saying that 1.5 Microsec. delay is required after each read & write cycle in the place of 20 ms & 5 ms delay is each byte processing time. Am i right?

2) I was trying to read the EEPROM. Once it reads right but othertime wrong. I couldn't understand. Pl clearify.


Thanks

Mak
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top