我的红外接收头型号是HS0038B,然后写玩程序后,按键有变化,但是数码管十位会显示不全,为什么?来大神!!!!
我写的是遥控按下,数码管显示对应按键的数
[mw_shl_code=c,true]#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
uint time;
uchar flag,m,ge,shi,ok,a;
sbit dula=P2^6;
sbit wela=P2^7;
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,
0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
uchar jishu[4]={0,0,0,0};
void init();
void display(uchar s,uchar g);
void delay(uchar i);
void main()
{
init();
while(1)
{
if(ok==1)
{
shi=table[jishu[2]&0xf0];
ge=table[jishu[2]&0x0f];
ok=0;
}
for(a=100;a>0;a--)
{
display(shi,ge);
}
}
}
void init()
{
EA=1;
IT1=1;//设为外部中断1为负跳变沿有效
EX1=1;//可以不要吗?
EX1=1;//启动外部中断1
TMOD=0x11;
TH0=0;
TL0=0;
TR0=1;//定时器0运行控制位(=1启动定时器1)
flag=0;
m=0;
ok=0;
shi=0x3f;
ge=0x3f;
}
void display(uchar s,uchar g)
{
wela=1;
P0=0xfe;
wela=0;
dula=1;
P0=s;
dula=0;
delay(5);
wela=1;
P0=0xfd;
wela=0;
dula=1;
P0=g;
dula=0;
delay(5);
}
void delay(uchar i)
{
uchar j,k;
for(j=i;j>0;j--)
for(k=110;k>0;k--);
}
void timer0() interrupt 2
{
time=TH0*256+TL0;
TH0=0;
TL0=0;
if(time>8000&&time<14000)
{
flag=1;
m=0;
}
if(flag==1)
{
if(time>1450&&time<3000)//1码
{
jishu[m/8]=jishu[m/8]>>1|0x80;
m++;
}
if(time>700&&time<1450)//0码
{
jishu[m/8]=jishu[m/8]>>1;
m++;
}
if(m==32)
{
m=0;
flag=0;
if(jishu[2]==~jishu[3])
{
ok=1;
}
else ok=0;
}
}
}[/mw_shl_code]
|