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 me to interface eeprom with 89c51

Status
Not open for further replies.

naeem_28

Newbie level 4
Newbie level 4
Joined
Mar 31, 2011
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,350
hi
please help me i want to interface 24c16 eeprom with 89c51
i just want when the power cut and resume the power 89c51 should not reset, i want 89c51 start from that point where the power cut ,i don't know how to write eeprom interface code
my asm code is below,
with regard,
thank u

$mod51
ORG 0b

mov p0,#11111111b

mov p2,#0b
mov p3,#0b
start:
mov p1,#11111111b
name: jb p0.0,name
clr p1.0
acall was
clr p1.1
acall was
clr p1.2
acall was
clr p1.3
acall was
clr p1.4
acall was
clr p1.5
acall was
clr p1.6
ahmad: jb p0.6,ahmad
sjmp start

was: mov r0,#45
loop1: mov r1,#25
loop2: mov r2,#250
loop3: nop

djnz r2,loop3
DJNZ r1,loop2
djnz r0,loop1

ret


end:sad::sad:
 

that is not possible, you cannot store PC value and feed it to controller.... when power goes and re-powered on , by default pc values is loaded with 00 where it is reset boot vector...

if you usebattery for 8051 to run in the absence of power then it will keep on running without stopping.....
 
hi
sir i want to inerface eeprom 24c16 please let me know simple one way to interface 24c16 with 89c51 i need asm code,

regard,

---------- Post added at 23:26 ---------- Previous post was at 23:25 ----------

hi
sir i want to inerface eeprom 24c16 please let me know simple one way to interface 24c16 with 89c51 i need asm code,

regard,
 

hi

you could try to write a boot loader which will write stack to eeprom and then at power up restore stack. something like a pc in hibernation. ;-)
 
hi

you could try to write a boot loader which will write stack to eeprom and then at power up restore stack. something like a pc in hibernation. ;-)

how do you say that it is possible when you can develop only secondary bootloader and controller access primary bootloader.. in 8 bit where would you store a bootloader????????
 

hi

store in eeprom try to generate interrupt from power supply failure. isr will write stack to eeprom.
 
i agree it will require battery, but it will be for a very short period. if power requirements are low ......
 

Hey theta..
give proper justification for your answers so that everyone can understand properly... dont keep posting what you like... post something which is useful to the person who started the thread...
 

hi
i have seen rpm meter 5 digit they put the 24c16 eeprom with the 89c51 and i saw when the power cut the count restore when the power resume,,,
hope understand,

thank u
regard,

---------- Post added at 15:02 ---------- Previous post was at 14:55 ----------

thank u very much

---------- Post added at 15:08 ---------- Previous post was at 15:02 ----------

hi
i have seen rpm meter 5 digit they put the 24c16 eeprom with the 89c51 and i saw when the power cut the count restore when the power resume,,,
hope understand,

regard,
 

the controller is programmed to read certain memory location after power up, where the data is written.. so it reads the data.. it happens so fast that it makes us feel that it directly reads the data
 

i have seen rpm meter 5 digit they put the 24c16 eeprom with the 89c51 and i saw when the power cut the count restore when the power resume

using a timer ISR that executes every 1 second, save the data to eeprom. On startup in your code, read this value, and display it.
 
you are right . but my code is below please help me to write the code i am new to eeprom i don't know how to write the code ,,,,,,,,,,,,
regard



$mod51
ORG 0b

mov p0,#11111111b

mov p2,#0b
mov p3,#0b
start:
mov p1,#11111111b
name: jb p0.0,name
clr p1.0
acall was
clr p1.1
acall was
clr p1.2
acall was
clr p1.3
acall was
clr p1.4
acall was
clr p1.5
acall was
clr p1.6
ahmad: jb p0.6,ahmad
sjmp start

was: mov r0,#45
loop1: mov r1,#25
loop2: mov r2,#250
loop3: nop

