📄 inter.c
字号:
SetBit(Receive_ir_flag,High_45ms_25ms_flag);
SetBit(Receive_ir_flag,Low_9ms_flag);
SetBit(Receive_ir_flag,High_15ms_06ms_flag);
ClrBit(Receive_ir_flag,Last_low_06ms_flag);
ClrBit(Receive_ir_flag,Back_low_06ms_flag);
IR_store_code();
}
}
//-----------------------------------
static void Last_low_06ms(void)
{
if(Store_time_H > 0x04*2 || Store_time_H < 0x01*2)
{
Action_Error();
Code_cont = 0;
return;
}
if((IR_Code_buff[0] + IR_Code_buff[1] == 0xff) && (IR_Code_buff[2] + IR_Code_buff[3] == 0xff))
{
IR_Code_number = IR_Code_buff[2];
SetBit(Receive_ir_flag,No_rece_first_backupcode_flag);
switch(IR_Code_number)
{
case Remote_power:
case Remote_menu:
case Remote_open:
case Remote_display:
case Remote_l_r:
case Remote_title_pbc:
case Remote_setup:
case Remote_1:
case Remote_2:
case Remote_3:
case Remote_4:
case Remote_5:
case Remote_6:
case Remote_7:
case Remote_8:
case Remote_9:
case Remote_0:
case Remote_10_adding:
case Remote_up:
case Remote_down:
case Remote_left:
case Remote_right:
case Remote_enter:
case Remote_mode:
case Remote_osd:
case Remote_mute:
case Remote_search:
case Remote_repeat:
case Remote_jump_back:
case Remote_jump_front:
case Remote_adding:
case Remote_dec:
case Remote_function:
case Remote_stop:
case Remote_play_pause:
ClrBit(System_flag4,Check_long_IR_flag);
SetBit(System_flag,IR_flag);
break;
case Remote_time:
case Remote_slow_back:
case Remote_fast_front:
case Remote_close_panel:
case Remote_open_panel:
SetBit(System_flag4,Check_long_IR_flag);
ClrBit(System_flag,IR_flag);
IR_delay_110ms = 11;
break;
}
Action_Error();
}
}
//-----------------------------------
static void Back_low_06ms(void)
{
Code_cont++;
if((IR_Code_buff[0] + IR_Code_buff[1] == 0xff) && (IR_Code_buff[2] + IR_Code_buff[3] == 0xff))
{
IR_Code_number = IR_Code_buff[2];
if(!ValBit(Receive_ir_flag,No_rece_first_backupcode_flag))
{
if(IR_Code_number == Remote_adding || IR_Code_number == Remote_dec)
SetBit(System_flag,IR_flag);
else
Receive_ir_flag = 0;
}
else
ClrBit(Receive_ir_flag,No_rece_first_backupcode_flag);
}
Action_Error();
}
//-----------------------------------
static void Action_Error(void)
{
ClrBit(Receive_ir_flag,Low_9ms_flag);
ClrBit(Receive_ir_flag,High_45ms_25ms_flag);
ClrBit(Receive_ir_flag,Low_06ms_flag);
ClrBit(Receive_ir_flag,High_15ms_06ms_flag);
ClrBit(Receive_ir_flag,Last_low_06ms_flag);
ClrBit(Receive_ir_flag,Back_low_06ms_flag);
//Receive_ir_flag = 0x00;
Code_cnt1 = 0x00;
Code_cnt2 = 0x00;
}
//------------------------------------
static void Back_high_25ms(void)
{
if((Store_time_H >0x0c*2) || (Store_time_H < 0x06*2))
{
Action_Error();
Code_cont = 0;
ClrBit(Receive_ir_flag,No_rece_first_backupcode_flag);
return;
}
else
{
SetBit(Receive_ir_flag,Low_9ms_flag);
SetBit(Receive_ir_flag,High_45ms_25ms_flag);
SetBit(Receive_ir_flag,Low_06ms_flag);
SetBit(Receive_ir_flag,High_15ms_06ms_flag);
SetBit(Receive_ir_flag,Last_low_06ms_flag);
ClrBit(Receive_ir_flag,Back_low_06ms_flag);
}
}
//------------------------------------
static void IR_store_code(void)
{
unsigned char Code_num;
Code_num = 0x00;
if(Store_time_H >= 0x04*2)
{
Code_num = 0x01;
}
// Code_buff[Code_cnt1] = Code_buff[Code_cnt1] | Code_num;
asm
{
Ld A, Code_cnt1
Ld X, A
Ld A, (IR_Code_buff,X)
Sla A ;C<-A<-0
Or A, Code_num
Ld (IR_Code_buff,X), A
}
if(++Code_cnt2 >= 0x08)
{
if(++Code_cnt1 >= 0x04)
{
SetBit(Receive_ir_flag,0);
SetBit(Receive_ir_flag,1);
SetBit(Receive_ir_flag,2);
SetBit(Receive_ir_flag,3);
}
else
Code_cnt2 = 0x00;
}
}
void Check_long_IR_key(void)
{
if(!ValBit(System_flag4,Check_long_IR_flag) || IR_delay_110ms != 0)
return;
if(Code_cont >= 7) /*The ir key is pressing on but the time is out 1s*/
{
switch(IR_Code_number)
{
case Remote_time: IR_Code_number = Long_Remote_time; break;
case Remote_slow_back: IR_Code_number = Long_Remote_slow_back; break;
case Remote_fast_front: IR_Code_number = Long_Remote_fast_front; break;
case Remote_close_panel: IR_Code_number = Long_Remote_close_panel; break;
case Remote_open_panel: IR_Code_number = Long_Remote_open_panel; break;
}
ClrBit(System_flag4,Check_long_IR_flag);
Code_cont = 0x00;
Action_Error();
SetBit(System_flag,IR_flag);
return;
}
if(IR_low_level_time < 2) /*IR key had not press on,now is free*/
{
ClrBit(System_flag4,Check_long_IR_flag);
Code_cont = 0x00;
SetBit(System_flag,IR_flag);
if(Code_cont >= 7)
{
switch(IR_Code_number)
{
case Remote_slow_back: IR_Code_number = Long_Remote_slow_back; break;
case Remote_fast_front: IR_Code_number = Long_Remote_fast_front; break;
case Remote_close_panel: IR_Code_number = Long_Remote_close_panel; break;
case Remote_open_panel: IR_Code_number = Long_Remote_open_panel; break;
}
}
}
else
{
SetBit(System_flag4,Check_long_IR_flag);
IR_delay_110ms = 11;
}
Action_Error();
IR_low_level_time = 0x00;
}
/***************************************************************
Function:Send the command to the dvd player
***************************************************************/
static Send_command_to_dvd_player(void)
{
unsigned char transmittal_data;
if(!ValBit(Send_dvd_command_flag,First_pull_down_flag))
{
ClrBit(PF_DR,DVD_IR);
SetBit(Send_dvd_command_flag,First_pull_down_flag);
Time_cnt = 17; /*9ms = 18 * 500us*/
return;
}
if(!ValBit(Send_dvd_command_flag,Finish_9ms_pull_high_flag))
{
if(Time_cnt != 0)
Time_cnt--;
else
{
SetBit(PF_DR,DVD_IR);
SetBit(Send_dvd_command_flag,Finish_9ms_pull_high_flag);
Time_cnt = 8; /*4.5ms = 9 * 500us*/
}
return;
}
if(!ValBit(Send_dvd_command_flag,Finish_45ms_pull_low_flag))
{
if(Time_cnt != 0)
Time_cnt--;
else
{
ClrBit(PF_DR,DVD_IR);
SetBit(Send_dvd_command_flag,Finish_45ms_pull_low_flag);
}
return;
}
if(!ValBit(Send_dvd_command_flag,Low_06ms_pull_high_flag))
{
SetBit(PF_DR,DVD_IR);
SetBit(Send_dvd_command_flag,Low_06ms_pull_high_flag);
switch(Send_command_byte_cnt)
{
case 0: transmittal_data = DVD_consumer_code_1;break;
case 1: transmittal_data = DVD_consumer_code_2;break;
case 2: transmittal_data = DVD_command;break;
case 3: transmittal_data = 0xff - DVD_command;break;
}
if(ValBit(transmittal_data,(7 - Send_command_bit_cnt))) /*First send the high bit*/
Time_cnt = 2;
else
Time_cnt = 0;
if(Send_command_byte_cnt >= 4) /*Finish send 4 bytes*/
{
Send_command_byte_cnt = 0;
Send_command_bit_cnt = 0;
Send_dvd_command_flag = 0;
ClrBit(System_flag,Send_command_to_dvd_flag);
}
return;
}
if(!ValBit(Send_dvd_command_flag,Send_one_bit_flag))
{
if(Time_cnt !=0)
Time_cnt--;
else
{
ClrBit(PF_DR,DVD_IR);
if(++Send_command_bit_cnt >= 8) /*Finish send 8 bits*/
{
asm nop;
Send_command_byte_cnt++;
Send_command_bit_cnt = 0;
}
ClrBit(Send_dvd_command_flag,Low_06ms_pull_high_flag);
}
return;
}
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Routine : CdcTimer
Input : Output Compare 2
Output :
Description
- Timer Int Routine to handle Tx & Rx
of SIN-HEUNG CD Changer Output Compare 2
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
static void CdcTimer (void)
{
asm
{
ld a,TIM1_ACH
ld TmpOch,a
ld a,TIM1_ACL
add a,#0xf0
ld TmpOcl,a
ld a,TmpOch
adc a,#0x01
ld TIM1_OC2H,a
ld a,TmpOcl
ld TIM1_OC2L,a
}
#if 0
/*---------For CDC Rx Routine----------*/
if (ValBit(CdcFlag,CdcRx))
{ CrxTimer++;
// if (CrxTimer > 7 ) CrxTimer = 8;
if (CrxTimer > 7 )
{
CrxTimer = 8;
ClrBit(CdcFlag,CdcRx);
}
}
/*-------------CDC Tx Routine----------*/
if (ValBit(CdcFlag,RdyCtx))
{
switch (CtxState)
{
case CT_LOW:
BitClr(PinCDC_Data); /* make low for 500 usec */
CtxState = CT_HIGH;
break;
case CT_HIGH:
BitSet(PinCDC_Data); /* make high */
if ((ctbyte == 2) && (ctbit == 0))
{ /* finished to the last bit ! */
PIN_CdcIn(); /* Change to Input */
ClrBit(CdcFlag, RdyCtx);
ClrBit(CdcFlag, CdcTx);
break;
}
CtxTimer = 3;
CtxState = CT_LOW;
if (ValBit(CtxBuffer[ctbyte],ctbit)) CtxState = CT_WAIT;
ctbit++;
if (ctbit == 8)
{
ctbit = 0;
ctbyte++;
}
break;
case CT_WAIT:
CtxTimer--;
if (CtxTimer == 0) CtxState = CT_LOW;
break;
}
}
#endif
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Routine : CdcTimer1
Input :
Output :
Description
- Timer Int Routine to handle Tx & Rx
of SANYO CD Changer
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
static void CdcTimer1 (void)
{
asm
{
ld a,TIM1_ACH
ld TmpOch,a
ld a,TIM1_ACL
add a,#0x50
ld TmpOcl,a
ld a,TmpOch
adc a,#0x02
ld TIM1_OC2H,a
ld a,TmpOcl
ld TIM1_OC2L,a
}
/*---------For CDC1 Rx Routine----------*/
#if 1
if (Cd1Tout != 0)
Cd1Tout--;
if (Cd1Tout == 0)
ClrBit(CdcFlag,CdcRx); //Time full out then finish receive the data from the changer
if (ValBit(CdcFlag,CdcRx)) //Now in receive mode
{
if (!ValBit(CdcFlag1,SmpReq))
return;
CrxTimer--;
if (CrxTimer == 0)
{
ClrBit(CdcFlag1,SmpReq);
CrxBuffer[crbyte] = CrxBuffer[crbyte] << 1;
CrxBuffer[crbyte] &= 0xFE;
if (Check_CDC_BUS_low)
CrxBuffer[crbyte] |= 0x01;
crxcntr++;
crbit++;
if (crbit == 8)
{
crbit = 0;
crbyte++;
if ((crbyte == 1) && (crbit == 0))
{
switch (CrxBuffer[0] & 0x0F)
{
case CS_CDC:
Crxbits = 64;
break;
case CS_DSC:
Crxbits = 48;
break;
case CS_TOC:
Crxbits = 52;
break;
case CS_ERR:
Crxbits = 32;
break;
case CS_MGZ:
Crxbits = 64;
break;
case CS_CON:
Crxbits = 12;
break;
default:
ClrBit(CdcFlag,CdcRx);
return; /* error ! */
}
}
}
if (crxcntr == Crxbits) /* all received ! */
{
SetBit(CdcFlag,RdyCrx); //Finish receive the data from the changer
ClrBit(CdcFlag,CdcRx); //Exit the receive mode
}
}
}
#endif
/*-------------CDC1 Tx Routine----------*/
if (ValBit(CdcFlag,CdcRx)) return; //In receive data mode then return
if (ValBit(CdcFlag,RdyCtx)) //Now the mode is send the data to the changer
{
switch (CtxState)
{
case CT_LOW:
Make_CDC_BUS_low; /* make low for 600 usec */
CtxTimer = 1;
if (ValBit(CtxBuffer[ctbyte],7-ctbit)) CtxTimer = 3;
CtxState = CT_HIGH;
break;
case CT_HIGH:
CtxTimer--;
if (CtxTimer != 0) break;
Make_CDC_BUS_high; /* make high */
CtxTimer = 3;
if (ValBit(CtxBuffer[ctbyte],7-ctbit)) CtxTimer = 1;
CtxState = CT_WAIT;
break;
case CT_WAIT:
CtxTimer--;
if (CtxTimer != 0) break;
ctxcntr--;
if (ctxcntr == 0)
{ /* finished to the last bit ! */
PIN_CdcIn(); /* Change to Input */
ClrBit(CdcFlag, CdcTx);
CtxTimer = 30; /* 15 msec = 25 * 0.6 */
CtxState = CT_IDLE;
break;
}
ctbit++;
if (ctbit == 8)
{
ctbit = 0;
ctbyte++;
}
CtxState = CT_LOW;
break;
case CT_IDLE:
CtxTimer--;
if (CtxTimer == 0) ClrBit(CdcFlag, RdyCtx);
break;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -