EEPROM

Status
Not open for further replies.

Thorpydo

New Member
Hey,
I'm trying to write to EEPROM.. After I get that Ill try read..
Code:
	movlw	0h
	movwf	EEADR
	movlw	0x0F
	movwf	EEDATA
	bsf		STATUS,RP0			;bank 1	
	bsf		EECON1,WREN			;enable write
	bcf		INTCON,GIE			;disable interrupts
	movlw	55h					;unlock write
	movwf	EECON2
	movlw	AAh
	movwf	EECON2
	bsf		EECON1,WR			;start the write
	bsf		INTCON,GIE			;enables interrupts

The data isnt written to the EEPROM and instead of continueing on with the program, it sits there(I believe anyway).

I was thinking the problem might have to do with "AAh". When I write "AAh" in MPLAB, it shows up in purple like its a symbol, not blue, like the 55h does. I have to write AAh in my cblock which I think is just substituing any old register for the AAh register.

Thanks
 

AAh is just a hexadecimal constant (as is 55h), not a register, try using 0xAA instead!. Here's a working EEPROM writing routine from my IR tutorial:
Code:
EE_Write	movf	LED_PORT,	w	; read current value
		bsf 	STATUS,	RP0 		; Bank 1
		bsf	EECON1,	WREN 		; Enable write
		movwf	EEDATA			; set EEPROM data
		movlw	EEPROM_Addr
		movwf	EEADR			; set EEPROM address
		movlw	0x55
		movwf	EECON2 			; Write 55h
		movlw	0xAA
		movwf	EECON2 			; Write AAh
		bsf	EECON1,	WR 		; Set WR bit
						; begin write
		bcf 	STATUS,	RP0 		; Bank 0
		
		btfss	PIR1,	EEIF		; wait for write to complete.
		goto	$-1
		bcf	PIR1,	EEIF		; and clear the 'write complete' flag
		bsf 	STATUS,	RP0 		; Bank 1
		bcf	EECON1,	WREN 		; Disable write
		bcf 	STATUS,	RP0 		; Bank 0
		retlw	0x00
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…