djnz r2,loop3
DJNZ r1,loop2
djnz r0,loop1

ret


end

---------- Post added at 01:12 ---------- Previous post was at 01:11 ----------

you are right . but my code is below please help me to write the code i am new to eeprom i don't know how to write the code ,,,,,,,,,,,,
regard



$mod51
ORG 0b

mov p0,#11111111b

mov p2,#0b
mov p3,#0b
start:
mov p1,#11111111b
name: jb p0.0,name
clr p1.0
acall was
clr p1.1
acall was
clr p1.2
acall was
clr p1.3
acall was
clr p1.4
acall was
clr p1.5
acall was
clr p1.6
ahmad: jb p0.6,ahmad
sjmp start

was: mov r0,#45
loop1: mov r1,#25
loop2: mov r2,#250
loop3: nop

djnz r2,loop3
DJNZ r1,loop2
djnz r0,loop1

ret


end
 

First you need to explain in detail what you are trying to accomplish, or nobody will be able to help you.
Secondly you have to post your code with code tags. Nobody wants to format your code and edit the code if it is posted here. You need to use code tags (the "#" symbol above) to paste your code into.
Thirdly you need comments in your code! Always, Always, Always, use comments on every line to describe what you are doing. Get into this habit right from the start.

your code should look like this:
Code:
$mod51
;you need this or the code won't start!!
org	0h
	sjmp	start

;why are you using the timer interrupt vector here? There is no routine to initialize the timer?
ORG 0bh			;you forgot the "h"
	mov p0,#11111111b
	mov p2,#0b		;
	mov p3,#0b
;---------------------------------------
ORG 30h
start:
	mov p1,#11111111b
name:
	jb p0.0,name		;no comments? what are you trying to do
	clr p1.0
	acall was
	clr p1.1
	acall was
	clr p1.2
	acall was
	clr p1.3
	acall was
	clr p1.4
	acall was
	clr p1.5
	acall was
	clr p1.6
ahmad:	
	jb p0.6,ahmad
	sjmp start
;---------------------------------------
was:
	mov r0,#45			;this looks like a delay, but there are no comments
loop1:				;like how long the delay is
	mov r1,#25
loop2:
	mov r2,#250
loop3:
	nop
	djnz r2,loop3
	DJNZ r1,loop2
	djnz r0,loop1
	ret
;---------------------------------------
end
 
hi
my asm code is working well p0.0 need (0 ) input when you put 0 input to the p0.0 then after each 8 second p1.0 bit will clear and after 8 second p1.1 bit clear so on till p1.6 bit clear and p0.6 bit will hold it for 0 input , i just want when it working i mean p1.0 clear after 8 second p1.1 clear after 8 second p1.2 clear and at this point power cut i just want when the power resume 89c51 should not reset it should be start from the p1.2 bit ....
hope understand,,
regard

$mod51
ORG 0b

mov p0,#11111111b

mov p2,#0b ;port 2 clear
mov p3,#0b ;port 3 clear
start:
mov p1,#11111111b ;port 1 makes input port
name: jb p0.0,name ;wait for 0 input
clr p1.0 ; port 1 zero bit clear
acall was ; time delay 8 second
clr p1.1 ;p1.1 bit clear
acall was ;time delay 8 second
clr p1.2 ;p1.2 bit clear
acall was ; time delay 8 second
clr p1.3 ;p1.3 bit clear
acall was ;time delay 8 second
clr p1.4 ;p1.4 bit clear
acall was ;time delay 8 second
clr p1.5 ;p1.5 bit clear
acall was ;time delay 8 second
clr p1.6 ; p1.6 bit clear
ahmad: jb p0.6,ahmad ; wait for zero input
sjmp start ; start again

was: mov r0,#45 ; time delay
loop1: mov r1,#25
loop2: mov r2,#250
loop3: nop

djnz r2,loop3
DJNZ r1,loop2
djnz r0,loop1

ret


end
 

