Writing and reading a PORTC value to EEPROM? (PIC16F877)

Thread Starter

GuitarMan216

Joined Oct 6, 2011
18
In Assembly.

I'm working on a simple code that rotates through 8 LED's(PORTC) from with the rlf instruction. All I need to do is store the value into EEPROM so the same LED is lit up when the circuit is powered on. Say RC2 is high when you power off, when you power it back on, RC2 is still high...same with the other pins. If that makes any sense.

I know I need the 5 lines:

movlw 0x55
movwf EECON2
movlw 0xAA
movwf EECON2
bsf EECON1, WR

but other than that, I'm new to EEPROM.

Thanks guys, you're always helpful.
 

Thread Starter

GuitarMan216

Joined Oct 6, 2011
18
Here's what I have to write:

Rich (BB code):
	banksel EECON1 			 
	btfsc EECON1, WR 		
	goto $-1 				
	movlw 0xC3 			
	banksel EEADR 			
	movwf EEADR 			
	movf  PORTC, W			
	movwf EEDATA 			 
	banksel EECON1 			 
	bcf EECON1, EEPGD 		
	bsf EECON1, WREN 		
	bcf INTCON, GIE 		
	movlw 0x55 				
	movwf EECON2 			 
	movlw 0xAA 				
	movwf EECON2 			
	bsf EECON1, WR 			
	bsf INTCON, GIE 		
	bcf EECON1, WREN
And to read:

Rich (BB code):
	movlw 0xC3 		
	banksel EEADR 			
	movwf EEADR 			
	banksel EECON1 			
	bcf EECON1, EEPGD 		
	bsf EECON1, RD 			
	banksel EEDATA 			
	movf EEDATA, W
 

Felo

Joined Feb 20, 2012
91
Hi,

Keep in mind that EEPROM writing cycles are limited, (most pic's have 1M cycles). For example, let's say that your aplication will be writting to the EEPROM 10 times per sec.

10x60x60=36000 , within an hour it would have written 36k times the EEPROM

If it is intended to be used for say 8 hours a day, within a day you will have 288k cycles out, in 3,47 days of 8 hours, your application will be out of spec.

I remember to have read an AP note from MC wich dealt with this problem and suggested a form o "rolling position" of EEPROM accessing, quite interesting.

Good Luck
 

Thread Starter

GuitarMan216

Joined Oct 6, 2011
18
Hi,

Keep in mind that EEPROM writing cycles are limited, (most pic's have 1M cycles). For example, let's say that your aplication will be writting to the EEPROM 10 times per sec.

10x60x60=36000 , within an hour it would have written 36k times the EEPROM

If it is intended to be used for say 8 hours a day, within a day you will have 288k cycles out, in 3,47 days of 8 hours, your application will be out of spec.

I remember to have read an AP note from MC wich dealt with this problem and suggested a form o "rolling position" of EEPROM accessing, quite interesting.

Good Luck

Thanks. I need it to work for a very limited time though. Maybe a minute at the longest.
 

Felo

Joined Feb 20, 2012
91
this is my code for dealing with EEPROM

To write

Rich (BB code):
WRITE_EEPROM	; PUT VALUE IN EEDATA AND EEADR  BEFORE CALLING!! 
		BANCO1	;EEPROM_ADDR MACRO
		BSF	EECON1, WREN
		MOVLW	0X55	;OBLIGATORIO
		MOVWF	EECON2	;
		MOVLW	0XAA	;
		MOVWF	EECON2	;
		BSF	EECON1, WR
		BTFSC EECON1,WR
		GOTO $-1
VERIF  	NOP
		MOVFW	EEDATA	; LAST WRITTEN VALUE IN 'W'
		BSF		EECON1, RD	; START READ AT CURRENT ADDRESS
		SUBWF	EEDATA, W	; SUBTRACT W FROM EEDATA
		BTFSS	STATUS, Z	; ZERO FLAG SET?
		GOTO	WRITE_EEPROM	; NO, THERE WAS A WRITE-ERROR
		BANCO0
		RETURN
 

Felo

Joined Feb 20, 2012
91
Too read

Rich (BB code):
	BANCO1
		MOVLW	0X01 ;DIRECCION A LEER (TARGET ADDRESS TO READ)
		MOVWF	EEADR
		BSF		EECON1,RD
		MOVFW	EEDATA
		BANCO0
		MOVWF	INDICE ; OR ANYTHING
 

Thread Starter

GuitarMan216

Joined Oct 6, 2011
18
Thanks for all the help man. Not gonna lie, I laughed at the Banco1. Two semesters of espanol, and it's one of the few words I still remember. :D
 

Felo

Joined Feb 20, 2012
91
HEHEH, Spanglish coder in tha house!!!

two semesters of spanish should have left you way more than a few words my friend, do as I and write your macros in spanish...:D
 
Top