Read/Write Problem


Closed Thread
Results 1 to 2 of 2
  1. #1

    Default Read/Write Problem

    18F4620 chip

    I can read data fine but when I go to write it appears that I am writing the same data to all EEPROM locations. I am only putting in the relevant code. The entire code is 1400 lines.

    Code:
    Stage1TOnS      data    word      0000      '''''''''''''
    Stage1TOffS     data    word      10000
    Stage1ROnS      data    word      0000
    Stage1ROffS     data    word      11000
    Stage2TOnS      data    word      0800   '''''''''''''
    Stage2TOffS     data    word      12000
    Stage2ROnS      data    word      0000
    Stage2ROffS     data    word      13000
    Stage3TOnS      data    word      1200   '''''''''''''
    Stage3TOffS     data    word      14000
    Stage3ROnS      data    word      0000
    Stage3ROffS     data    word      15000
    Stage4TOnS      data    word      1500   '''''''''''''
    Stage4TOffS     data    word      16000
    Stage4ROnS      data    word      0000
    Stage4ROffS     data    word      17000 
    Stage5TOnS      data    word      0400   '''''''''''''
    Stage5TOffS     data    word      18000
    Stage5ROnS      data    word      6800
    Stage5ROffS     data    word      19000 
    Stage6TOnS      data    word      0800   '''''''''''''
    Stage6TOffS     data    word      20000
    Stage6ROnS      data    word      7000 
    Stage6ROffS     data    word      21000
    Stage7TOnS      data    word      1200   '''''''''''''
    Stage7TOffS     data    word      22000
    Stage7ROnS      data    word      23000
    Stage7ROffS     data    word      24000
    Stage8TOnS      data    word      1600   '''''''''''''
    Stage8TOffS     data    word      25000
    Stage8ROnS      data    word      2000
    Stage8ROffS     data    word      26000
    Stage1TrigS     data    byte       0
    Stage2TrigS     data    byte       0
    Stage3TrigS     data    byte       0
    Stage4TrigS     data    byte       0
    
    StagesX         VAR WORD[32]
    StagesY         VAR BYTE[16]
    Index           VAR BYTE
    Index2          VAR BYTE
    Temp            VAR WORD
    Stage1TOn       VAR StagesX[0]  'EEprom location from 0 to 63.
    Stage1TOff      VAR StagesX[1]
    Stage1ROn       VAR StagesX[2]
    Stage1ROff      VAR StagesX[3]
    Stage2TOn       VAR StagesX[4]
    Stage2TOff      VAR StagesX[5]
    Stage2ROn       VAR StagesX[6]
    Stage2ROff      VAR StagesX[7]
    Stage3TOn       VAR StagesX[8]
    Stage3TOff      VAR StagesX[9]
    Stage3ROn       VAR StagesX[10]
    Stage3ROff      VAR StagesX[11]
    Stage4TOn       VAR StagesX[12]
    Stage4TOff      VAR StagesX[13]
    Stage4ROn       VAR StagesX[14]
    Stage4ROff      VAR StagesX[15]
    Stage5TOn       VAR StagesX[16]
    Stage5TOff      VAR StagesX[17]
    Stage5ROn       VAR StagesX[18]
    Stage5ROff      VAR StagesX[19]
    Stage6TOn       VAR StagesX[20]
    Stage6TOff      VAR StagesX[21]
    Stage6ROn       VAR StagesX[22]
    Stage6ROff      VAR StagesX[23]
    Stage7TOn       VAR StagesX[24]
    Stage7TOff      VAR StagesX[25]
    Stage7ROn       VAR StagesX[26]
    Stage7ROff      VAR StagesX[27]
    Stage8TOn       VAR StagesX[28]
    Stage8TOff      VAR StagesX[29]
    Stage8ROn       VAR StagesX[30]
    Stage8ROff      VAR StagesX[31]
    Stage1Trig      VAR StagesY[0]  'EEprom location from 64 to 79.
    Stage2Trig      VAR StagesY[1]
    Stage3Trig      VAR StagesY[2]
    Stage4Trig      VAR StagesY[3]
    
    Gosub Read_Data
    Then display data on LCD and data is fine. 
    Gosub Write_Data
    Data on display shows 26000 for all variables, which is Stage8ROffS     data    word      26000
    
    Read_Data:
      Index2 = 0
      FOR Index = 0 TO 62 STEP 2
          READ Index,Temp.LowByte       ' Word sized data. Index is the eeprom addr.
          READ (Index+1),Temp.HighByte
          StagesX[Index2] = Temp        'Index2 is array adr.
                      
          IF Index2 < 4 THEN READ (Index2+64),StagesY[Index2]  ' Byte sized data.
          Index2 = Index2 + 1     ' Max. 31.
      NEXT Index
    return
    
    Write_Data:
      Index2 = 0
      FOR Index = 0 TO 62 STEP 2
          Write Index,Temp.LowByte       ' Word sized data. Index is the eeprom addr.
          Write (Index+1),Temp.HighByte
          StagesX[Index2] = Temp        'Index2 is array adr.
                      
          IF Index2 < 4 THEN Write (Index2+64),StagesY[Index2]  ' Byte sized data.
          Index2 = Index2 + 1     ' Max. 31.
      NEXT Index
    return

  2. #2
    Join Date
    Nov 2007
    Location
    South-West of Australia. A small town called Denmark. 'Where the forest meets the sea.'
    Posts
    136


    Did you find this post helpful? Yes | No

    Default Read/write

    I think the problem is in:

    A. The READ works OK because you get Temp.LowByte/HighByte from EEPROM and put the Temp word into your array.

    B. The WRITE fails because you just write Temp.LowByte/Highbyte into EEPROM and the 'array read' is after this - put the 'array read' before the EEPROM write and all will be OK - I hope?

    Regards Bill Legge

Similar Threads

  1. problem with sending data using RF module
    By rano_zen06 in forum mel PIC BASIC Pro
    Replies: 51
    Last Post: - 10th April 2008, 17:08
  2. USART Problem , but don't know where, in pc? or in PIC?
    By precision in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 15th July 2007, 08:12
  3. 1 slave 1 master 1 MAX232 1 problem ?
    By SuB-ZeRo in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 31st July 2005, 22:59
  4. weird 12F629/675 problem
    By peterdeco1 in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 7th October 2004, 01:08
  5. PORTA.PinNo = 1 ' problem
    By frank small in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 6th May 2004, 14:30

Members who have read this thread : 1

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