+ Post New Thread
Results 1 to 4 of 4
  1. #1
    Member level 2
    Points: 335, Level: 3

    Join Date
    Mar 2019
    Posts
    51
    Helped
    0 / 0
    Points
    335
    Level
    3

    For loop termination with data in array is 0xff

    Hiee members,
    i'm working on a project which is send binary file to EEPROM, read it back and display it on uart terminal.
    i'm using PIC16F877A micro controller, xc8 compiler and 93lc46a eeprom.
    i'm able to sending/reading the file to/from eeprom properly.
    Code:
    for(j=0; j < 64 ;j++)
        {
            Ewen();
            __delay_ms(100);
            Write(write_addr2, RxData[j]);
            __delay_ms(100);
            Ewds();
            Rx_file = Read(write_addr2);
            Result[j] = Rx_file;
            write_addr2++;
        }
        for(j = 0;j < 64; j++)
        {
            output = strcmp(RxData[j],Result[j]);
            if(output == 0)
            {
                UART_TxChar(Result[j]);
            }
            else
            {
                RD0 = 1;
                UART_str(error);
            }
        }
         __delay_ms(1000);
    i split the binary file (size 128 bytes) into two arrays, the above code is for first 64 bytes of data, in the code i'm comparing each byte of data, the problem is the for loop terminates at j = 62, (RxData[62] = FF ) . i don't know why? i have few doubt does it treats FF as end of the file, can i use strcmp in side for loop?
    Last edited by mayasunny; 27th August 2019 at 12:57.

    •   AltAdvertisement

        
       

  2. #2
    Super Moderator
    Points: 259,376, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    45,285
    Helped
    13777 / 13777
    Points
    259,376
    Level
    100

    Re: For loop termination with data in array is 0xff

    Why strcmp(), it's for null terminated strings? You want to compare single bytes, e.g.
    Code:
    if (RxData[j] == Result[j])



    •   AltAdvertisement

        
       

  3. #3
    Member level 2
    Points: 335, Level: 3

    Join Date
    Mar 2019
    Posts
    51
    Helped
    0 / 0
    Points
    335
    Level
    3

    Re: For loop termination with data in array is 0xff

    Thanks for your reply, I solved the problem with if(RxData[j]== Result[j])
    One more question how can I send two files to the eeprom one by one



    •   AltAdvertisement

        
       

  4. #4
    Advanced Member level 2
    Points: 3,117, Level: 13
    baileychic's Avatar
    Join Date
    Aug 2017
    Posts
    622
    Helped
    49 / 49
    Points
    3,117
    Level
    13

    Re: For loop termination with data in array is 0xff

    microSD Card interface to read files and above code to send read bytes to eeprom.



--[[ ]]--