新聞中心

EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > MSP430和AT89C51單片機(jī)4x4鍵盤C程序

MSP430和AT89C51單片機(jī)4x4鍵盤C程序

作者: 時(shí)間:2016-11-30 來源:網(wǎng)絡(luò) 收藏

#include "io430.h"
#define uchar unsigned char
#define uint unsigned int
uint key,i;
uchar temp,temp1,ms;
uchar tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,
0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
void delay(uchar ms)
{
while(ms--)
{
for(i=0;i<120;i++);
}
}
void B_key()
{
temp1=0x0e;
P1OUT=temp1;
if(P1IN!=temp1)
{
delay(10);
if (P1IN!=temp1)
{
temp=P1IN|temp1;
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=0x0d;
P1OUT=temp1;
if(P1IN!=temp1)
{
delay(10);
if (P1IN!=temp1)
{
temp=P1IN|temp1;
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=0x0b;
P1OUT=temp1;
if(P1IN!=temp1)
{
delay(10);
if (P1IN!=temp1)
{
temp=P1IN|temp1;
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=0x07;
P1OUT=temp1;
if(P1IN!=temp1)
{
delay(10);
if (P1IN!=temp1)
{
temp=P1IN|temp1;
switch(temp)
{
case 0xe7:key=12;break;
case 0xd7:key=13;break;
case 0xb7:key=14;break;
case 0x77:key=15;break;
default:break;
}
}
}
}
int main( void )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
P1DIR=0x0f;
P2DIR=0xff;
while(1)
{
B_key();
P2OUT=tab[key];
}
}

上一頁(yè) 1 2 下一頁(yè)

關(guān)鍵詞: MSP430AT89C51單片

評(píng)論


技術(shù)專區(qū)

關(guān)閉