This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Help with error when compiling LPC1768

hello friends
I'm doing a 8x8 LED matrix with LPC1768 and when I compile I get an error that I can not solve also leave some warnings but I did not care much.
could help me? I leave the whole project in keil

many thanks
Ciernes

Parents
  • This function:

    void Matrix_NewFrame(uint8_t array[8])
    {
            matrix[0] = array[0];
            matrix[1] = array[1];
            matrix[2] = array[2];
            matrix[3] = array[3];
            matrix[4] = array[4];
            matrix[5] = array[5];
            matrix[6] = array[6];
            matrix[7] = array[7];
    }
    


    is receiving a pointer to 8 uint8_t elements.

    As can be clearly seen from the implementation of the function, it never tries to modify the content of array[], and so if called as

    Matrix_NewFrame(ascii['A']);
    


    it is not trying to modify the bitmap for the character 'A' in the ascii[] array.

    So the obvious thing to consider then, is to inform the compiler that the function is safe, by modifying the source code so the compiler sees this by adding the "const" keyword.

    Then the compiler will know that there is a binding contract allowing you to call it with "ascii[xxx]" even if ascii[] happens to be const. And so the compiler will not complain about unsafe use of a const variable.

    It really is important that you learn about the difference between "call-by-value" and "call-by-reference" and that you also understand the significance of using "const". And also that "const" can be used in two ways when relating to pointers, i.e. the difference between a const pointer and a pointer to const data.

Reply
  • This function:

    void Matrix_NewFrame(uint8_t array[8])
    {
            matrix[0] = array[0];
            matrix[1] = array[1];
            matrix[2] = array[2];
            matrix[3] = array[3];
            matrix[4] = array[4];
            matrix[5] = array[5];
            matrix[6] = array[6];
            matrix[7] = array[7];
    }
    


    is receiving a pointer to 8 uint8_t elements.

    As can be clearly seen from the implementation of the function, it never tries to modify the content of array[], and so if called as

    Matrix_NewFrame(ascii['A']);
    


    it is not trying to modify the bitmap for the character 'A' in the ascii[] array.

    So the obvious thing to consider then, is to inform the compiler that the function is safe, by modifying the source code so the compiler sees this by adding the "const" keyword.

    Then the compiler will know that there is a binding contract allowing you to call it with "ascii[xxx]" even if ascii[] happens to be const. And so the compiler will not complain about unsafe use of a const variable.

    It really is important that you learn about the difference between "call-by-value" and "call-by-reference" and that you also understand the significance of using "const". And also that "const" can be used in two ways when relating to pointers, i.e. the difference between a const pointer and a pointer to const data.

Children
  • ok I'll try to read carefully what you tell me.
    I'm researching where to put the const word.
    thank you very much

  • ok I put the const in the function:

    void Matrix_NewFrame(const uint8_t array[8]);
    


    but now it seems that there is still something wrong

    Build target 'Target 1'
    compiling main.c...
    compiling matrix.c...
    linking...
    .\matriztest.axf: Error: L6200E: Symbol ascii multiply defined (by matrix.o and main.o).
    .\matriztest.axf: Error: L6200E: Symbol ascii multiply defined (by matrix_font.o and main.o).
    .\matriztest.axf: Error: L6200E: Symbol character_length multiply defined (by matrix.o and main.o).
    .\matriztest.axf: Error: L6200E: Symbol character_length multiply defined (by matrix_font.o and main.o).
    ".\matriztest.axf" - 4 Errors, 0 Warning(s).
    Target not created
    

  • matrix.h

    extern const uint8_t ascii[128][8];
    extern const uint8_t character_length[128];
    

    Then actually define it ONCE

  • This is a time when a sequential reading of a good programming book really would have helped.

    Ever consider the keyword "extern"?
    Ever looked into a book about C regarding use of multiple source files and the use of header files to inform the compiler of what functions and variables the different source files might contain?

    There is a reason why people often start with something simple, like a "hello world!" application and then add new complexities step-by-step instead of trying a big-bang approach. The step-by-step approach teaches all the relevant keywords. How to spell them. What they are good for. When to use them. And it describes the block structure, the control and loop blocks. And covers from simple to more and more complex data type constructs.

    Doing many small steps, with regular positive feedback in form of a working program, is way more satisfying than getting stuck with a too large piece of code and not understanding what is happening and why.

    Note that Google is very good to use when you get an error message - it will very often lead to either other people having had a similar issue (and help they have received with it) or even full lessons teaching that relevant part of coding.

  • The code now does not throw any error, we wanted to thank the patience you have had.
    I certainly started with a "hello world"
    and it seemed easy, so I wanted to take a chance with something bigger
    it is clear that the code is too big and complicated for me, but believe me I'm going to spend long hours studying to do similar things without help.
    I know that no questions are addressed to "stupid" problems in this kind of forums
    but this forum together with two or three more are the ones who have a professional level.
    There are supposedly forums where people try to give you an expert solution
    but unfortunately these people have not shown a higher level mio.
    The next time I come into this forum, I will try to do more constructive questions.
    thank you very much Per Westermark

    carefully: Jonathan