You should post the code with the code tags as I mentioned before. Select the "#" symbol and paste your code between the two "CODE]paste code in here[/CODE".

Why this?
Code:
$mod51
ORG 0b
you should be starting at address 0. Then jump to the start routine, Like this:
Code:
$mod51
ORG 0
jmp start ;the assembler will automatically adjust this to be a ljmp or a sjmp depending on the location of the routine.

Theoretically, (I have never tried this) you could save the program counter and the value of P1 in the external eeprom whenever the delay is called (in the was routine). This way the program will remember the settings every 8 seconds or whenever the delay is called.

At the beginning of the start routine, you can read those locations in the eeprom, restore the value of P1, copy the last program counter location from the eeprom to the dptr,and jump to the program counter location with an instruction "JMP @A+DPTR". Now you can't read the program counter but you can load a label into the data pointer, and jump to that address.

For more info, read this:
A51: READING THE PROGRAM COUNTER

Try this code. Connect Led's to P1. Remember which LED was on at the time you cut the power.
Disconnect power from your circuit.
Wait at least 2 seconds, then power up the board.
The same LED or the next one before the power was cut, will be on.

There are probably many more ways to do this, however you will have to research for yourself. For now this will be a good starting point for you to learn from.

Good Luck

Code:
$mod51
;
;here is a program to save the contents of the program counter 
;and the value of P1
;every 8 seconds to an external eeprom
;on startup, the program will read the eeprom and jump to the address
;where it left off when the power was disconnected
;
DataByte    equ	08h		; data byte to write eeprom
addrlo	equ	09h		; used for storing PC low byte
addrhi	equ	0Ah		; used for storing PC high byte
;
EepData	equ	0010h		;the address constant where you want to store your eeprom data
					;this can be anything you want
;
org	0h
	sjmp	start
;---------------------------------------
start:
	mov SP,#6Fh           	; always set up stack pointer if using ram space
	mov p0,#11111111b
	mov	dptr,#EepData	;get the data previously stored

	call EEPROM_READ		;get a byte @ dptr address in ext eeprom
	mov	a,DataByte
	cjne	a,#0FFh,Next	;check for invalid address
	jmp	name			;skip the rest if the data contains invalid address
;
;**********
;something to remember here:
;if the program jumps to an address where there is no code
;undetermined results may occur!!!
;like if the eeprom is blank or contains data that points 
;to an address outside of your code
;you must take this into consideration
;**********
;
Next:
	mov	dph,DataByte	;
	inc	dptr			;next address

	call EEPROM_READ		;get a byte @ dptr address in ext eeprom
	mov	dpl,DataByte	;
	inc	dptr			;next address

	call EEPROM_READ		;get a byte @ dptr address in ext eeprom
	mov	p1,DataByte		;restore P1
	
	clr	a			;ensure 0
	JMP @A+DPTR			;go to dptr address

name:
;	jb p0.0,name		;

	clr p1.0
	acall was			;8 second delay
	setb p1.0

	clr p1.1
	acall was			;8 second delay
	setb p1.1

	clr p1.2
	acall was			;8 second delay
	setb p1.2

	clr p1.3
	acall was			;8 second delay
	setb p1.3

	clr p1.4
	acall was			;8 second delay
	setb p1.4

	clr p1.5
	acall was			;8 second delay
	setb p1.5

	clr p1.6
	acall was			;8 second delay
	setb p1.6

ahmad:	
;	jb p0.6,ahmad
	sjmp name
;---------------------------------------
;8 second delay
was:
	MOV DPTR,#was		;save the current program counter to dptr
	mov	addrhi,dph		;copy PC to addrhi:addrlo
	mov	addrlo,dpl

	mov	dptr,#EepData	;save the data to eeprom

	mov	DataByte,addrhi	;write PC high byte	
	call	EEPROM_WRITE
	inc	dptr			;next address

	mov	DataByte,addrlo	;write PC low byte	
	call	EEPROM_WRITE
	inc	dptr			;next address

	mov	DataByte,P1		;save P1 value	
	call	EEPROM_WRITE

