MSP430和AT89C51單片機(jī)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單片
相關(guān)推薦
技術(shù)專區(qū)
- FPGA
- DSP
- MCU
- 示波器
- 步進(jìn)電機(jī)
- Zigbee
- LabVIEW
- Arduino
- RFID
- NFC
- STM32
- Protel
- GPS
- MSP430
- Multisim
- 濾波器
- CAN總線
- 開關(guān)電源
- 單片機(jī)
- PCB
- USB
- ARM
- CPLD
- 連接器
- MEMS
- CMOS
- MIPS
- EMC
- EDA
- ROM
- 陀螺儀
- VHDL
- 比較器
- Verilog
- 穩(wěn)壓電源
- RAM
- AVR
- 傳感器
- 可控硅
- IGBT
- 嵌入式開發(fā)
- 逆變器
- Quartus
- RS-232
- Cyclone
- 電位器
- 電機(jī)控制
- 藍(lán)牙
- PLC
- PWM
- 汽車電子
- 轉(zhuǎn)換器
- 電源管理
- 信號(hào)放大器
評(píng)論