Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

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
 
Thorpydo said:
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.

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.

New Articles From Microcontroller Tips

Back
Top