;begin the delay
	MOV   R3,#8			;1 second delay @ 11.0592 MHz (always include comments here)
      MOV   R2,#8
      MOV   R1,#236
loop1:
	DJNZ  R1,loop1
      DJNZ  R2,loop1
      DJNZ  R3,loop1
      RET

;	 MOV   R3,#57		;8 second delay @ 11.0592 MHz (always include comments here)
;      MOV   R2,#64
;      MOV   R1,#131
;loop1:
;	 DJNZ  R1,loop1
;      DJNZ  R2,loop1
;      DJNZ  R3,loop1
;      RET
;---------------------------------------
$include (I2C.inc)
;---------------------------------------
end

and the eeprom routines here:
Code:
;I2C routines here
read_cmd	equ	10100001B
write_cmd	equ	10100000B
;
;remember pullups on ALL I2C lines!!
SCL		EQU	p0.1		; serial clock
SDA		EQU	p0.2		; serial data
;************************************************************
;read one byte from i2c device into acc
I2C_READ:            
	MOV R7,#8
GFD:
	SETB SDA
	SETB SCL 
	MOV C,SDA 
	RLC A
	CLR SCL
	DJNZ R7,GFD
	RET
;************************************************************
;write one byte to i2c device from acc
I2C_WRITE:
	MOV R7,#8
WRITING:
	RLC A
	MOV SDA,C
	call CLOCK
	DJNZ R7,WRITING
	RET
;************************************************************
;start of i2c routine 
I2C_START:           
	SETB SCL
	SETB SDA 
	CLR SDA
	CLR SCL
	RET
;************************************************************
;end of i2c routine 
I2C_STOP: 
	SETB SCL
	SETB SDA 
	CLR SCL
	RET
;************************************************************
;synchronizing clock 
CLOCK: 
	SETB SCL	;raise clock
	NOP
	NOP
	CLR SCL	;drop clock
	RET
;************************************************************
;acknowledge from transmitter or receiver 
ACK: 
	CLR SDA	;ACK bit
	SETB SCL	;raise clock
	CLR SCL	;drop clock
	RET
;************************************************************
;no acknowledge from transmitter or receiver 
NO_ACK: 
	SETB SDA	;NAK Bit
	SETB SCL	;raise clock
	CLR SCL	;drop clock
	RET
;************************************************************
;write one byte to eeprom @ dph:dpl
EEPROM_WRITE:
	call I2C_START
	mov A,#write_cmd		;send write command
	call I2C_WRITE

	call ACK

	mov	a,dph			;send the address high byte
	call I2C_WRITE
	call ACK

	mov	a,dpl			;send the address high byte
	call I2C_WRITE
	call ACK

	MOV  A,DataByte		;write DataByte to eeprom
	call I2C_WRITE
	call ACK

	call I2C_STOP
	call DELAY_STOP
	RET
;************************************************************
;read one byte eeprom @ dph:dpl into DataByte
EEPROM_READ: 
	call I2C_START
	MOV A,#write_cmd		;send write command
	call I2C_WRITE
	call ACK

	MOV  A,dph			;send the address high byte
	call I2C_WRITE
	call ACK

	MOV  A,dpl			;send the address high byte
	call I2C_WRITE
	call ACK

	call I2C_START
	MOV A,#read_cmd		;send read command
	call I2C_WRITE
	call ACK

	call I2C_READ		;read one byte from eeprom into acc
	MOV DataByte,A
	call NO_ACK
	call I2C_STOP
	RET
;************************************************************
;terminating write process
DELAY_STOP:
	MOV   R2,#8
      MOV   R1,#98
Del_Stop:
	DJNZ  R1,Del_Stop
      DJNZ  R2,Del_Stop
      NOP
      RET
;************************************************************
 
Last edited:
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top