How can save into eeprom ?

Status
Not open for further replies.

bianchi77

Advanced Member level 4
Joined
Jun 11, 2009
Messages
1,313
Helped
21
Reputation
44
Reaction score
20
Trophy points
1,318
Location
California
Visit site
Activity points
9,442
Guys,

How can I save data to eeprom after data is valid ? with counter ?
here's the code :
Code:
valid_byte
								;SAVE SWAPPED BYTE
								;eeprom address
								movf	save_counter,W
								;movf	Addr_Counter,W
								
								movwf 	nTheEEAddress	
								;eeprom data
								;movwf 	Swap_data	
								movf	Swap_data,W
								movwf 	nTheEEData

								call  	eeWrite						
								;SAVE SWAPPED BYTE	
								;DEBUG
						 			;bsf LED_Flag,0
						  		;DEBUG 	
								incf	save_counter,f
						       ;=================check if address counter is equal to 7 ( finish sending 8 bytes)
						        
								
                                
								;movf	Addr_Counter,W
								movf	save_counter,W
								;xorlw	0x08			;check if address counter is equal to 7 ( finish sending 8 bytes)
								xorlw	0xFF			;TEST ONLY, check if address counter is equal to 255 ( finish sending 256 bytes)		
								btfss	STATUS,Z
								;goto	read_compare
								goto send_again
								;BLINK LED ON-OFF-ON-OFF
								goto send_and_check_finish
						send_again
							;address counter is here...
							movlw   .8
							movwf	byte_counter
		    				decf	State,1	
							return

						send_and_check_finish							
							bsf		LED_Flag,0

thanks
 

Hi! which of the pic controller are you using? Meanwhile, check the datasheet for the sample code. I would like to know the eeprom type (internal eeprom of the pic or external serial eeprom)
 

I'm using 16F648A and it's internal eeprom, I want to write 256 bytes, then read and transmit via UART 8 bytes for 32 times, and receive them check it, if it's correct save it into eeprom again,
any ideas, thanks
 

NOTE:
>Let the ram address use in keeping information use in eeprom and uart process should be assign address like 70h upward, for easy access on banks. e.g EE_ADDR EQU 0X072, and EE_DATA EQU 0X071.

Try My example on how to read and write on the eeprom. Access the save code via your programmer. if done, then proceed to use of uart operation.
;----------------------------------------------
;Saving ZERO in eeprom Memory address 0x1-0x5

MOVLW D'1'
MOVWF EE_ADDR
CALL EEPROM_READ
SUBLW D'255'
BTFSS STATUS,Z
GOTO OVER_EEPINT

MOVLW D'0'
MOVWF EE_ADDR
;----------------------------------------------
;Saving ZERO in eeprom Memory address
CLEAR_EEP:
INCF EE_ADDR,F
MOVLW D'0'
MOVWF EE_DATA
CALL EEPROM_WRITE
MOVF EE_ADDR,W
SUBLW D'5'
BTFSS STATUS,Z
GOTO CLEAR_EEP

OVER_EEPINT:
END
;------------------------------------------
EEPROM_WRITE:
BSF STATUS, RP0 ;Bank 1
MOVF EE_ADDR,W ;Data Memory
MOVWF EEADR ;Address to write
MOVF EE_DATA,W ;Data Memory Value
MOVWF EEDATA ;to write

;BSF STATUS, RP0 ;Bank 1
BSF EECON1, WREN ;Enable write
BCF INTCON, GIE ;Disable INTs.
MOVLW 55h ;
MOVWF EECON2 ;Write 55h
MOVLW AAh ;
MOVWF EECON2 ;Write AAh
BSF EECON1,WR ;Set WR bit begin write
BCF EECON1,WREN ;Disable writes

BCF STATUS,RP1 ;
BCF STATUS,RP0 ; Bank 0
RETURN

EEPROM_READ:
BSF STATUS, RP0 ;Bank 1
MOVF EE_ADDR,W ; Data Memory
MOVWF EEADR ; Address to read

BSF EECON1,RD ; EE Read
MOVF EEDATA,W ; W = EEDATA

BCF STATUS,RP1 ;
BCF STATUS,RP0 ; Bank 0
RETURN
 
Last edited:

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…