⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 inter.c

📁 一款车载DVD的车机源程序(正在生成中的哦)
💻 C
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************
Project  :  RDS Car Radio System
Compiler :  ST7 HiCross C (HiWARE)
Module   :  inter.c
Version  :  V 1.0
Created  :  Feb 20, 1997
Author   :  C. Baek / ST-Korea
Description
         -  Interrupt Routine of RDS Car Radio System.  
            Total 14 interrupts including RESET.
***************************************************************************/
#include "inter.h"
#include "libr.h"
#include "IOport.h"
#include "St72321.h"
#include "System_operation.h"
#include "Touch.h"
#include "Sys_config.h"
#include "CDC.h"
#include "TV_tuner.h"
#include "Menu.h"

//This are use for receive the ir
static unsigned char Previous_H;
static unsigned char Store_time_H;
static unsigned char Code_cnt1;
static unsigned char Code_cnt2;
static unsigned char Code_cont = 0;
static unsigned char IR_Code_buff[4];
unsigned char IR_Code_number;
static unsigned char Receive_ir_flag;
static unsigned char IR_delay_110ms = 11;
static unsigned char IR_low_level_time= 0;
//Use for the timer1
static unsigned char TmpOcl;
static unsigned char TmpOch;
static unsigned char Test_flag;
//Use for send command to dvd player
static unsigned char Send_dvd_command_flag = 0;
static unsigned char Time_cnt ;	/*Counter the time,such as 9ms/4.5ms and so on*/
static unsigned char Send_command_byte_cnt = 0;	/*Counter the bytes ,total are 4 bytes*/
static unsigned char Send_command_bit_cnt = 0;	/*Counter the bits,one byte is 8 bits*/
//Use for the CDC
unsigned int  CdcDelay;
unsigned char CtxBuffer[4];
unsigned char CdcDispDelay;
unsigned char CtxState;
unsigned char ctbit;
unsigned char ctbyte;
unsigned int  CdcTout;
unsigned char CrxBuffer[8];
unsigned int  Cd1Delay;
unsigned char Cd1Tout;
unsigned char ctxcntr; 
unsigned char Crxbits;
unsigned char CrxTimer; //test   
static unsigned char CtxTimer;  
static unsigned char crbyte;
static unsigned char crxcntr; 
static unsigned char crbit;
static unsigned char CdcChkSum; 
static unsigned char itmp;
//------------OSD delay--------------
unsigned int Clear_OSD_delay=500;	//Delay s
//These below are the remote receive's program
static void IR_receiver(void);
static void Low_9ms(void);
static void High_45ms_or_25ms(void);
static void Low_06ms(void);
static void High_15ms_or_06ms(void);
static void Last_low_06ms(void);
static void Back_low_06ms(void);
static void Action_Error(void);
static void Back_high_25ms(void);
static void IR_store_code(void);
void Check_long_IR_key(void);
//This below is the send command to the dvd player program
static Send_command_to_dvd_player(void);

static void CdcTimer (void);
static void CdcTimer1 (void);


