帮我看一个红外的程序,悬赏30分.........高手指点

#include<reg52.h>
#include<intrins.h>
#include"1602.h"
#include"delay.h"
#include"key.h"
#define uchar unsigned char;
sbit jishu=P1^7;
sbit buzzer=P1^6;
uchar k,i,j,value,aa;
uchar irtime;
uchar startflag;
uchar irdata[33];
uchar bitnum;
uchar irreceok;
uchar ircode[4];
uchar irprosessok;
uchar display[10];
unsigned char code word[ ]={"3"}; //定义字符数组显示数字
unsigned char code word11[ ]={"2"};
unsigned char code word22[ ]={"1"};
unsigned char code word1[ ]={"time mode"};
unsigned char code word2[ ]={"count mode"};
void time() //倒计时3 2 1 buzzer
{
w_string(0x80,word);
delay(10000);
w_string(0x80,word11);
delay(10000);
w_string(0x80,word22);
delay(10000);
buzzer=1;
}

void count() //计数模式
{
/* uchar aa=0;
if(jishu==1)
{
aa++;
}
w_string(0x80,word2);
if(aa==9)
aa=0;
*/
KeyOut1=0;
Init_LCD1602();
while(1)
{
if(!KeyIn1)
{
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
if(!KeyIn1)
{
w_string(0x80,word1);
while(!KeyIn1);
}
}
}
}

//***定时器0初始化设置*****//
void timer0init()
{
TMOD=0x20;
TH0=0x00;
TL0=0x00;
EA=1;
ET0=1;
TR0=1;
}
//***外部中断0初始化设置*****//
void int0init()
{
IT0=1;
EX0=1;
EA=1;
}
void irwork()
{
if(ircode[2]==0x16) //按下0,计时开始
{
w_string(0x80,word1);
time();
}
if(ircode[2]==0x0c) //按下1,计数开始
{
count();
}
}
void irprosess() //1.125/0.27776=4此时为0 2.25/0.27776=8 为1 可以取6为0或1的分界
{
uchar k,i,j,value;
for(j=0;j<4;j++)
{
for(i=0;i<8;i++)
{
value=value>>1; //7
if(irdata[k]>6) //8
{
value=value|0x80;
}
k++;
}
ircode[j]=value;
}
irprosessok=1;
}
void main()
{
Init_LCD1602();
timer0init();
int0init() ;
while(1)
{
if(irreceok)
{
irprosess();
irreceok=0;
}
if(irprosessok)
{
irwork();
irprosessok=0;
}
}
buzzer=1;

}
//定时器0的中断服务函数//
void timer1init() interrupt 1
{
irtime++;//max=255;
}
//interrupt 0的中断服务函数//
void int0() interrupt 0
{
if(startflag)
{
if(irtime>32)//检测引导码
bitnum=0;
irdata[bitnum]=irtime;
irtime=0;
bitnum++;
if(bitnum==33)
{
bitnum=0;
irreceok=1;
}
}
else
{
startflag=1;
irtime=0;
}
}
程序没错误,只是按键的话,没反应

if(!KeyIn1)
{
w_string(0x80,word1);
while(!KeyIn1);
应该先做松手检测再进行操作吧
温馨提示:内容为网友见解,仅供参考
第1个回答  2012-07-19
????
相似回答
大家正在搜