Write and Read from eeprom


Closed Thread
Results 1 to 24 of 24

Hybrid View

  1. #1
    Join Date
    Jun 2006
    Location
    Greece
    Posts
    302

    Default Write and Read from eeprom

    I have the below code (one part of code).
    My problem is when turn off the power and after turn on again , don't save the value P in the eeprom always.Why;
    I use 16f88
    Code:
        P VAR WORD	          'value of the divider
        FLAG VAR BYTE
    
    
        READ 3,FLAG
        IF FLAG = 55 THEN
        READ 1,P.BYTE0        ' Divider
        READ 2,P.BYTE1
        ELSE
    	P= 256	        	  ' value of the divider	
        ENDIF
        
    ..
    ..
    ..
    ..
    ..    
        
    '************************** CHOICE OF THE DIVIDER ***********************
    
    PREDIV:
    
    	LCDOUT $FE,1,"*    DIVIDER   *"
    	LCDOUT $FE,$C0,"     P = ",#P
    	
    LOOP:	
        BUTTON PLUS,0,10,5,B1,1,PICK	    ' Goes to PICK if press the button
    	BUTTON BMENU,0,255,0,B4,1,MEN	
    	PAUSE 100
    	GOTO LOOP
    	
    PICK:	
        IND = IND + 1
    	IF IND< 9 THEN CHOIX
    	IND= 0
    	GOTO CHOIX
    	
    CHOIX:	
        LOOKUP2 IND,[1,10,16,32,40,64,80,128,256],P
    
    	WRITE 3 , 55
    	WRITE 1 , P.BYTE0      	            ' SAVE The VALUE OF P
    	WRITE 2 , P.BYTE1
        PAUSE 100
    	
    	GOTO MAIN
    Last edited by savnik; - 19th March 2007 at 08:10.

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,132


    Did you find this post helpful? Yes | No

    Default

    Yassou Niko!

    If the power is taken before the Write commands, then it is possible to loose the values. When do you power off the device?

    Ioannis

  3. #3
    Join Date
    Jun 2006
    Location
    Greece
    Posts
    302


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Ioannis View Post
    Yassou Niko!

    If the power is taken before the Write commands, then it is possible to loose the values. When do you power off the device?

    Ioannis
    Geiasou Giannh (ta agglika mou einai xalia)
    I turn off the power after enough (>30 sec) time when change the value

  4. #4
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,132


    Did you find this post helpful? Yes | No

    Default

    Time is not the most critical point. If the program never makes it to the Write commands, then it sure will never store the values to EEPROM.

    Ioannis

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    I had a similar problem and fixed it by using two variables. Do not know why this worked, but I have used this routine for some time now.

    Code:
    cnt var byte      
    Pb1	var word  
    Pset    var word 
    READ 0,Pset.BYTE0
    READ 1,Pset.BYTE1
    Pb1 = Pset
    
    C_P:
    		for cnt = 1 to 1  
    		Pb1=Pb1+1
    		WRITE 0,Pb1.BYTE0
    		WRITE 1,Pb1.BYTE1
    		READ 0,Pset.BYTE0
    		READ 1,Pset.BYTE1
    		pause 100
    		next
    RETURN
    Maybe all you need is the count routine to ensure that the data is being written?
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Jun 2006
    Location
    Greece
    Posts
    302


    Did you find this post helpful? Yes | No

    Default

    I have 4 routines to write and read

  7. #7
    Join Date
    Jun 2006
    Location
    Greece
    Posts
    302


    Did you find this post helpful? Yes | No

    Default

    Need to add the : Include "Modedefs.Bas" ;

Similar Threads

  1. Can't read sequential addresses in external EEPROM
    By tjkelly in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 18th February 2010, 14:46
  2. Problem with I2C EEPROM addressing
    By Atom058 in forum General
    Replies: 14
    Last Post: - 3rd November 2009, 03:17
  3. write -read problem?
    By turkuaz in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 30th August 2009, 13:06
  4. PIC16F684 + LCD to use the 256bytes of EEPROM - HELP
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 7th March 2008, 14:19
  5. word variable to 25lc640
    By TONIGALEA in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 6th July 2004, 19:59

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts