Write and Read from eeprom


Closed Thread
Results 1 to 24 of 24

Hybrid View

  1. #1
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Post EEPROM and index ...

    Hi, Jason

    Did you had a look to THAT Thread ???

    http://www.picbasic.co.uk/forum/showthread.php?t=1078

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  2. #2
    Join Date
    Jun 2007
    Posts
    26


    Did you find this post helpful? Yes | No

    Default uuuuuh ?????

    WOW

    I think that is my problem here. However I only understood a little bit of it.

    Why is this so complicated just to store a word ?

    OK, so I thought storing total.byte0 in location 0 and then storing total.byte1 in location 1 would handle the whole word right ?
    '----------------------------------------------------------------------
    total=33024 or total.byte0=10000000 and total.byte1=11111111
    write 0,total.byte0
    write 1,total.byte1

    If so then in location 0 would be 10000000 and in location 1 would be 11111111
    or is this wrong ?

    if it is right then I can't get that data back the same way ?

    read 0,total.byte0
    read 1,total.byte1

    total=33024

    if not then what ???? I'm more confused then before, but I think your on the right track

  3. #3
    Join Date
    Mar 2005
    Location
    Iowa, USA
    Posts
    216


    Did you find this post helpful? Yes | No

    Default

    total=33024
    Binary(33024) = %1000000100000000
    total.BYTE1 = %10000001
    total.BYTE0 = %00000000

    Quote Originally Posted by PBP Manual
    To write a word, each of the 2 bytes that make up the word must be
    written separately:
    w Var Word
    WRITE 0,w.BYTE0
    WRITE 1,w.BYTE1
    Last edited by rhino; - 8th June 2007 at 20:38.
    Wisdom is knowing what path to take next... Integrity is taking it.
    Ryan Miller

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    And there be the logic error I thought I saw earlier...
    Now build you program up and see what happens...then we can work on optimizing that program a bit. I looks a bit of a mess...not too bad, but could be better...

  5. #5
    Join Date
    Jun 2007
    Posts
    26


    Did you find this post helpful? Yes | No

    Default just an example,

    thank you for setting me straight, however that didnt answer my question. am i reading the data back to "total" correctly ?

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by jason View Post
    thank you for setting me straight, however that didnt answer my question. am i reading the data back to "total" correctly ?
    Did you try it out yet?

  7. #7
    Join Date
    Jun 2007
    Posts
    26


    Did you find this post helpful? Yes | No

    Default yep

    Hello skimask

    Yes Ive been working on your suggestion this whole time, But did get side tracked with one of those replys. so here is the conclusion if I take out "IF COINOUT = 1 THEN COINOUT100" from the main loop it works fine. but I dont see what is wrong there. I dont even have any coins going out while I'm testing this to cause a problem. But ive programed the pic and tested it about 4 times now. every time I take it out of the loop it works fine

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

    that math was wrong but I figured it out. However even if I take that clear out it still wouldn't write correctly

    A = TOTAL * PERCENT
    A = DIV32 100

    so I keeped working until I came to that conclusion

    here is the code in its cut down version with the problem quoted out




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

    A VAR WORD
    DONE VAR BIT
    X VAR BYTE
    PERCENT VAR BYTE
    TOTAL VAR WORD
    PREMIOS VAR WORD
    CAMBIO VAR WORD
    MAC VAR BYTE
    T0 VAR TOTAL.byte0
    T1 VAR TOTAL.byte1
    P0 VAR PREMIOS.BYTE0
    P1 VAR PREMIOS.BYTE1
    C0 VAR CAMBIO.BYTE0
    C1 VAR CAMBIO.BYTE1
    COINOUT VAR PORTB.0
    COININ VAR PORTB.1
    DONE=0
    PERCENT=50

    DISABLE
    GOSUB READIT

    loop:
    IF PORTB.6 = 1 THEN LLACONECTED
    IF COININ = 1 THEN COUNT1COIN
    ' IF COINout = 1 THEN COINOUT100 'this is the problem
    GOTO LOOP

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

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


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

    BORRAR1:
    TOTAL=0
    PREMIOS=0
    CAMBIO=0
    GOSUB WRITEIT
    FOR X=1 TO 5
    GOSUB INFO
    NEXT X
    GOTO LOOP

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

    READIT:
    READ 0,T0
    READ 1,T1
    READ 2,P0
    READ 3,P1
    READ 4,C0
    READ 5,C1
    READ 6,MAC
    RETURN

    INFO:
    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,["S",DEC5 CAMBIO]
    PAUSE 100
    rETURN

    CNT:
    COUNTER=1
    PAUSE 20
    COUNTER=0
    PAUSE 20
    RETURN

    'COINOUT100:
    ' PREMIOS=PREMIOS+1
    ' TOTAL=TOTAL-1
    ' GOSUB WRITEIT
    'GOTO LOOP
    Last edited by jason; - 8th June 2007 at 21:55. Reason: UPDATE

  8. #8
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Try this out:

    Include "modedefs.bas" ' Include serial modes
    DEFINE OSC 4
    TRISA=$1b : trisb=$db : a var word : done var bit : x var byte : percent var byte : total var word : premios var word : cambio var word : mac var byte : t0 var total.byte0 : t1 var total.byte1
    p0 var premios.byte0 : p1 var premios.byte1 : c0 var cambio.byte0 : c1 var cambio.byte1 : coinout var portb.0 : coinin var portb.1 : done=0 : percent=50
    DISABLE
    GOSUB READIT
    loop:
    IF PORTB.6 = 1 THEN LLACONECTED
    IF COININ = 1 THEN COUNT1COIN
    IF COINout = 1 THEN COINOUT100 'this is the problem
    GOTO LOOP
    COUNT1COIN: PAUSE 20 : IF COININ=1 THEN COUNT1COIN
    TOTAL=TOTAL+1 : GOSUB WRITEIT:GOTO LOOP
    LLACONECTED: gosub readit : pause 500:for x=1 to 5:gosub info:next x : goto borrar
    BORRAR: SERIN2 PORTA.3,16780, 500,BORRAR,[WAIT ("CB"),DEC1 DONE]
    IF DONE=1 THEN BORRAR1
    IF DONE=0 THEN
    gosub info:gosub info:gosub info
    endif
    GOTO BORRAR
    BORRAR1: total=0 : premios=0:cambio=0:gosub writeit:for x=1 to 5 : gosub info:next x:goto loop
    writeit: write 0,t0:write 1,t1:write 2,p0:write 3,p1:write 4,c0:write 5,c1 : return
    readit: read 0,t0:read 1,t1:read 2,p0:read 3,p1:read 4,c0:read 5,c1:read 6,mac:return
    info: 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,["S",dec5 cambio]
    pause 100:return
    CNT: COUNTER=1:PAUSE 20:COUNTER=0:PAUSE 20:RETURN
    COINOUT100:
    PREMIOS=PREMIOS+1:if total > 0 then TOTAL=TOTAL-1
    GOSUB WRITEIT:GOTO LOOP
    END
    Last edited by skimask; - 9th June 2007 at 04:06. Reason: Fixed the colons and smiley faces :)

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