Digital tube display 4X4 keyboard matrix buttons

Publisher:advancement3Latest update time:2021-12-22 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Function: Digital tube display 4X4 keyboard matrix keys PROTEUS and 51 single chip microcomputer tutorial

insert image description here
insert image description here
insert image description here

The program source code is as follows:


/*

Digital tube display 4X4 keyboard matrix buttons

*/

#include

typedef unsigned char uint8;

typedef unsigned int uint16;


#define BUZZER() P3 ^= 0x01


code uint8 LED_CODE[] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,

0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71};


void delay(uint16 x)

{

uint16 i,j;

for(i = x; i > 0; i --)

for(j = 114; j > 0; j --);

}


uint8 Pre_KeyNO = 16,KeyNO = 16;


void Keys_Scan()

{

uint8 Tmp;

P1 = 0x0f;

delay(1);

Tmp = P1 ^ 0x0f; //High 4 bits output, low 4 bits input

switch(Tmp)

{

case 1: KeyNO = 0; break;

case 2: KeyNO = 1; break;

case 4: KeyNO = 2; break;

case 8: KeyNO = 3; break;

default: KeyNO = 16;

}

P1 = 0xf0;

delay(1);

Tmp = P1 >> 4 ^ 0x0f; // High 4 bits input, low 4 bits output

switch(Tmp)

{

case 1: KeyNO += 0; break;

case 2: KeyNO += 4; break;

case 4: KeyNO += 8; break;

case 8: KeyNO += 12;

}

}


void Beep()

{

uint8 i;

for(i=0;i<100;i++)

{

delay(1);BUZZER();

}

}


void main()

{

P0 = 0x00;

while(1)

{

P1 = 0xf0;

if(P1 != 0xf0)

Keys_Scan();

if(Pre_KeyNO != KeyNO)

{

P0 = LED_CODE[KeyNO];

Beep();

Pre_KeyNO = KeyNO;

}

delay(10);

}

}


Reference address:Digital tube display 4X4 keyboard matrix buttons

Previous article:A single button controls a single digital tube to scroll display
Next article:Microcontroller controls buzzer to sing Happy Birthday song

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号