/*--------------------------------------------------------------------------
Routine : INT_PortB0123
Input   : PinCDP_c2
Output  :
Description 
        -  
--------------------------------------------------------------------------*/ 
#pragma TRAP_PROC SAVE_REGS
void INT_PortB0123 (void)
{ 
	unsigned char i;
	unsigned char Cunt_time=0;
	if(DVD_SW_low)	//Disc in interrupt
		{
		for(i=0;i<10;i++)
			{
			if(DVD_SW_low)
				Cunt_time++;
			WAIT_100us();
			}
		if(Cunt_time < 5)
			return;
		if(System_mode == DVD_mode)
			{
			SetBit(System_flag3,Disc_in_detect_close_panel_flag);	//When the disc into the rom then will close the panel sometime
			return;
			}
		if(Disc_is_in_rom)	//Had one disc in the rom
			return;
		Hardware_enable_mute_system;
		Hardware_enable_mute_BACK_CON;
		SetBit(System_flag2,Disc_in_flag);
		SetBit(System_flag3,Disc_in_detect_close_panel_flag);	//When the disc into the rom then will close the panel sometime
		Open_DVD_5v_power;
		return;
		}
	
}
/*--------------------------------------------------------------------------
Routine : INT_Timer1
Input   : 
Output  :
Description 
        - General Use of Timer, Transmit Routine of CD Changer
          & Receiving Routine of CD Player
--------------------------------------------------------------------------*/ 
#pragma TRAP_PROC SAVE_REGS
void INT_Timer1 (void)
{
/*-----------Output Compare 1-----------*/
	if (BitVal(TIM1_OCF1))
  		{ /* every 10m normal or 100 msec sleep */ 
  		asm
        	{
           	ld      a,TIM1_OC1L;         // 1 CLK = (1 / 8.664) * 2 * 8 
           	add     a,#0x88              //       = 2000 / 1083 usec    
           	ld      TmpOcl,a             // 10 msec = 5 * 1083 CLKs     
           	ld      a,TIM1_OC1H          //         = 5415 (0x1527 hex) 
           	adc     a,#0x26            // OC = 0x1527 
           	ld      TIM1_OC1H,a			//10ms = 5000 CLKS (0x1388 hex)
           	ld      a,TmpOcl				//
           	ld      TIM1_OC1L,a
        	} 
  		
  		//Check ACC
  		if(ValBit(PF_DR,ACC_ID))	/*Sleep mode*/
			{
			ClrBit(System_flag,ACC_on_flag);
			Hardware_enable_mute_system;
			Hardware_enable_mute_BACK_CON;
  			}
  		
		//Check out the disc delay
  		if(Out_disc_delay != 0)
  			Out_disc_delay--;
  		
  		//Check need to close the DVD power
  		if(ValBit(System_flag4,Close_dvd_power_flag))
  			{
  			if(DVD_close_power_delay != 0)
  				DVD_close_power_delay--;
  			else
  				{
  				Close_DVD_5v_power;
  				ClrBit(System_flag4,Close_dvd_power_flag);
  				}
  			}
  		
  		//Check need to default light current item or not
  		if(ValBit(System_flag2,Close_high_light_item_flag))
  			{
  			if(Item_light_time != 0)
  				Item_light_time--;
  			else
  				{
  				ClrBit(System_flag2,Close_high_light_item_flag);
  				SetBit(System_flag2,Default_light_item_flag);	//Set this flag then in the main program to default light current item's picture
  				}
  			}
  		
  		//Check the volume key's delay
  		if(Volume_key_delay !=0)
  			Volume_key_delay--;
  		//Check detect key
  		if(Key_delay != 0) 
  			Key_delay--;
  		
  		//Check the CDC delay
  		if (CdcTout != 0)     CdcTout--;
  		if (Cd1Delay != 0)    Cd1Delay--; 
  		if (CdcDelay != 0)    CdcDelay--;
  		
  		//Chcek the panel delay
  		if(ValBit(System_flag2,stop_open_close_panel_flag))
  			{
  			if(Open_close_panel_delay != 0)	
  				Open_close_panel_delay--;
  			else
  				{
  				Close_motor_power;	//Close the motor power
				ClrBit(System_flag2,stop_open_close_panel_flag);
  				}
  			}
  		
  		//Chcek when have video signal 5 minute then clear the OSD	
  		if(Clear_OSD_delay != 0)
  			Clear_OSD_delay--;
  		
  		//Check disc in close the panel sometime 
  		if(ValBit(System_flag4,Disc_in_stop_close_panel_flag))
  			{
  			if(Disc_in_close_panel_delay != 0)
  				Disc_in_close_panel_delay--;
  			else
  				{  
  				Close_motor_power;
  				ClrBit(System_flag4,Disc_in_stop_close_panel_flag);
  				}
  			}
  		//Check counter the ir's 110ms
  		if(IR_delay_110ms != 0)
  			IR_delay_110ms--;
  		//Check protect motor 5s
  		if(Protect_motor_delay != 0)
  			Protect_motor_delay--;
		}
/*-----------Output Compare 2-----------*/
	if (BitVal(TIM1_OCF2))
  		{	/* every 500/600 usec */
  		#ifdef CDC_timer_500us
  		CdcTimer();	 /*every 500 usec*/
  		#else
  		CdcTimer1();	/*every 600 usec*/
  		#endif
  		
  		//Check need or not to send command to dvd player
  		if(ValBit(System_flag,Send_command_to_dvd_flag))
  			Send_command_to_dvd_player();
  		
  		//Check need to disable the bell function
  		if(Bell_cnt != 0)
  			Bell_cnt--;
  		else
  			Disable_bell_function;

  		//Test the timer
  		if(TIM2_CNT == 0xff)
  			TIM2_CNT = 0x00;
  		//Check the long ir key's low level time
  		if(ValBit(System_flag4,Check_long_IR_flag))
  			{
  			if(!ValBit(PF_DR,IR))
  				IR_low_level_time++;
  			}
  			
  		}
 	else
 		{
        asm  ld   a,TIM1_OC2L;     /* just clear the flag, ld means clear*/
     	}  
	
 }

