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.

pic16f877

Status
Not open for further replies.
gomathi said:
plz any one can help me

how to read and write the EEPROM of PIC 16f877?

Do you mean the data EEPROM, or the program EEPROM (for that matter, in PIC code or with a programmer?). If you mean reading and writing the data EEPROM within a PIC program, there's sample code listed in the 16F877 datasheet. Here's some sample code based on that, it reads and writes the value of a port to one address in the EEPROM.

Code:
EE_Read		bsf 	STATUS,	RP0 		; Bank 1
		movlw 	EEPROM_Addr
		movwf 	EEADR			; Address to read
		bsf 	EECON1,	RD 		; EE Read
		movf 	EEDATA,	W 		; W = EEDATA
		bcf 	STATUS,	RP0 		; Bank 0
		movwf	LED_PORT		; restore previous value
		retlw	0x00

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
 
first off sorry for jumping in yet another thread...

But, I have a few question about this code. I have tried to use it and I get a bunch of error. the main one is that the "label are not defined" errors...

so I guess my question is do I need to include a different header file in order to write to the address in the onchip eeprom?

the LED_PORT is that a chip define or a user defined varible. also can you explain why the 55h and the aah need to be written to the chip and I guess the final one I need to ask is what is the goto $-1. is that a just a goto back one step and check again instruction. if so can the goto be used like goto $-2?



Code:
EE_Read		bsf 	STATUS,	RP0 		; Bank 1
		movlw 	EEPROM_Addr
		movwf 	EEADR			; Address to read
		bsf 	EECON1,	RD 		; EE Read
		movf 	EEDATA,	W 		; W = EEDATA
		bcf 	STATUS,	RP0 		; Bank 0
		movwf	LED_PORT		; restore previous value
		retlw	0x00

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

Thank you for the pending help
 
This is only a section of code from one of my tutorials, it doesn't include the definitions I made at the beginning of the program - if you want the complete thing, it's from one of my IR tutorials.
 
Mr. Goodwin
is there a way I can get a link to the information you refer... I for some reason could find it before.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top