您的位置:網(wǎng)站首頁 > 電器維修資料網(wǎng) > 正文 >
NEC制式紅外線解碼程序
來源: 日期:2013-12-12 11:13:46 人氣:標(biāo)簽:
#define uchar unsigned char
#define uint unsigned int
//void Delay(unsigned int i);
void chuangkou(void);
void unint0 (void);
void senddata(unsigned char outdata);
unsigned char yandata[]=
{
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'A',
'B',
'C',
'D',
'E',
'F'
};
unsigned char Iid[4]={0,0,0,0};
void main(void)
{
LCD1602();
Init_Lcd();
unint0();
chuangkou();
P3_2=1;
senddata('1');
while(1)
{
Display_LCD_Byte(0,0,'I');
Display_LCD_Byte(0,1,'D');
Display_LCD_Byte(0,2,':');
Display_LCD_Byte(0,5,'0');
Display_LCD_Byte(0,6,'X');
Display_LCD_Byte(0,7,yandata[ Iid[0] / 16] );
Display_LCD_Byte(0,8,yandata[ Iid[0] % 16] );
Display_LCD_Byte(1,0,'D');
Display_LCD_Byte(1,1,'A');
Display_LCD_Byte(1,2,'T');
Display_LCD_Byte(1,3,'A');
Display_LCD_Byte(1,4,':');
Display_LCD_Byte(1,5,'0');
Display_LCD_Byte(1,6,'X');
Display_LCD_Byte(1,7,yandata[ Iid[2] / 16] );
Display_LCD_Byte(1,8,yandata[ Iid[2] % 16] );
}
}
/*void Delay(unsigned int i)
{
while(-- i);
}*/
void chuangkou(void)
{
TMOD = 0X20;// JI SHU QI 1
TH1=0XFA; //11.0592, 4800KPS
TL1 =0XFA;
TR1=1; //QI DONG
SCON=0X50; //
PCON=0X00; //BU JIA BEI
}
void unint0 (void)
{
EA=1;
EX0=1;
IT0=1;
}
void senddata(unsigned char outdata)
{
SBUF=outdata;
while(!TI);
TI=0;
}
void INT_0() interrupt 0 using 1
{
unsigned char id[4]={0,0,0,0};
unsigned char cishu0,cishu1,cishu2;
EX0=0;
for(cishu0=0;cishu0<10;cishu0++)
{
Delay(100);
if(P3_2) goto exit;
}
if(!P3_2)
{
Delay(534);
}
while(!P3_2);//等待高電平 gou qu
for(cishu1=0;cishu1< 4 ; cishu1 ++)
{
for(cishu2=0;cishu2 < 8 ; cishu2 ++)
{
while(!P3_2);//等待該gao電平開始延時(shí),判斷高低
Delay(90);
if(P3_2)
{
id[cishu1]|= 0x01 << cishu2;
Delay(100);
//while(P3_2);在解碼時(shí)千萬不要有這樣的口令
}
/* else
{
id[cishu1]&= 0xfe << cishu2;
}*/
}
}
if(id[0]!=~id[1]) goto exit;
if(id[0]!=0x02) goto exit;
if(id[2]!=~id[3]) goto exit;
senddata(id[0]);
// senddata(id[1]);
senddata(id[2]);//數(shù)據(jù)碼
// senddata(id[3]);//數(shù)據(jù)碼飯嗎
for(cishu0=0;cishu0<200;cishu0++)
{
P2_0=~P2_0;
Delay(50);
}
Iid[0]=id[0];
Iid[2]=id[2];
exit:
// while(!P3_2);
EX0=1;
}
【看看這篇文章在百度的收錄情況】