Write and Read from eeprom


Closed Thread
Results 1 to 24 of 24

Hybrid View

  1. #1
    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 05:06. Reason: Fixed the colons and smiley faces :)

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Get a few more Colon's in there and we're gonna be in deep ____.

    Or have a cancer problem.
    <br>
    DT

  3. #3
    Join Date
    Oct 2004
    Location
    Hangover, Germany
    Posts
    289


    Did you find this post helpful? Yes | No

    Exclamation

    What happens, if you switch off the power ?
    Maybe the code just think, the switch is pressed and try to write to the eeprom - while power is falling...
    PBP 2.50C, MCS+ 3.0.0.5, MPLAB 8, MPASM 5.14, ASIX Presto, PoScope, mE mikroBasic V7.2, PICKIT2

  4. #4
    Join Date
    Jun 2007
    Posts
    26


    Did you find this post helpful? Yes | No

    Default BigWumpus's was right !!!

    Yep that is my problem.

    if I take out the "write" it saves fine

    COINOUT100:
    PREMIOS=PREMIOS+1:if total > 0 then TOTAL=TOTAL-1
    :GOTO LOOP 'GOSUB WRITEIT

    So I did a little checking and the machine I'm interfacing to sends several signals as its lossing power, somthing to do with a cheap design cause theres no other reason. I will buy a scope to see if its a specific signal or just random crap. I think its just random crap cuase if I hook a anolog counter to it, it counts up to differrent amounts somtime 3 somtimes up to 6.

    As to my messy code design, I'm sorry skimask. I have never had any training of any kind nor has anyone ever showed me how to write decent code. This is the first time in 15 years I have ever been on a forum for basic, quickbasic, visual basic, or pic basic pro.

    I am one to learn things on my own, but as you pointed out (at my messy code) that type of learning has its problems. I do my best

    I will continue this forum experience, Its al right. thank you all for your help with this one.

    And thank you BigWumpus for figuring this one out for me......

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, 15:46
  2. Problem with I2C EEPROM addressing
    By Atom058 in forum General
    Replies: 14
    Last Post: - 3rd November 2009, 04:17
  3. write -read problem?
    By turkuaz in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 30th August 2009, 14: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, 15:19
  5. word variable to 25lc640
    By TONIGALEA in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 6th July 2004, 20: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