#include<ir.h>
/*
typedef enum{
IR_idle,
IR_waitstart,
IR_getaddr,
IR_getaddrinv,
IR_getdata,
IR_getdatainv
}_IRstate;
_IRstate IRstate = IR_idle;
unsigned char IRaddr=0xff;
unsigned char _IRaddr=0xff;
unsigned char IRdata=0xff;
unsigned char _IRdata=0xff;
unsigned char IR_repeat=0;
unsigned char IR_ready=0;
*/
unsigned char uup=0; //有连续按键时用
unsigned char IRtimer;
unsigned char phonejack; //有没有音频线状态
unsigned char MUTEstate = 0; //MUTE状态
/*
void IRint() interrupt 0
{
static unsigned char bits;
unsigned short time;
FLAG_Timer = 0;
switch(IRstate)
{
case IR_idle:
LBYTE_Timer=0;
HBYTE_Timer=0;
EN_Timer=1;
IRstate=IR_waitstart;
IRtimer = 26;
break;
case IR_waitstart:
EN_Timer=0;
time=HBYTE_Timer;
time =(time <<8)+LBYTE_Timer;;
LBYTE_Timer=0;
HBYTE_Timer=0;
EN_Timer=1;
if ((time > msec_12p5)&&(time < msec_15)) // greater than 12.5Msec & less than 15 msec = start code
{
IRaddr=0;
_IRaddr=0;
IRdata=0;
_IRdata=0;
bits=1;
IRstate=IR_getaddr;
}
else if ((time > msec_9)&&(time < msec_12p5))// less than 12.5Msec and greater than 9 msec =Repeat code
{
IR_repeat=1;
IRstate=IR_idle;
}
else
{ // to short, bad data just go to idle
IRstate=IR_idle;
}
break;
case IR_getaddr: // P2_4=!P2_4;
EN_Timer=0;
time=HBYTE_Timer;
time =(time <<8)+LBYTE_Timer;;
LBYTE_Timer=0;
HBYTE_Timer=0;
EN_Timer=1;
if ((time>msec_2p5)||(time<msec_0p9))// if > 2.5msec or shorter than .9Msec bad data , go to idle
{
IRstate=IR_idle;
break;
}
if (time>msec_1p68)// greater than 1.68Msec is a 1
{
IRaddr|= bits;
}
bits=bits<<1;
if (!bits)
{
IRstate=IR_getaddrinv;
bits=1;
}
break;
case IR_getaddrinv:
EN_Timer=0;
time=HBYTE_Timer;
time =(time <<8)+LBYTE_Timer;;
LBYTE_Timer=0;
HBYTE_Timer=0;
EN_Timer=1;
if ((time>msec_2p5)||(time<msec_0p9))// if > 2.5msec or shorter than .9Msec bad data , go to idle
{
IRstate=IR_idle;
break;
}
if (time>msec_1p68)// greater than 1.68Msec is a 1
{
_IRaddr|= bits;
}
bits=bits<<1;
if (!bits)
{
IRstate=IR_getdata;;
bits=1;
}
break;
case IR_getdata:
EN_Timer=0;
time=HBYTE_Timer;
time =(time <<8)+LBYTE_Timer;;
LBYTE_Timer=0;
HBYTE_Timer=0;
EN_Timer=1;
if ((time>msec_2p5)||(time<msec_0p9))// if > 2.5msec or shorter than .9Msec bad data , go to idle
{
IRstate=IR_idle;
break;
}
if (time>msec_1p68)// greater than 1.68Msec is a 1
{
IRdata|= bits;
}
bits=bits<<1;
if (!bits)
{
IRstate=IR_getdatainv;
bits=1;
}
break;
case IR_getdatainv:
EN_Timer=0;
time=HBYTE_Timer;
time =(time <<8)+LBYTE_Timer;;
LBYTE_Timer=0;
HBYTE_Timer=0;
EN_Timer=1;
if ((time>msec_2p5)||(time<msec_0p9)) // if > 2.5msec or shorter than .9Msec bad data , go to idle
{
IRstate=IR_idle;
break;
}
if (time>msec_1p68)// greater than 1.68Msec is a 1
{
_IRdata|= bits;
}
bits=bits<<1;
if (!bits) // we have it all , now we make sure it is a NEC code from the CHS IR transmitter
{ // make sure address,~address are correct , data ,~data are correct and address is 0.
if(IRdata^_IRdata){IR_ready=1;}else{IR_ready=0;} //如果后面两个数据互补,则表示接收正确
// IR_ready=((IRaddr^_IRaddr)==0xff)&&((IRdata^_IRdata)==0xff)&&(IRaddr==0); //检查客户码是不是0x00ff
if(IR_ready)
{
IRstate=IR_idle;
}
}
break;
default:
IRstate=IR_idle;
break;
}
}
*/
/*
void IR_init(void) //红外用T0
{
EA = 0;
IRstate = IR_idle;
AUXR &= 0x7F; //定时器时钟12T模式
TMOD &= 0xF0; //设置定时器模式
TMOD |= 0x01; //设置定时器模式
IT0 = 1; //下降沿中断
EX0 = 1; //使能INT0中断
EA = 1; //
}
*/
void Volume_add(void)
{
UINT8 iadd = 5;
UPDOWN = 1;
while(--iadd)
Delay1ms();
CLOCK = 0;
iadd = 5;
while(--iadd)
Delay1ms();
CLOCK = 1;
}
void Volume_sub(void)
{
UINT8 isub = 5;
UPDOWN = 0;
while(--isub)
Delay1ms();
CLOCK = 0;
isub = 5;
while(--isub)
Delay1ms();
CLOCK = 1;
}
void Scan_key(void)
{
UINT16 loop;
if(KEY_SUB == 0)
{LED = 1;
loop = 10;
while((KEY_SUB == 0) && (loop >0))
{--loop;Delay1ms();}
if(KEY_SUB == 0)
{
Volume_sub();
u_sstr("-1\n\r");
flash_LED(20);;
loop = 1500;
while((KEY_SUB == 0) && (loop >0))
{--loop;Delay1ms();}
}
while(KEY_SUB == 0)
{
Volume_sub();
u_sstr("-1\n\r");
flash_LED(20);;
loop = 200;
while((KEY_SUB == 0) && (loop >0))
{--loop;Delay1ms();}
}
}
if(KEY_ADD == 0)
{LED = 1;
loop = 10;
while((KEY_ADD == 0) && (loop >0))
{--loop;Delay1ms();}
if(KEY_ADD == 0)
{
Volume_add();
u_sstr("+1\n\r");
flash_LED(20);
loop = 1500;
while((KEY_ADD == 0) && (loop >0))
{--loop;Delay1ms();}
}
while(KEY_ADD == 0)
{
Volume_add();
u_sstr("+1\n\r");
flash_LED(20);
loop = 200;
while((KEY_ADD == 0) && (loop >0))
{--loop;Delay1ms();}
}
}
if(KEY_MUTE == 0)
{
LED = 1;
loop = 10;
while((KEY_MUTE == 0) && (loop >0))
{--loop;Delay1ms();}
if(MUTEstate == 1)
{
MUTEstate = 0;
// MUTE = 0;
// u_sstr("MUTE\n\r");
}
else
{
MUTEstate = 1;
// MUTE = 1;
// u_sstr("CLOSE MUTE\n\r");
}
flash_LED(20);
while(KEY_MUTE==0)
{
loop = 10;
while(loop >0)
{--loop;Delay1ms();}
}
}
if(CHECK == 0) //没有音频线插入
{
MUTE = 1;
phonejack = 0; //没有音频线
}
else //有耳机
{
if(phonejack == 0)
{
flash_LED(20);
}
phonejack = 1;
if(MUTEstate == 1)
{
MUTE = 1;
}
else
{
MUTE = 0;
}
}
}
/*
void IR_key(void)
{
UINT8 lop = 100;
if(IR_ready) //有按键
{
IR_ready=0;
IR_repeat=0;
if( IRdata == 0x44)
{
LED = 0;
Volume_sub();
while(--lop)
{Delay1ms();}
LED = 1;
}
// u_schar(IRaddr);//先发用户码
// u_schar(IRdata);//数据码
if( IRdata == 0x06)
{
LED = 0;
Volume_add();
while(--lop)
{Delay1ms();}
LED = 1;
}
uup=0;
IR_ready=0;
IR_repeat=0;
return;
}
if(CHECK == 0) //