|
c51红外通讯程序
void int1Remote() interrupt 2 { uCHAR tempTH1; bit ir_0_1,ir_flag; 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; } else if((ir_data[2]==IR_CUSTOM_CODE1)&&(ir_data[3]==IR_CUSTOM_CODE2)) { ir_enable=1; 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) { TMOD=TMOD|0X10; TH1=T1_TH; TL1=T1_TL; TR1=1; } void Timer1_IRQ () interrupt 3 { 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); }
上一页 [1] [2] |
|