51 single chip matrix keyboard

Publisher:BlissfulHeartLatest update time:2019-08-24 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

 

 

uchar code KEY_TABLE[] =

{

    0x77,0xB7,0xD7,0xE7

0x7B,0xBB,0xDB,0xEB

0x7D,0xBD,0xDD,0xED

0x7E,0xBE,0xDE,0xEE

}; //The upper four bits are the columns, the lower four bits are the rows

 

uchar code TABLE[] =

{

    '1', '2', '3',

'4', '5', '6',

'7', '8', '9',

    'C', '0', 'A',

};

 

 

char key_scan()

{

uchar temp, key, i;

P1 = 0xf0; //1111 0000 

    //First scan the column and determine the column

    //Set the high four bits of the column pins to high level, and the low four bits of the row pins to low level. When the button is pressed, it will be pulled low.

    if (P1 != 0xf0)  

        {

            delay_ms(10);

 

            if (P1!= 0xf0)

            {

                temp = P1; //temp exists after pressing

 

                P1 = 0x0f;

                // Scan the line later to determine which line

                //Set the row pin, the lower four bits, to high level, and the column pin, the upper four bits, to low level. When the button is pressed, it will be pulled low.

 

                key = temp | P1;

                //Or the rows and columns, the position where the upper four bits are 0 is the column, and the position where the lower four bits are 0 is the row

 

                for (i = 0; i < 12; ++i) //Find the corresponding key and assign the corresponding character

                    if (key == KEY_TABLE[i])

                        break;

 

                return TABLE[i];

            }

        }

 

else

return 0x00;

}



Reference address:51 single chip matrix keyboard

Previous article:Use 51 single chip microcomputer to output PWM to control the servo
Next article:51 MCU nrf24l01 transceiver

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号