/*--------------------------------------------------------------------------
Routine : INT_Timer2
Input   : 
Output  :
Description 
        - For What ???
--------------------------------------------------------------------------*/ 
#pragma TRAP_PROC SAVE_REGS
void INT_Timer2 (void)
{ 
}
/*--------------------------------------------------------------------------
Routine : INT_PortB4567
Input   : 
Output  :
Description 
        - Receiving Routine of SIN-HEUNG/SANYO CD Changer
        - Check Sum (higher nibble of CrxBuffer[7]
          = all higher nibbles except CrxBuffer[7] +
            all lower nibbles of CrxBuffer[0] to [7]
--------------------------------------------------------------------------*/ 
#pragma TRAP_PROC SAVE_REGS
void INT_PortB4567 (void)
{
	#if 1
	//---------CDC interrupt-------------
	if(!ValBit(PB_DR,CDC_BUS))
		{
		if (ValBit(CdcFlag,CdcTx))  return;	//In send data mode then return
  		if (ValBit(CdcFlag,RdyCrx))  return;	//If finish receive the data then return   
  		if (!ValBit(CdcFlag,CdcRx) || (Cd1Tout == 0))
     			{	//First interrupt to receive the data,so you must clear all register and the flags
        		crbit = 0;
        		crbyte = 0; 
        		crxcntr = 0;
        		Crxbits = 0xFF;
        		SetBit(CdcFlag,CdcRx); 
			}     // florent
     		SetBit(CdcFlag1,SmpReq);           /* request to read a bit */
     		Cd1Tout = 30;                      /* 15 ms of timeout */
     		CrxTimer = 2;   // Florent - avoid bug display (2 sec. jump)
		}
	#endif
}

#pragma TRAP_PROC SAVE_REGS
void INT_Sw_rt (void)
{
}

#pragma TRAP_PROC SAVE_REGS
void INT_TLI (void)
{
}


#pragma TRAP_PROC SAVE_REGS
void INT_PortA0123 (void)
{
}

#pragma TRAP_PROC SAVE_REGS
void INT_Spi(void)
{
}
//#pragma TRAP_PROC SAVE_REGS
//void INT_Spi2(void)
//{
//}
#pragma TRAP_PROC SAVE_REGS
void INT_Sci(void)
{
}



