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

ARM LPC2000 GPIO problem

I have a problem reading input pins on the LPC2138.
I used the following assignment in the Keil uVision3 and got the following error:
CODE FRAGMENT
unsigned int Key_0=IOPIN1& 0x00080000; // Read input pin P1.24

ERROR
error: KeyPad.c(36): error: #28: expression must have a constant value.

What could be the problem? How do I read an input (IOPIN) and store the value?

Parents Reply Children
  • Back to the drawing board again.

    Still lots of magic numbers that can't be understood.

    What is GREEN? I most definitely can't look at the declaration:

    #define  GREEN       0x00FF0000  // 7Seg  display p1
    


    and deduce any meaning. Do you have a single 7-segment digit placed on P0.16..23? Why name it GREEN?

    What does Keypad4x4 mean? Shouldn't the function be called ScanKeypad, to inform that it actually does something?

    Your keyboard scanner has an interesting logic. You scan one column at a time with individual timing loops for each individual button. What happens if you have multiple keys pressed?

    What are your expected result if you press two keys from the same row? From the same column? Two keys from different rows and columns?

    A 4x4 keypad has 16 buttons. You normally write a keyboard scanner that produces a numeric sequence. For example 0..15 for one key pressed, 16 for no key pressed, 17 for multiple keys pressed.

    Then you can later convert the key-press into ASCII characters, or 7-segment patterns with a single table lookup depending on what you want to do with the key-presses.

    Or if you do support multiple keys, return an unsigned int, with 16 bits for the 16 possible keys.

    The normal way is to have one debounce loop and then you walk the 4 columns and pick up the row values, with acceptance only if one single column has one single row bit detected. More advanced scenarios can be implemented but then you normally have to take care of key-down and key-up so that you can implement n-key rollover and auto-repeat if a key is pressed longer than a specific time.

    Do you want key repeat? It is common to implement the keyboard scanner so that it doesn't constantly repeat a pressed key (or as extension starts to repeat after a mimimum wait time). If you press a key now, and call your keyboard scanner multiple times, each call will detect the key. That is ok if your display is expected to just show the last key pressed. But if you enter a number, it will be hard to just press a one, and not instead manage to enter several ones, the repetition only controlled by how fast your main loop manages to call your keyboard scanner.

    The logic may be simpler if you have one function that performs the debounce, and let this function call another function that performs the low-level scan.

    How do you indent your code? A number of lines are first on the line - are you mixing tab and space? Another thing: Is there a hidden message to be extracted by looking at the number of spaces between statement and the semicolon?

    Don't create variables ZERO, ONE, TWO, ... Why are they variables? They only get one single assigned constant value, which implies that they are not variables but constants.

    And why are they defined as bit-and of the GREEN constant?

    Instead, create a 10-entry lookup table that specifies what segments to light for the digit 0..9 (preferably without shifting for actual pins used, to allow the table to be used for multiple 7-segment digits).

    Avoid extra global variables. KeyBounce is used by your keyboard scanner, never outside.

  • // write to 7seg Function t
    void Write_2_7Seg(void)
    

    It isn't a good idea to use SMS speech in a forum. And it is just as bad to use it in source code.

    Write_2_7Seg() could just as well mean the second row of digits, or that you write to two digits.