Write and Read from eeprom


Results 1 to 24 of 24

Threaded View

  1. #20
    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

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