MSP430和AT89C51單片機4x4鍵盤C程序
#include
#define uchar unsigned char
#define uint unsigned int
uint key,i;
uchar temp,temp1,ms,buff;
uchar tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,
0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
void delay(ms)
{
while(ms--)
{
for(i=0;i<120;i++);
}
}
void B_key()
{
temp1=0xfe;
P1=temp1;
if(P1!=temp1)
{
delay(10);
if (P1!=temp1)
{
temp=P1;
switch(temp)
{
case 0xee:key=0;break;
case 0xde:key=1;break;
case 0xbe:key=2;break;
case 0x7e:key=3;break;
default:break;
}
}
}
temp1=0xfd;
P1=temp1;
if(P1!=temp1)
{
delay(10);
if (P1!=temp1)
{
temp=P1;
switch(temp)
{
case 0xed:key=4;break;
case 0xdd:key=5;break;
case 0xbd:key=6;break;
case 0x7d:key=7;break;
default:break;
}
}
}
temp1=0xfb;
P1=temp1;
if(P1!=temp1)
{
delay(10);
if (P1!=temp1)
{
temp=P1;
switch(temp)
{
case 0xeb:key=8;break;
case 0xdb:key=9;break;
case 0xbb:key=10;break;
case 0x7b:key=11;break;
default:break;
}
}
}
temp1=0xf7;
P1=temp1;
if(P1!=temp1)
{
delay(10);
if (P1!=temp1)
{
temp=P1;
switch(temp)
{
case 0xe7:key=12;break;
case 0xd7:key=13;break;
case 0xb7:key=14;break;
case 0x77:key=15;break;
default:break;
}
}
}
}
void main()
{
while(1)
{
B_key();
P2=tab[key];
P3=0x04;
}
}
#define uchar unsigned char
#define uint unsigned int
uint key,i;
uchar temp,temp1,ms,buff;
uchar tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,
0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
void delay(ms)
{
while(ms--)
{
for(i=0;i<120;i++);
}
}
void B_key()
{
temp1=0xfe;
P1=temp1;
if(P1!=temp1)
{
delay(10);
if (P1!=temp1)
{
temp=P1;
switch(temp)
{
case 0xee:key=0;break;
case 0xde:key=1;break;
case 0xbe:key=2;break;
case 0x7e:key=3;break;
default:break;
}
}
}
temp1=0xfd;
P1=temp1;
if(P1!=temp1)
{
delay(10);
if (P1!=temp1)
{
temp=P1;
switch(temp)
{
case 0xed:key=4;break;
case 0xdd:key=5;break;
case 0xbd:key=6;break;
case 0x7d:key=7;break;
default:break;
}
}
}
temp1=0xfb;
P1=temp1;
if(P1!=temp1)
{
delay(10);
if (P1!=temp1)
{
temp=P1;
switch(temp)
{
case 0xeb:key=8;break;
case 0xdb:key=9;break;
case 0xbb:key=10;break;
case 0x7b:key=11;break;
default:break;
}
}
}
temp1=0xf7;
P1=temp1;
if(P1!=temp1)
{
delay(10);
if (P1!=temp1)
{
temp=P1;
switch(temp)
{
case 0xe7:key=12;break;
case 0xd7:key=13;break;
case 0xb7:key=14;break;
case 0x77:key=15;break;
default:break;
}
}
}
}
void main()
{
while(1)
{
B_key();
P2=tab[key];
P3=0x04;
}
}
關(guān)鍵詞:
MSP430AT89C51單片
評論