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 Program help with 8051

Status
Not open for further replies.

Reborn121

Newbie level 5
Joined
Jun 29, 2010
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
united states
Activity points
1,340
i have some code i am trying to get working here...there are probably a few things wrong with it but i cant seem to get it together...please help!...the program is suppose to erase EEPROM, then read a value from EEADR and store in EEBYT and output the value to port 3, then suppose to write a byte to EEPROM and thats it....please point me in the right direction...thanks


Code:
size    	EQU	9		
EEBYT		EQU	00h		
EEADR		EQU	20h		

CS		EQU	p1.0		
SK		EQU	p1.1		
DI		EQU	p1.2		
DO		EQU	p1.3		

		clr	CS		; low
		clr	SK		; low
		setb	DI		; high
		setb	DO		; high
		
		call	ewen		;enable write 	

		call	eral            ;erase device

		call	ewds            ;disable writing

		mov c,EEADR		;move EEADR into c
		mov EEBYT,c             ;move c into EEBYT
		mov p3,EEBYT            ;move EEBYT to port 3

		;write byte to EEPROM
		
		mov	EEADR, #7fh	; address
		mov	EEBYT, #55h	; data
		mov     a, EEBYT
		
		call	write		;call write routine

write:
		setb	CS		

		mov	dpl, #101b
		mov	b, #3
		call	outdata

		mov	dpl, EEADR	
		mov	b, #size	; bit count
		call	outdata

		mov	dpl, EEBYT
		mov	b, #8
		call	outdata

		clr	CS		; drop CS

eral:
		setb	CS		; raise CS

		mov	dptr, #(10010b SHL (size-2))
		mov	b, #(size+3)
		call	outdata

		clr	CS		; drop CS
		ret

ewen:
		setb	CS		; raise CS

		mov	dptr, #(10011b SHL (size-2))
		mov	b, #(size+3)
		call	outdata

		clr	CS		; drop CS
		ret

ewds:
		setb	CS		
		mov	dptr, #(10000b SHL (size-2))
		mov	b, #(size+3)
		call	outdata
		clr	CS		
		ret

outdata:
		push	b
		mov	a, b		; get bit count
		mov	a, dpl
		call shout
		pop b
		ret

shout:
	out:
		clr	SK		; drop clock
		rlc	a		; move bit into CY
		mov	DI, c		; output bit
		nop			; delay min 400 nS
		setb	SK		; raise clock
		djnz	b, out  	; next bit / delay min one u
		clr	SK		; drop clock
		ret

END
 

Code:
      mov c,EEADR      ;move EEADR into c 
      mov EEBYT,c             ;move c into EEBYT

C is a bit, EEADR is a byte ..
You can not move a byte into a bit ..

Similar thing happens in the second line:
EEBYT is a byte, C is a bit ..
There is no direct instruction o put a bit into a byte, as you have to specify which bit out of 8-bits you want to move the C-bit into ..
You can do it using for example the A register ..

What do you plan to do here?

There are several other issues, such as:
After "call write" you have to stop or loop program as it will go to subroutines ..
"write" sub has to finish with "RET" ..
..and so on ..
but lets address issues one at a time ..

IanP
:?:
 

thanks for the reply...i was trying to get the part of reading a value from variable EEADR and storing it in EEBYT done with that statement...i tried the C because i tried to put both variables as registers but it wont let me move one register to another...i put a return statement at the end of Write routine...how do you suggest i stop the program after the "call write"? thank you
 

Code:
EEBYT      EQU   00h       
EEADR      EQU   20h
The above assigns value #00h to EEBYT and #20h to EEADR ..

Code:
EEBYT      DATA   00h       
EEADR      DATA   20h
This defines EEBYT as memory location 00h and EEADR as memory location 20h ..

Now:
MOV EEADR, EEBYT will move contents of M[00] to M[20] ..

IanP
:|
 

ok i fixed the problem with that thanks...do you have any other suggestions...such as how to deal with the stopping the program after the "call write"? thank you
 

Reborn121 said:
ok i fixed the problem with that thanks...do you have any other suggestions...such as how to deal with the stopping the program after the "call write"? thank you

Post you current code, lets see how the changes are implemented so far ..
:D
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top