|
這是我的關(guān)于紅外線接收的程序,其中某一行為什么是這樣,我已用中文標(biāo)注在下面
#include<reg52.h>
#define uchar unsigned char
sbit ir=P3^2;
sbit FM=P2^3;
uchar num,flag,receive,bite;
uchar irdate[33];
void hwtx_init()
{
TMOD&=0x0f;
TMOD|=0x20;
TH1=0;
TL1=0;
EA=1;
ET1=1;
TR1=1;
EX0=1;
IT0=1;
}
void hwtx_work()
{
uchar i,j,k,value;
uchar irrecorde[4];
k=1;
for(i=0;i<4;i++)
{
value=0;
for(j=0;j<8;j++)
{
value=value>>1 // 一定要在if語(yǔ)句前面,如果放在if語(yǔ)句后面的話,肯定出錯(cuò), 為什么 if(irdate[k]>6) value|=0x80;
k++;
}
irrecorde=value;
}
switch(irrecorde[2])
{
case 0x46:FM=0;break;
case 0x45:FM=0;break;
case 0x47:FM=0;break;
case 0x43:FM=0;break;
default:FM=1;
}
}
void hwtx_recive()
{
if(receive)
{
receive=0;
hwtx_work();
}
}
void main()
{
hwtx_init();
while(1)
{
hwtx_recive();
}
}
void fun1() interrupt 0
{
if(flag)
{
if(num>32&&num<63) bite=0;
irdate[bite]=num;
num=0;
bite++;
if(bite==33)
{
bite=0;
receive=1;
}
}
else
{
flag=1;
num=0;
}
}
void fun2() interrupt 3
{
num++;
}
|
|