#include <reg51.h>
#include <intrins.h>
#define NOP() _nop_()
#define uchar unsigned char
#define uint unsigned int
#define delayNOP(); {_nop_();_nop_();_nop_();_nop_();};
void delay(uchar x);
void delay1(int ms);
void beep(void);
sbit IRIN = P3^2; //红外接收器数据线
sbit BEEP = P1^5; //蜂鸣器驱动线
sbit LED1=P1^0; //主音量 +
sbit LED2=P1^1; //主音量 -
sbit LED3=P1^2; //高音 -
sbit LED4=P1^3; //高音 +
sbit LED5=P3^3; //低音 -
sbit LED6=P3^4; //低音 +
sbit key1=P2^0; //切换
sbit key2=P2^1; //静音
sbit key3=P2^2; //开关
sbit QIEHUAN=P2^3; //切换键 怎么让这几个按键控制 p2.3 p2.4 p2.5
sbit JINGYIN=P2^4; //静音键
sbit OFF=P2^5; //开关键
uchar IRCOM[7];
uchar cdis1[] = {" REMOTE CONTROL "};
uchar cdis2[] = {" IR-CODE: ----H"};
main()
{
IE = 0x81;
TCON = 0x01;
IRIN=1;
BEEP=1;
}
void IR_IN(void) interrupt 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;
}//end for k
}//end for j
if (IRCOM[2]!=~IRCOM[3])
{ EX0=1;
return; }
IRCOM[5]=IRCOM[2] & 0x0F;
IRCOM[6]=IRCOM[2] >> 4;
if(IRCOM[5]>9)
{ IRCOM[5]=IRCOM[5]+0x37;}
else
IRCOM[5]=IRCOM[5]+0x30;
if(IRCOM[6]>9)
{ IRCOM[6]=IRCOM[6]+0x37;}
else
IRCOM[6]=IRCOM[6]+0x30;
switch(IRCOM[2])
{
case 0x09: LED1=0;
delay(250);
LED1=1; break;
case 0x15: LED2=0;
delay(250);
LED2=1; break;
case 0x07: LED3=0;
delay(250);
LED3=1; break;
case 0x44: LED4=0;
delay(250);
LED4=1; break;
case 0x40: LED5=0;
delay(250);
LED5=1; break;
case 0x43: LED6=0;
delay(250);
LED6=1 ;break;
case 0x0D: QIEHUAN=!QIEHUAN; break; //切换
case 0x45: OFF=!OFF; break; //静音
case 0x47: JINGYIN=!JINGYIN; break; //开关
}
beep();
EX0 = 1;
}
/**********************************************************/
void beep(void)
{
unsigned char i;
for (i=0;i<100;i++)
{
delay(4);
BEEP=!BEEP; //BEEP取反
}
BEEP=0; //关闭蜂鸣器
}
/**********************************************************/
void delay(unsigned char x)
{
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_();
}
}
} |