初级会员
- 积分
- 76
- 金钱
- 76
- 注册时间
- 2015-12-12
- 在线时间
- 9 小时
|
#include<intrins.h>
#include"lcd.h"
void Int0Configure(void);
void delay140us(int i);
sbit Ir=P3^2;
unsigned char code CS1[]=" RED CONTROL ";
unsigned char code CS2[]=" IR-CODE:--H ";
unsigned char IrValue[6];
unsigned char t;
void main()
{
unsigned char i;
delayms(70);
LcdInit();
Int0Configure();
LcdWrite(0,0x80);
for(i=0;i<13;i++)
{
LcdWrite(1,CS1[i]);
}
LcdWrite(0,0x80+0X40);
for(i=0;i<13;i++)
{
LcdWrite(1,CS2[i]);
}
while(1)
{
IrValue[4]=IrValue[2]>>4;
IrValue[5]=IrValue[2]&0x0f;
if(IrValue[4]>9)
{
LcdWrite(0,0xc0+0x09);
LcdWrite(1,0x37+IrValue[4]);
}
else
{
LcdWrite(0,0xc0+0x09);
LcdWrite(1,0x30+IrValue[4]);
}
if(IrValue[5]>9)
{
LcdWrite(0,0xc0+0x0a);
LcdWrite(1,0x37+IrValue[5]);
}
else
{
LcdWrite(0,0xc0+0x0a);
LcdWrite(1,0x30+IrValue[5]);
}
}
}
void Int0Configure(void)
{
IT0=1;
EX0=1;
EA=1;
Ir=1;
}
void delay140us(int i)
{
unsigned char k;
while(i--)
{
for(k=0;k<114;k++)
{}
}
}
void Ir_read() interrupt 0
{
unsigned char j,k;
unsigned int err;
delayms(70);
t=0;
if(Ir==0)
{
err=1000;
while((Ir==0)&&(err>0))
{
err--;
delayms(1);
}
if(Ir==1)
{
err=500;
while((Ir==1)&&(err>0))
{
err--;
delayms(1);
}
for(k=0;k<4;k++)
{
for(j=0;j<8;j++)
{
err=60;
while((Ir==0)&&(err>0))
{
err--;
delayms(1);
}
err=500;
while((Ir==1)&&(err>0))
{
err--;
t++;
delay140us(1);
if(t>30)
{
EX0=1;
return;
}
}
IrValue[k]>>=1;
if(t>=5)
{
IrValue[k]|=0x80;
}
t=0;
}
}
}
if(IrValue[2]!=IrValue[3])
{
return;
}
}
}
|
|