本帖最后由 ningyinga 于 2011-7-28 13:26 编辑
按下矩阵键盘第二行时以1200bps发送,1,2,3,4,
#include <reg52.h>
unsigned char num,temp;
unsigned char code table[]={
48,49,50,51,
52,53,54,55,
56,57,58,59};
void display();
void main()
{
TMOD=0x20;
TL1=0XE8;
TH1=0XE8;
TR1=1;
SM0=0;
SM1=1;
while(1)
{
display();
}
}
void display()
{
P3=0xfd;
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
switch(temp)
{
case 0xe0:num=1;break;
case 0xd0:num=2;break;
case 0xb0:num=3;break;
case 0x70:num=4;break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
P1=table[num];
SBUF=table[num];
while(!TI);
TI=0;
}
} |