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.

[SOLVED] PIC16F887 EEPROM writing problem !!!

Status
Not open for further replies.

dustie

Newbie level 6
Newbie level 6
Joined
Oct 2, 2009
Messages
11
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Location
Macedonia
Visit site
Activity points
1,354
Hi guys,

I have problem with writing to the internal EEPROM on PIC16F887.
As you can see in the code below, I am using LEDs on PORTB so I can watch where the code stucks.
So, the problem is: EECON1,WR bit doesn't set at all (and the PORTB,2 indicator LED doesn't go "1").
And I really can't figure out what causes this problem.
Please help me if you have any idea.
Below is the procedure for writing to EEPROM (as a part of a program), and the _CONFIG sentence:

Code:
;----------------------------------------------------------------------------------

    __CONFIG    _CONFIG1, _LVP_OFF & _FCMEN_ON & _IESO_ON & _BOR_ON & _CPD_OFF & _CP_OFF & _MCLRE_ON & _PWRTE_OFF & _WDT_OFF & _HS_OSC & _DEBUG_OFF
    __CONFIG    _CONFIG2, _WRT_OFF & _BOR40V

;---------------------------------------------------------------------------------
;		EEPROM  WRITE
eeprom_write
	nop
	banksel	EEADR
	movlw	0x00
	movwf	EEADR

	banksel	EEDAT
	movlw	H'26'
	movwf	EEDAT

	banksel	EECON1
	bcf	EECON1,EEPGD
	bsf	EECON1,WREN

	banksel	INTCON
	bcf	INTCON,GIE
	btfsc	INTCON,GIE
	goto	$-2

	banksel	PORTB
	bsf	PORTB,0		; Indication LED

	banksel	EECON2
	movlw	H'55'
	movwf	EECON2
	movlw	H'AA'
	movwf	EECON2

	banksel	PORTB
	bsf	PORTB,1		; Indication LED

	banksel	EECON1
	bsf	EECON1,WR
	btfss	EECON1,WR
	goto	$-2

	banksel	PORTB
	bsf	PORTB,2		; Indication LED

	banksel	INTCON
	bsf	INTCON,GIE

	banksel	EECON1
	btfsc	EECON1,WR
	goto	$-1

	banksel	PORTB
	bsf	PORTB,3		; Indication LED

	banksel	EECON1
	bcf	EECON1,WREN
;
	banksel	STATUS
	bcf	STATUS,RP0
	bcf	STATUS,RP1
	return
;---------------------------------------------------------------------------
 
Last edited by a moderator:

Hi,

The EEprom routine is a tricky one and you must follow Microchips eeprom code examples to the letter.

Have not got time to degug your code, but have attached some working write and read eeprom routines I used an old 16876A chip.
You just need to check the registers are in the same banks on your 887chip
 

Attachments

  • eerpom.zip
    986 bytes · Views: 76
  • Like
Reactions: dustie

    dustie

    Points: 2
    Helpful Answer Positive Rating
Dear wp100,

Thank you very much for your help, you really saved me from going crazy.
It works great now and I can finish the project.
Thanks pal !
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top