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

accessing array's row 0

I have a matrix for the keyboard layout in my program as follows:

code unsigned char buttons[BUTTON_COUNT][KEY_TABLE_WIDTH]
            = {
                 {'8',        'u',        'ü',        'v',        EMPTY_CODE},
                 {'7',        'r',        's',        'ş',        't'},
                 {'6',        'ö',        'p',        'q',        EMPTY_CODE},
                 {'5',        'l',        'm',        'n',        'o'},
                 {'1',        'a',        'b',        'c',        'ç'},
                 {'2',        'd',        'e',        'f',        EMPTY_CODE},
                 {'3',        'g',        'ğ',        'h',        'ı'},
                 {'4',        'i',        'j',        'k',        EMPTY_CODE},
                 {'9',        'w',        'x',        'y',        'z'},
                 {'0',        ' ',        ':',        '-',        EMPTY_CODE},
                 {RIGHT_ARROW,EMPTY_CODE, EMPTY_CODE, EMPTY_CODE, EMPTY_CODE},
                 {LEFT_ARROW, EMPTY_CODE, EMPTY_CODE, EMPTY_CODE, EMPTY_CODE},
                 {ESC,        EMPTY_CODE, EMPTY_CODE, EMPTY_CODE, EMPTY_CODE},
                 {DEL,        EMPTY_CODE, EMPTY_CODE, EMPTY_CODE, EMPTY_CODE},
                 {CAPS,       EMPTY_CODE, EMPTY_CODE, EMPTY_CODE, EMPTY_CODE},
                 {ENTER,      EMPTY_CODE, EMPTY_CODE, EMPTY_CODE, EMPTY_CODE}
              };

I use this table to use keyboard as in gsm phones to produce letters using 10 buttons.

Code works fine, but when I push on the button 0, it fails to access the row 0 of the array. I can get key '7', but cannot get key '8'. It finds 0x00 for the first row members.

I studied the code produced and tried to investigate using debugger; but they all seem OK to me. However, when I program the AT89C55WD with this code, it cannot find the keys (8, ...) for button 0. Please note all the other keys are OK.

I could not solve this problem, and inserted a dummy row to the table at row 0, and indexed the table with not the button pressed, but with (button+1).

This worked, but since it is just a work-around; I really wonder the reason.

Any ideas?

Parents
  • As a test, I tried this:

    #define EMPTY_CODE  'Z'
    #define RIGHT_ARROW 'R'
    #define LEFT_ARROW  'L'
    #define ESC         'E'
    #define DEL         'D'
    #define CAPS        'C'
    #define ENTER       'E'
    
    #define BUTTON_COUNT    16
    #define KEY_TABLE_WIDTH 5
    
    void list_buttons( void )
    {
        unsigned char row;
        unsigned char col;
    
        for( row = 0; row < BUTTON_COUNT; ++row )
        {
            for( col = 0; col < KEY_TABLE_WIDTH; ++col )
            {
                printf( "buttons[%2d][%2d] = '%c'\n", (unsigned int)row, (unsigned int)col, buttons[row][col] );
            }
            printf( "\n" );
        }
    }
    and got this:
    buttons[ 0][ 0] = '8'
    buttons[ 0][ 1] = 'u'
    buttons[ 0][ 2] = 'ü'
    buttons[ 0][ 3] = 'v'
    buttons[ 0][ 4] = 'Z'
    
    buttons[ 1][ 0] = '7'
    buttons[ 1][ 1] = 'r'
    buttons[ 1][ 2] = 's'
    buttons[ 1][ 3] = 's'
    buttons[ 1][ 4] = 't'
    
    buttons[ 2][ 0] = '6'
    buttons[ 2][ 1] = 'ö'
    buttons[ 2][ 2] = 'p'
    buttons[ 2][ 3] = 'q'
    buttons[ 2][ 4] = 'Z'
    
    buttons[ 3][ 0] = '5'
    buttons[ 3][ 1] = 'l'
    buttons[ 3][ 2] = 'm'
    buttons[ 3][ 3] = 'n'
    buttons[ 3][ 4] = 'o'
    
    etc

    Looks OK to me?

Reply
  • As a test, I tried this:

    #define EMPTY_CODE  'Z'
    #define RIGHT_ARROW 'R'
    #define LEFT_ARROW  'L'
    #define ESC         'E'
    #define DEL         'D'
    #define CAPS        'C'
    #define ENTER       'E'
    
    #define BUTTON_COUNT    16
    #define KEY_TABLE_WIDTH 5
    
    void list_buttons( void )
    {
        unsigned char row;
        unsigned char col;
    
        for( row = 0; row < BUTTON_COUNT; ++row )
        {
            for( col = 0; col < KEY_TABLE_WIDTH; ++col )
            {
                printf( "buttons[%2d][%2d] = '%c'\n", (unsigned int)row, (unsigned int)col, buttons[row][col] );
            }
            printf( "\n" );
        }
    }
    and got this:
    buttons[ 0][ 0] = '8'
    buttons[ 0][ 1] = 'u'
    buttons[ 0][ 2] = 'ü'
    buttons[ 0][ 3] = 'v'
    buttons[ 0][ 4] = 'Z'
    
    buttons[ 1][ 0] = '7'
    buttons[ 1][ 1] = 'r'
    buttons[ 1][ 2] = 's'
    buttons[ 1][ 3] = 's'
    buttons[ 1][ 4] = 't'
    
    buttons[ 2][ 0] = '6'
    buttons[ 2][ 1] = 'ö'
    buttons[ 2][ 2] = 'p'
    buttons[ 2][ 3] = 'q'
    buttons[ 2][ 4] = 'Z'
    
    buttons[ 3][ 0] = '5'
    buttons[ 3][ 1] = 'l'
    buttons[ 3][ 2] = 'm'
    buttons[ 3][ 3] = 'n'
    buttons[ 3][ 4] = 'o'
    
    etc

    Looks OK to me?

Children
No data