#pragma TRAP_PROC SAVE_REGS
void INT_PortF012(void)                                                             
{ 
	/*Remote interrupt routine*/
 	if(TIM2_CNT < Previous_H)
		Store_time_H = TIM2_CNT + (0xff - Previous_H);
	else
		Store_time_H = TIM2_CNT - Previous_H;
	Previous_H = TIM2_CNT;
	IR_receiver();
}

#pragma TRAP_PROC SAVE_REGS
void INT_Eeprom(void)
{
} 

/*-----------------------------------------------------------------------------
ROUTINE NAME : dummy_rt
INPUT/OUTPUT : None

DESCRIPTION  : Empty Interrupt Service Routine

COMMENTS     : all the non-connected interrupt vectors are connected to this empty function
-----------------------------------------------------------------------------*/ 
#pragma TRAP_PROC SAVE_REGS
void dummy_rt(void)
{
}
#pragma TRAP_PROC SAVE_REGS
void INT_MCC(void)
{
	ClrBit(MCCSR,0);
	ClrBit(MCCSR,1);
}
#pragma TRAP_PROC SAVE_REGS
void INT_AVD(void)
{
}
#pragma TRAP_PROC SAVE_REGS
void INT_I2C (void)
{
}
#pragma TRAP_PROC SAVE_REGS
void INT_PWMART(void)
{
}

/*******************************************************************
Function:These below are the remote interrupt routinue
********************************************************************/
static void IR_receiver(void)
{
	if(!ValBit(Receive_ir_flag,Low_9ms_flag))
	{
		Low_9ms();
		return;
	}
	if(!ValBit(Receive_ir_flag,High_45ms_25ms_flag))
	{
		High_45ms_or_25ms();
		return;
	}
	if(!ValBit(Receive_ir_flag,Low_06ms_flag))
	{
		Low_06ms();
		return;
	}
	if(!ValBit(Receive_ir_flag,High_15ms_06ms_flag))
	{
		High_15ms_or_06ms();
		return;
	}
	if(!ValBit(Receive_ir_flag,Last_low_06ms_flag))
	{
		Last_low_06ms();
		return;
	}
	if(!ValBit(Receive_ir_flag,Back_low_06ms_flag))
	{
		Back_low_06ms();
		return;
	}
}
//-----------------------------------------------
static void Low_9ms(void)
{
	if(Store_time_H > 0x25*2 || Store_time_H < 0x23*2)
		{
		Action_Error();
		return;
		}
	else
		{
		SetBit(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);
		}
}
//-----------------------------------
static void High_45ms_or_25ms(void)
{
	if(Store_time_H > 0x13*2)
		{
		Action_Error();
		Code_cont = 0;
		return;
		}
	if(Store_time_H < 0x0E*2)	/*3.5ms*/
		Back_high_25ms();
	else
		{	/*High 4.5ms*/	//New ir signal
		IR_Code_buff[0] = 0xff;
		IR_Code_buff[1] = 0xff;
		IR_Code_buff[2] = 0xff;
		IR_Code_buff[3] = 0xff;
		IR_Code_number = 0xff;
		Code_cont = 0;
		ClrBit(System_flag4,Check_long_IR_flag);
		SetBit(Receive_ir_flag,High_45ms_25ms_flag);
		SetBit(Receive_ir_flag,Low_9ms_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);
		}
}	
//-----------------------------------
static void Low_06ms(void)
{
	if(Store_time_H > 0x04*2 || Store_time_H < 0x01*2)
		{
		Action_Error();
		Code_cont = 0;
		return;
		}
	SetBit(Receive_ir_flag,Low_06ms_flag);
	SetBit(Receive_ir_flag,High_45ms_25ms_flag);
	SetBit(Receive_ir_flag,Low_9ms_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);
}
//-----------------------------------
static void High_15ms_or_06ms(void)
{
	if(Store_time_H > 0x09*2 || Store_time_H < 0x01*2)
		{
		Action_Error();
		Code_cont = 0;
		return;
		}
	else
		{
		ClrBit(Receive_ir_flag,Low_06ms_flag);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -