Please help me!!
#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
#define delayNOP(); {_nop_();_nop_();_nop_();_nop_();};
void smg(uchar x,uchar y);
void send(uchar dat);
void out();
void delay(unsigned char x);
void delay1(int ms);
void irwork();
void display();
sbit IRIN=P3^2;
sbit mosic=P2^2;
sbit r_clka=P2^3;
sbit s_clka=P2^4;
uchar IRCOM[7],irok;
uchar code dula[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar code wela[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
void main()
{
IRIN=1;
delay1(10);
IE=0x81;
TCON=0x01;
if(irok)
while(1)
{
irwork();
display();
}
}
void IR_IN() interrupt 0 using 0
{
unsigned char j,k,N=0;
EX0 = 0;
delay(15);
if (IRIN==1)
{
EX0 =1;
return;
}
while (!IRIN)
delay(1);
for (j=0;j<4;j++)
{
for (k=0;k<8;k++)
{
while (IRIN)
{delay(1);}
while (!IRIN)
delay(1);
while (IRIN)
{
delay(1);
N++;
if (N>=30)
{
EX0=1;
return;
}
}
IRCOM[j]=IRCOM[j] >> 1;
if(N>=8)
{
IRCOM[j] = IRCOM[j] | 0x80;
}
N=0;
}
}
if(IRCOM[2]!=~IRCOM[3])
{
EX0=1;
return;
}
irok=1;
EX0 = 1;
}
void delay(unsigned char x) //x*0.14MS
{
unsigned char i;
while(x--)
{
for (i = 0; i<13; i++) {}
}
}
void delay1(int ms)
{
unsigned char y;
while(ms--)
{
for(y = 0; y<250; y++)
{
_nop_();
_nop_();
_nop_();
_nop_();
}
}
}
void smg(uchar x,uchar y)
{
send(wela[x]);
send(dula[y]);
out();
}
void send(uchar dat)
{
uchar i;
for(i=0;i<8;i++)
{
if((dat<<i)&0x80)
mosic=1;
else
mosic=0;
s_clka=0;
s_clka=1;
}
}
void out()
{
r_clka=0;
r_clka=1;
}
void irwork()
{
smg(0,IRCOM[0]/16);
smg(1,IRCOM[0]%16);
smg(2,IRCOM[1]/16);
smg(3,IRCOM[1]%16);
smg(4,IRCOM[2]/16);
smg(5,IRCOM[2]%16);
smg(6,IRCOM[3]/16);
smg(7,IRCOM[3]%16);
}
void display()
{
while(1)
irwork();
}
-
-
HT6221遥控.pdf
下载积分: 积分 -1 分
214 KB, 下载次数: 10, 下载积分: 积分 -1 分
一周热门 更多>