Discussion Forum

accessing array's row 0

Next Thread | Thread List | Previous Thread Start a Thread | Settings

DetailsMessage
Read-Only
Author
Bahri Okuroglu
Posted
23-Oct-2001 08:35 GMT
Toolset
C51
New! 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?
Read-Only
Author
Andrew Neil
Posted
23-Oct-2001 10:53 GMT
Toolset
C51
New! RE: accessing array's row 0
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?
Read-Only
Author
Jon Young
Posted
23-Oct-2001 14:32 GMT
Toolset
C51
New! RE: accessing array's row 0
Did you look in your hex code for '8uüv.' ? Was it there before '7rsşt'?

The micro cannot "find" the keys (8, ...). What did it find?

Do you get overlay errors when you link?
Read-Only
Author
Bahri Okuroglu
Posted
23-Oct-2001 15:26 GMT
Toolset
C51
New! RE: accessing array's row 0
Jon,

Yes, I checked the matrix with debugger and 8uü were there before 7...

And, with debugger there was not any problem. It works fine in the debugger.

Read-Only
Author
Bahri Okuroglu
Posted
23-Oct-2001 15:31 GMT
Toolset
C51
New! RE: accessing array's row 0
and, yes there was no compiler/linker warnings. Also, I disabled overlaying using nooverlay flag of the linker.
Read-Only
Author
Jon Young
Posted
24-Oct-2001 13:07 GMT
Toolset
C51
New! RE: accessing array's row 0
Interesting, can I see the good and bad code?
Read-Only
Author
Bahri Okuroglu
Posted
24-Oct-2001 15:05 GMT
Toolset
C51
New! RE: accessing array's row 0
Jon,

I know that it sounds weird. And in fact there is no good code. :)

The function may be a bit long to post here, so I can email it to you if you send an email to bahrio at yahoo dot com.

Next Thread | Thread List | Previous Thread Start a Thread | Settings