Reborn121 0 Newbie Poster

Hi everyone...i need some urgent help with a program that i am trying to write...the program is suppose to...Erase the EEPROM, then read a value from variable EEADR and store in EEBYT and also output the value to port 3 and finally write a byte to the EEPROM...if you have any suggestions or see any problems with my code please help!...its not working properly

size    	EQU	9		
EEBYT		EQU	20h		
EEADR		EQU	80h		

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.