紅外源程序源代碼
/*遙控接收在此中斷程序內完成
//遙控碼放在ir_da[]中
/************************************/
/*? Interrupt for IR subroutine???? */
/*? external interrupt source INT0? */
/************************************/
//#include
//#include "funtion_sub.h"
#include "message.H"
#include "include.h"
//#define uCHAR? unsigned char
extern bit ir_enable;
extern bit ir_start;
extern bit ir_key_continue_pressed;
extern bit Using_Timer1;
extern bit LeaderCode_9MS;
extern bit LeaderCode_4_5MS;
extern bit IR_Sending;
extern bit IR_Keep_Press; //長按
extern bit IR_2MS_Re;
extern bit IR_560US_Re;
extern uCHAR ir_word;
extern uCHAR ir_bit;
extern uCHAR ir_data[4];
extern uCHAR idata??? IR_Tran_data[4];
extern uchar idata IR_Out_Times;
extern uCHAR PRE_REMOTE_KEY;
void RESET_IROUT()
{
LeaderCode_9MS=0; //強制中止IR_OUT
LeaderCode_4_5MS=0;
IR_2MS_Re=0;
IR_Keep_Press=0;
IR_560US_Re=0;
IR_Sending=0;
Using_Timer1=0;
IR_Out_Times=0;
TR1=0;
//EX1_Pri_Hight;
//Timer1_Pri_LOW;
}
void IRTimer1Start(void)
{
TR1=0;
TF1=0;
RESET_IROUT();
TMOD=TMOD|0X10;
TH1=0X00;
TL1=0X00;
Using_Timer1=1;
TR1=1;
}
void int1Remote() interrupt 2
{
uCHAR? tempTH1;
bit ir_0_1,ir_flag;
//if(IR_Out_Times!=0){//正在發送
// return;//有必要的話可以奪取控制權.
// }
//Using_Timer1=1;
tempTH1=TH1;
EX1=0;
ir_flag=0;
ir_enable=0;
if(TF1)
{
IRTimer1Start();
goto ir_return1;
}
IRTimer1Start();
switch(tempTH1)
{
case IR_13_5MS://ir start
ir_word=0;
ir_bit=0;
ir_start=1;
PRE_REMOTE_KEY=0;
ir_key_continue_pressed=0;
goto ir_return1;
case IR_1_125MS://bit '0'
if(ir_start)
{
ir_0_1=0;
ir_flag=1;
}
break;
case IR_2_25MS://bit '1'
if(ir_start)
{
ir_0_1=1;
ir_flag=1;
}
break;
?case IR_11_25MS1://ir key continue pressed
ir_bit=0;
ir_word=4;
ir_key_continue_pressed=1;
break;
default:
ir_bit=0;
ir_word=0;
goto ir_return1;
}
if(ir_flag)
{
ir_data[ir_word]>>=1;
if(ir_0_1){
?? ir_data[ir_word]|=0x80;
}
else{
ir_data[ir_word]&=0x7f;
}
ir_bit++;
ir_flag=0;
}
if(ir_bit==8)
{
ir_word++;
ir_bit=0;
}
if(ir_word==4)
{
ir_word=0;
Using_Timer1=0;
#ifdef RC42
if(ir_key_continue_pressed){
ir_enable=1;
Using_Timer1=0;
PUSH_Message_Buf(IR_Key, ir_data[2]);
}
else if((ir_data[0]==IR_CUSTOM_CODE1)&&(ir_data[1]
==IR_CUSTOM_CODE2)){
ir_enable=1;
Using_Timer1=0;
PUSH_Message_Buf(IR_Key, ir_data[2]);
}
#else
if(ir_key_continue_pressed){
ir_enable=1;
//Using_Timer1=0;
//PUSH_Message_Buf(IR_Key, ir_data[0]);
}
else if((ir_data[2]==IR_CUSTOM_CODE1)&&(ir_data[3]
==IR_CUSTOM_CODE2)){
ir_enable=1;
//Using_Timer1=0;
PUSH_Message_Buf(IR_Key, ir_data[0]);
}
#endif
else{
ir_start=0;
}
}
ir_return1:
INT1=1;
EX1=1;
return;
}
void Timer1Clock(uCHAR T1_TH,uCHAR T1_TL)
{
//Timer1_Pri_Hight;
//EX1_Pri_LOW;
//Using_Timer1=1;
//TR1=0;
//TF1=0;
TMOD=TMOD|0X10;
TH1=T1_TH;
TL1=T1_TL;
TR1=1;
//while(!TF1){};
}
void Timer1_IRQ? () interrupt 3
{
//static uchar i ;
if(IR_560US_Re){ //重發碼結束
goto IR_END;
}
else if(IR_2MS_Re){ //重發碼的低電平0.5ms
IR_OUT=0;
IR_560US_Re=1;
Timer1Clock(IR_560us_TH1,IR_560us_TL1);
}
else if(LeaderCode_9MS){ //前導碼和重發碼的9ms
IR_OUT=1;
LeaderCode_9MS=0;
if(IR_Keep_Press){
IR_2MS_Re=1;
Timer1Clock(IR_2MS_TH1,IR_2MS_TL1);//重發碼的高
電平2mS
}
else{
LeaderCode_4_5MS=1;
IR_Out_Times=0;
Timer1Clock(IR_4_5MS_TH1,IR_4_5MS_TL1);//前導碼
的4.5ms
}
}
else if(LeaderCode_4_5MS){
IR_OUT=0;
LeaderCode_4_5MS=0;
IR_Sending=1;
Timer1Clock(IR_560us_TH1,IR_560us_TL1);
}
else if(IR_Sending){
IR_OUT=1;
if(IR_Tran_data[0]&0x01){//為什么一直用IR_Tran_data[0],參
考RRC_IR_OUT()函數。
Timer1Clock(IR_1960us_TH1,IR_1960us_TL1);//? 1
}
else{
Timer1Clock(IR_560us_TH1,IR_560us_TL1);//???? 0
}
IR_Out_Times++;
if(IR_Out_Times!=33){
LeaderCode_4_5MS=1;
RRC_IR_OUT();
}
else{? //發
送完畢
IR_END:
RESET_IROUT();
EX1=1;
}
}
}
void IR_Start_Tran(uchar Send_Data)
{
IR_Tran_data[0]=Send_Data;
IR_Tran_data[1]=(~IR_Tran_data[0]);
IR_Tran_data[2]=IR_CUSTOM_CODE1;
IR_Tran_data[3]=IR_CUSTOM_CODE2;
LeaderCode_9MS=1;
IR_OUT=0;
EX1=0;
Timer1Clock(IR_9MS_TH1,IR_9MS_TL1);
}
非常好我支持^.^
(2) 100%
不好我反對
(0) 0%