Matrix keyboard C language programming

Publisher:心有归属Latest update time:2021-04-06 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere


The following is the C language source program:


#include

#define uint unsigned int

#define uchar unsigned char

uintled[]={0xc0,0xf9,0xa4, 0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,

0x88,0x83,0xc6,0xa1,0x86,0x8e};

uchar a,b,c,temp;

void delay7ms(void) //error -0.217013888891us

{

unsigned char a,b;

for(b=208;b>0;b--)

for(a=14;a>0;a--);

}


ucharkey()

{

P1=0x0f;

if(P1!=0x0f)

{

delay7ms();

if(P1!=0x0f);


P1=0xfe;

a=P1^0xfe;

switch(a)

{

case 0x80:c=0;break;

case 0x40:c=1;break;

case 0x20:c=2;break;

case 0x10:c=3;break;

}

temp=P1;

while(temp!=0xfe)

{

temp=P1;

}

}


P1=0x0f;

if(P1!=0x0f)

{

delay7ms();

if(P1!=0x0f);

P1=0xfd;

a=P1^0xfd;

switch(a)

{

case 0x80:c=4;break;

case 0x40:c=5;break;

case 0x20:c=6;break;

case 0x10:c=7;break;

}

temp=P1;

while(temp!=0xfd)

{

temp=P1;

}

}



P1=0x0f;

if(P1!=0x0f)

{

delay7ms();

if(P1!=0x0f);

P1=0xfb;

a=P1^0xfb;

switch(a)

{

case 0x80:c=8;break;

case 0x40:c=9;break;

case 0x20:c=10;break;

case 0x10:c=11;break;

}

temp=P1;

while(temp!=0xfb)

{

temp=P1;

}

}


P1=0x0f;

if(P1!=0x0f)

{

delay7ms();

if(P1!=0x0f);

P1=0xf7;

a=P1^0xf7;

switch(a)

{

case 0x80:c=12;break;

case 0x40:c=13;break;

case 0x20:c=14;break;

case 0x10:c=15;break;

}

temp=P1;

while(temp!=0xf7)

{

temp=P1;

}

}

return c;

}


void main(void)

{

while(1)

{

P2=led[b];

b=key();

}

}


Reference address:Matrix keyboard C language programming

Previous article:89C51 programmer end driver example
Next article:MCU Low Power Design Experience

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号