仿真图如下 要求键盘输入显示在虚拟终端 请教思路
下面的代码可以利用吗
#include<reg51.h>
#include<absacc.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
uchar code segtab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,
0xc6,0xa1,0x86,0x8e,0x89,0x8c,0xff,0xbf,0x8d};
uchar dbuf[4]={0x12,0x12,0x12,0x11};
uchar kbuf[4]={0,0,0,0};
void delay(void)
{ uchar i;
for(i=0;i<250;i++);
}
void init_serial(void)
{ SCON=0x50;
TMOD=0x20;
PCON=PCON&0x7f;
TH1=-3;
TL1=-3;
TR1=1;
}
uchar getkey()
{
uchar key=0;
uchar scode,recode;
P2=0xf0;
if((P2&0xf0)!=0xf0)
{
P2=0xf0;
if((P2&0xf0)!=0xf0)
{scode=0xfe;
while((scode&0x10)!=0)
{ P2=scode;
if((P2&0xf0)!=0xf0)
{recode=P2&0xf0;
scode=0x10;
while(scode!=0)
if(recode&scode==0)
{ while((P2&0xf0)!=0xf0)
{
P2=0xf0;
}
return(key);
}
else
{scode=scode<<1;
key++;
}
}
else
{ scode=_crol_(scode,1);
key=key+4;
}
}
}
}
return(0xff);
}
void main(void)
{ uchar i;
uchar dat;
P0=0xff;
init_serial();
while(1)
{
RI=0;
dat=SBUF;
if(dat==0x41)
{
for(i=4;i>0;i--)
{SBUF=kbuf[i-1]+0x30;
while(TI==0);
TI=0;
}
RI=0;
dat=SBUF;
for(i=0;i<4;i++)dbuf[i]=0x12;
}
}
}
附件列表
仿真.jpg
(2021-6-17 10:15 上传)
原图尺寸 118.85 KB, 下载次数: 34