Write and Read from eeprom


Closed Thread
Results 1 to 24 of 24

Hybrid View

  1. #1
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,117


    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

  2. #2
    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

  3. #3
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,117


    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

  4. #4
    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.

  5. #5
    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

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


    Did you find this post helpful? Yes | No

    Default

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

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


    Did you find this post helpful? Yes | No

    Default

    That would do it. Was scratching my head...
    Dave
    Always wear safety glasses while programming.

  8. #8
    Join Date
    Jun 2007
    Posts
    26


    Did you find this post helpful? Yes | No

    Default read write to eeprom

    hello ya all,

    I have been at this for 3 days and nights now, i give up, I need help.

    Its simple in the pbp manual and from what Ive read in this forum, but to no luck. heres the details, not in the exact order

    pbp 2.47
    Include "modedefs.bas" ' is included
    DISABLE ' to turn off interupts even though i never hae used them
    DEFINE OSC 4
    TRISA = %11011
    TRISB = %11011011

    The problem is somtimes it works and somtimes it dosn't. When I read back the data after i write it, it reads correct. but after Ive turned it off and back on it comes up with weird numbers, random numbers. I send it to and lcd through serout2, and also receive a command or two. but I dont think the problem is there because other data shows up fine. the exact full code will be down below, but for now to point out where I think the problem is.

    WRITEIT:

    WRITE 0,T0
    READ 0,T0
    WRITE 1,T1
    READ 1,T1
    WRITE 2,P0
    READ 2,P0
    WRITE 3,P1
    READ 3,P1
    WRITE 4,C0
    READ 4,C0
    WRITE 5,C1
    READ 5,C1
    RETURN

    If my problem is somewhere else then Please point it out, cause I have tried everything. I am not one to give up easy, so for me to be here asking for help is rare. I am not an expert at pbp, but I do my best and can do almost everything I set out to do. here is the rest of my code

    Include "modedefs.bas" ' Include serial modes
    DEFINE OSC 4
    TRISA = %11011
    TRISB = %11011011

    '--------------------------DECLARES------------------------------

    PERCENT VAR BYTE
    TOTAL VAR WORD
    CAMBIO VAR WORD
    PREMIOS VAR WORD
    TT VAR WORD
    PP VAR WORD
    CC VAR WORD
    COUNTING VAR BYTE
    AMOUNT VAR BYTE
    MAC VAR BYTE
    DIP1 VAR BYTE
    DIP2 VAR BYTE
    DIP3 VAR BYTE
    DONE VAR BYTE
    COINOUT VAR PORTB.0
    COININ VAR PORTB.1
    MOTOR VAR PORTB.2
    LLAVE VAR PORTB.3
    BUTTON1 VAR PORTB.4
    COUNTER VAR PORTB.5
    A VAR WORD
    C0 VAR CAMBIO.BYTE0
    C1 VAR CAMBIO.BYTE1
    T0 VAR TOTAL.byte0
    T1 VAR TOTAL.byte1
    P0 VAR PREMIOS.BYTE0
    P1 VAR PREMIOS.BYTE1


    X VAR BYTE

    '-------------------------------SETUP-----------------------------

    counter=0
    motor=0
    DONE=0

    '----------------------------turn off interupts-------------------
    DISABLE
    '-----------------------------get data-----------------------------

    pause 100
    READ 0,T0
    READ 1,T1
    READ 2,P0
    READ 3,P1
    READ 4,C0
    READ 5,C1
    READ 6,MAC
    PAUSE 500

    AMOUNT=100
    COUNTING=0

    '----------------------------DIP SETUP-----------------------------

    DIP1=PORTA.0
    IF DIP1=0 THEN
    DIP1=40
    ELSE
    DIP1=20
    ENDIF

    DIP2=PORTA.1
    IF DIP2=0 THEN
    DIP2=20
    ELSE
    DIP2=10
    ENDIF

    DIP3=PORTB.7
    IF DIP3=0 THEN
    DIP3=10
    ELSE
    DIP3=5
    ENDIF

    IF PORTA.4=0 THEN
    AMOUNT=25
    ELSE
    AMOUNT=100
    ENDIF

    PERCENT=DIP1+DIP2+DIP3
    IF PERCENT=70 THEN PERCENT=100
    IF BUTTON1 = 0 THEN BOR

    '--------------------------------MAIN LOOP---------------------------

    LOOP:
    IF COININ = 1 THEN COUNT1COIN
    IF COINout = 1 THEN COINOUT100
    IF PORTB.6 = 1 THEN LLA2
    IF LLAVE = 1 THEN LLAVE1
    IF BUTTON1 = 0 THEN SACAR
    GOTO LOOP

    '-------------------------LLAVERO CONNECTED--------------------------

    LLA2:
    PAUSE 500
    FOR X=1 TO 5
    GOSUB INFO
    NEXT X
    GOTO BORRAR

    '--------------------------CONTAR 1 MONEDA---------------------------

    COUNT1COIN:
    PAUSE 20
    IF COININ=1 THEN COUNT1COIN
    TOTAL=TOTAL+1
    GOSUB WRITEIT
    GOTO LOOP

    '----------------------CONTAR 1 MONEDA SALIENDO----------------------

    COINOUT100:
    PREMIOS=PREMIOS+1
    TOTAL=TOTAL-1
    GOSUB WRITEIT
    GOTO LOOP

    '-------------------------CONTAR 1 A CONTADOR------------------------

    CNT:
    COUNTER=1
    PAUSE 40
    COUNTER=0
    PAUSE 50
    RETURN

    '------------------------EL LLAVE DEL CLIENTE------------------------

    LLAVE1:
    PAUSE 100
    IF LLAVE=1 THEN LLAVE1

    IF CAMBIO +AMOUNT > (TOTAL/PERCENT)*100 THEN LOOP
    COUNTING=0
    MOTOR=1

    COUNT100:
    IF COINOUT=1 THEN COUNT100WAIT
    GOTO COUNT100

    COUNT100WAIT:
    PAUSE 5
    IF COINOUT=0 THEN COUNT100DONE
    GOTO COUNT100WAIT

    COUNT100DONE:
    COUNTING=COUNTING+1
    TOTAL=TOTAL-1
    CAMBIO=CAMBIO+1
    GOSUB WRITEIT

    IF COUNTING=AMOUNT THEN
    motor=0
    gosub cnt
    PAUSE 300
    GOTO LOOP
    ELSE
    ENDIF

    gosub cnt

    GOTO COUNT100

    '-----------------------------GUARDAR INFO--------------------------
    WRITEIT:

    WRITE 0,T0
    READ 0,T0
    WRITE 1,T1
    READ 1,T1
    WRITE 2,P0
    READ 2,P0
    WRITE 3,P1
    READ 3,P1
    WRITE 4,C0
    READ 4,C0
    WRITE 5,C1
    READ 5,C1
    RETURN

    'PARA NO BORRAR CON EL BUTTONES AL MENOS QUE NO TIENE UN # DE MAC


    BOR:
    IF BUTTON1 = 0 THEN BOR
    IF MAC > 251 THEN
    GOTO BORRAR1
    ELSE
    GOTO LOOP
    ENDIF

    '----------------------------BORRAR INFO---------------------------

    BORRAR:
    SERIN2 PORTA.3,16780, 500,BORRAR,[WAIT ("CB"),DEC1 DONE]
    IF DONE=1 THEN BORRAR1
    IF DONE=0 THEN MAC1
    GOTO BORRAR

    BORRAR1:
    TOTAL=0
    PREMIOS=0
    CAMBIO=0

    GOSUB WRITEIT

    FOR X=1 TO 5
    GOSUB INFO
    NEXT X

    GOTO LOOP

    '----------------------MANDAR LA INFO AL LLAVERO-------------------

    INFO:

    A = TOTAL * 100 'A is temporary storage of computation
    A = DIV32 PERCENT 'using DIV32... B can be any integer up to 65534
    A = A / 100 'final result is placed in variable A as an integer... any

    PREMIOS=A
    SEROUT2 PORTA.2,16780,["M",DEC3 MAC]
    PAUSE 100
    SEROUT2 PORTA.2,16780,["T",DEC5 TOTAL]
    PAUSE 100
    SEROUT2 PORTA.2,16780,["P",DEC5 PREMIOS]
    PAUSE 100
    SEROUT2 PORTA.2,16780,["%",DEC3 PERCENT]
    PAUSE 100
    SEROUT2 PORTA.2,16780,["S",DEC5 CAMBIO]
    RETURN

    '-----------------------GRABAR EL # DE MAC-------------------------

    MAC1:
    serin2 PORTA.3,16780, MAC1,[WAIT ("M"),DEC3 MAC]
    WRITE 6,MAC
    READ 6,MAC
    FOR X=1 TO 5
    GOSUB INFO
    NEXT X
    GOTO BORRAR

    '------------------------SACAR EL GANACIAS-------------------------

    SACAR:
    PAUSE 100
    IF BUTTON1=0 THEN SACAR
    IF TOTAL < 100 THEN LOOP
    MOTOR=1
    COUNTING=0

    CAMOUNT:
    IF COINOUT=1 THEN CAMOUNTWAIT
    GOTO CAMOUNT

    CAMOUNTWAIT:
    PAUSE 5
    IF COINOUT=0 THEN CDONE
    GOTO CAMOUNTWAIT

    CDONE:
    COUNTING=COUNTING+1
    TOTAL=TOTAL-1
    GOSUB WRITEIT

    IF COUNTING=100 THEN
    MOTOR=0
    PAUSE 300
    GOTO LOOP
    ELSE
    ENDIF
    GOTO CAMOUNT

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