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

📄 cpu.c

📁 车载DVD osdIC TW8816原厂代码
💻 C
📖 第 1 页 / 共 2 页
字号:
	tm001++;
	
	//---------- 0.01 sec timer ------------
	
	#ifdef CLOCK_11M
	if( tm001 > 48 ) {			// LJY001220 0.01sec
	#elif defined CLOCK_22M
	if( tm001 > 48*2 ) {		// LJY001220 0.01sec
	#endif

		tm001 = 0;
		tic01++;
		
		if( tic01==100 ) {				// 1 sec
			SystemClock++;
			tic01 = 0;
		}
		if( tic_pc!=0xffff ) 
			tic_pc++;

	///////////////////////////////////////////	
	if( _ReadKey() ) {
		if( keytic==3 ) {
			Key = _ReadKey();
			RepeatKey = 0;
			KeyReady = 1;
		}
		else if( keytic==100 ) {
			Key = _ReadKey();
			RepeatKey = 1;
			KeyReady = 1;
			keytic = 80;
		}
		keytic++;
	}
	else 
		keytic = 0;
	///////////////////////////////////////////	

		// Hans
		if (cDelayCounter > 0)
			cDelayCounter--;
	}
}
//------------------------------------------------------------------
// void	InitVars(void) - variable initialize
//------------------------------------------------------------------
void	InitVars(void)
{
	SystemClock=0;			//00:00
	LastBlockedTime=0xffffffff;		//00:00	//ljy010904...CC_FIX_CLEAR_ON_TIME..oops! previous vchip clear error 
	OffTime=0xffff;
	SleepTimer=0;
	SleepTime=0xffff;

	SEL_DVI=  1;		// disable Digital VGA
	// ResetKey();

	DebugLevel		= 0;
	RemoDataReady	= 0;

	P0_7 = 1;
	delay(100);
	PowerDown_XTAL(0);
	
	TW88HWReset = 1;	delay(1);
}

//------------------------------------------------------------------
// void	InitTechwell(void) - Techwell Decoder initialize
//------------------------------------------------------------------
void	InitTechwell( void )
{

	#ifdef NO_INITIALIZE
	if( P0_3==0 ) {// No Initialize
		NoInitAccess =1;
		Printf("\r\n No-initialize Test going on with DIP SW4 ..: %d\n", (WORD)P0_3);
		return;
	}
	#endif

	LCDPowerOFF();
       InitCCFL(); // Hans
       ConfigPanel(); // Hans
       ConfigTCON(); // Hans   
	Puts("\r\n\nDetect ");
	
	switch( ReadTW88(0) ) {
		case 0x21:	Puts("TW8816");		break;
		case 0x49:	Puts("TW8817");		break;
		default:	Printf("Nothing --0x%02x\r\n", (WORD)ReadDecoder(0)); 
			while(1) {
				#ifdef SERIAL
				if( RS_ready() ) break;
				#endif

				Printf("Check again --0x%02x\r\n", (WORD)ReadDecoder(0));
				delay(99);
				if( ReadTW88(0)==0 ) continue;
				if( ReadTW88(0)==0xff ) continue;
				break;
			}

			delay(99);
			delay(99);
			Printf("Last Check --0x%02x\r\n", (WORD)ReadDecoder(0));
		break;
	}

	#ifdef ADD_ANALOGPANEL
	if(IsAnalogOn())
		Printf("%s \n", AddedAnalogPanelStr);
	else
	#endif	
		Printf("%s \n", PanelInfoStr);
	CheckSpecialMode();
	main_init();

}
//=============================================================================
//                            Power LED ON / OFF                                                   
//=============================================================================
void PowerLED(BYTE flag)
{
#define	GREEN_LED	P0_4
#define RED_LED		P0_5

	if( flag==ON ) {
		GREEN_LED = 0;		// ON GREEN
		RED_LED = 0;		// ON RED
		dPuts("\r\n(PowerLED)-ON");
	}
	else {
		GREEN_LED = 1;		// OFF FREEN
		RED_LED = 0;		// ON RED
		dPuts("\r\n(PowerLED)-OFF");
	}
}
#endif

//------------------------ common routines with interrupts --------------------

/*****************************************************************************/
/*      Ext Int 1 Interrupt                                                  */
/*****************************************************************************/
//INTERRUPT(2, ext1_int)
void	ext1_int(void) interrupt 2 using 1
{
	EX1 = 0;
}

//****************************************************************************/
//      Timer 0 Interrupt                                                  
//			If TL0 overflow,
//			 .Invoke this interrupt
//			 .TL0 <- TH0
//			TL0 is incremented every machine cycle
//			Every machine cycle is 12*Tosc(11.0592MHz)
//
//			Every machine cycle = 1.085us
//			Interrupt interval = 208us ( 1.085*(256-64(TH0)) )
//			When tm001==48, it's 0.01sec.  48*208us
//							
//****************************************************************************/

#ifndef INTERNAL_MCU
#define _ReadKey()		( ((~P4>>2)& 0x01) | (~P1 & 0xfc) )
#endif

//=============================================================================
//			Remocon
//=============================================================================

#ifdef REMO_RC5

void InitForRemo(void)
{
	WORD temp;

	#if defined CLOCK_11M

	#ifdef TECHWELL_REMOCON // DONGYANG
	temp = 0x10000 - 193;	// 209.62us = 1.085*193
	#else
	temp = 0x10000 - 204;	// 221.34us = 1.085*204
	#endif
	
	#elif defined CLOCK_22M

	#ifdef TECHWELL_REMOCON // DONGYANG
	temp = 0x10000 - 193*2;	// 209.62us = 1.085/2*193*2
	#else
	temp = 0x10000 - 204*2;	// 221.34us = 1.085/2*204*2
	#endif

	#elif defined CLOCK_27M		// intenal_mcu

	#ifdef TECHWELL_REMOCON // DONGYANG
	temp = 0x10000 - 20;	// 209.62us = 1/27 * 283 * 20 = 209.63uS
	T2HIGH = 1;			// 283 = 256 + 27
	T2LOW = 27;			// 
	#else
	temp = 0x10000 - 36;	// 221.34us = 1/27 * 166 * 36 = 221.33uS
	T2HIGH = 0;			// 
	T2LOW = 166;			// 
	#endif

	#endif

	RCAP2H = TH2 = temp>>8;
	RCAP2L = TL2 = (BYTE)(temp & 0xff);
	TR2    = 1;

	tm01 = 4;
	RemoPhase1 = 1;
	RemoSystemCode= RemoDataCode=0;
}

#elif defined REMO_NEC

void InitForRemo(void)
{
	WORD temp;

	#if defined CLOCK_11M
	temp = 0x10000 - 173;	// 187.71us = 1.085*173
	#elif defined CLOCK_22M
	temp = 0x10000 - 173*2;
	#elif defined CLOCK_27M	
	T2HIGH = 0;			// 
	T2LOW = 252;			// 
	temp = 0x10000 - 20;	// 186.667uS = 1 /27 * 252 * 20
	#endif

	RCAP2H = TH2 = temp>>8;
	RCAP2L = TL2 = (BYTE)(temp & 0xff);

	TR2 = 1;

	tm01 = 0;
	RemoStep  = 0;
	RemoPhase = 0;
	RemoHcnt  = 0;
	RemoLcnt  = 0;
}

#endif


///****************************************************************************
///*      Ext Int 0 Interrupt                                                
///****************************************************************************
//_interrupt(0) void remocon_int (void)
//INTERRUPT(0, remocon_int)
void	remocon_int(void) interrupt 0 using 1
{
	EX0 = 0;	// Enable Remocon (Enable Ext int0)
	InitForRemo();
}

//*****************************************************************************
//      Serial Interrupt                                                   
//*****************************************************************************
#ifdef SERIAL

//INTERRUPT(4, serial_int)
void serial_int(void) interrupt 4 using 1		// register bank 1
{
	if( RI ) {					//--- Receive interrupt ----
		RI = 0;
		RS_buf[RS_in++] = SBUF;
		if( RS_in>=BUF_MAX ) RS_in = 0;
	}

	if( TI ) {					//--- Transmit interrupt ----
		TI = 0;
		RS_Xbusy=0;
	}
}
//=============================================================================
//		Serial RX Check 												   
//=============================================================================
BYTE RS_ready(void)
{
	if( RS_in == RS_out ) return 0;
	else return 1;
}
//=============================================================================
//		Serial RX														   
//=============================================================================
BYTE RS_rx(void)
{
	BYTE	ret;
		
	ES = 0;
	ret = RS_buf[RS_out];
	RS_out++;
	if(RS_out >= BUF_MAX) 
		RS_out = 0;
	ES = 1;

	return ret;
}
//=============================================================================
//		Serial TX														   
//=============================================================================
void RS_tx(BYTE tx_buf)
{
	while(RS_Xbusy);
	SBUF = tx_buf;
	RS_Xbusy=1;
}

#endif	// SERIAL



//****************************************************************************/
//      Timer 2 Interrupt                                                  
//			If TH2 and TL2 are overflowed,
//			 .Invoke this interrupt
//			 .TH2 <- RCAP2H
//			 .TL2 <- RCAP2L
//			TL2 is incremented every machine cycle
//			Every machine cycle is 12*Tosc(11.0592MHz)
//
//			Every machine cycle = 1.085us
//			Interrupt interval  
//				1) REMO_RC5 
//					221.34us  ( 1.085*204 )		// (256-52) (0x10000-0xff34)
//
//					data length: 14bit (2sync bits, 1 control bit, 11 data bits) 24,889ms
//
//								+----+
//					1 is coded:      |    |
//									 +----+   
//								  T    T
//
//									 +----+
//					0 is coded: |    |
//					            +----+	  
//								  T    T					T = 889us
//
//					*) DongYang
//						209.62	( 1.085*193 )	// (256-63) (0x10000-0xff3f)
//-----------------------------------------------------------------------------
//				2) REMO_NEC
//					187.714us ( 1.085*173 )     // (256-83) (0x10000-0xff53)
//							
//****************************************************************************/
//INTERRUPT(5, timer2_int)
void timer2_int(void) interrupt 5 using 1			// using register block 3
{
	TF2 = 0;					// clear overflow

	tm01++;

	#ifdef REMO_RC5
	{
		BYTE	i;

		i = tm01 & 0x07;
		if( i>=1 && i<=2 )
			RemoPhase1 = P3_2;
		else if( i>=5 && i<=6 )
			RemoPhase2 = P3_2;
		else
			;
		if( i==0 ) {	//every 8 tm01
			if( RemoPhase1==RemoPhase2 ) {	// error
				ClearRemoTimer();			
				EnableRemoconInt();
				return;
			}
			if( tm01<=(8*8) ) {				// start control system
				RemoSystemCode <<=1;
				if( RemoPhase1==1 && RemoPhase2==0 )
					RemoSystemCode |=1;
			}
			else {							// data
				RemoDataCode <<=1;
				if( RemoPhase1==1 && RemoPhase2==0 )
					RemoDataCode |=1;
			}
		}
		if( tm01 > (8*14) ) {
			RemoDataReady++;	//LJY051502 RemoDataReady = 1;				// new key
			ClearRemoTimer();				
			//RemoOver = 0;
		}
	}

	#elif defined REMO_NEC
	
	{
		if( RemoDataReady ) return;

		switch( RemoStep ) {

		case 0:
			if( P3_2==0 ) {
				RemoLcnt++;
				if( RemoLcnt==0xff ) goto RemoError;
			}
			else {
				RemoHcnt = 0;
				RemoStep++;
			}
			break;

		case 1:
			if( P3_2==1 ) {
				RemoHcnt++;
				if( RemoHcnt==0xff ) goto RemoError;
			}
			else {
				if( RemoLcnt>=15*3 && RemoLcnt<=17*3 ) {
					
					if( RemoHcnt>=3*3 && RemoHcnt<=5*3 ) {
						RemoStep = 3;
						RemoDataReady = 2;
						break;
					}
					else if( RemoHcnt>=7*3 && RemoHcnt<=9*3 ) {
						RemoStep++;
						RemoPhase = 0;
						RemoLcnt = 0;
						RemoNum  = 0;
						RemoBit  = 0;
						break;
					}
				}
				else goto RemoError;
			}
			break;

		case 2:
			if( RemoPhase==0 ) {
				if( P3_2==0 )					// Phase=0  Input=0
					RemoLcnt++;
				else {							// Phase=0  Input=1
					RemoPhase = 1;
					RemoHcnt = 0;
				}
			}
			else {								
				if( P3_2==1 )					// Phase=1  Input=1
					RemoHcnt++;
				else {							// Phase=1  Input=0
					RemoPhase = 0;
					if( RemoLcnt>=1 && RemoLcnt<=5 ) {
						if( RemoHcnt<=2*3 ) 			// bit 0
							RemoData[RemoNum] <<= 1;
						else if( RemoHcnt<=4*3 ) {		// bit 1
							RemoData[RemoNum] <<= 1;
							RemoData[RemoNum]++;
						}
						else goto RemoError;

						if( ++RemoBit>=8 ) {
							RemoBit = 0;
							if( ++RemoNum>=4 ) {
								RemoDataReady = 1;
								RemoStep++;
							}
						}
						RemoLcnt = 0;

					}
					else goto RemoError;
				}
			}
			break;

		case 3:
			break;
		
		}
		return;

RemoError:
		ClearRemoTimer();				//TimerFor208us();
		EnableRemoconInt();
	}

	#endif	// REMO_NEC
}


void delay(BYTE cnt)
{
	WORD ttic01;

	ttic01 =  ( tic01 + cnt ) % 100;
	do {
		;
	} while( tic01 != ttic01 );
}


//=============================================================================
//		Time
//=============================================================================
#define _24H_SECS			86400L			// 24*60*60
WORD GetTime_ms(void)
{
	WORD tms;

	tms = tic01;
	tms += ( SystemClock % 60 ) * 100;
	return tms;	// in ms
}
BYTE GetTime_H(void)
{
	return ( SystemClock / 60 / 60 ) % 24 ;
}

BYTE GetTime_M(void)
{
	return ( SystemClock / 60  ) % 60 ;
}

BYTE GetSleepTimer(void)
{
	WORD val;

	val = SleepTimer;
	if( val )	{	// already set, display rest of time
		val = ( SleepTime >> 8 ) * 60 + ( SleepTime & 0xff );
		val -= ( GetTime_H() * 60 + GetTime_M() );
	}
	return (BYTE)val;
}

void SetSleepTimer(BYTE stime)
{
	SleepTimer = stime;
	if( SleepTimer==0 )
		SleepTime = 0xffff;
	else {
		SleepTime = GetTime_H() + ( GetTime_M() + SleepTimer ) / 60;
		SleepTime = ( SleepTime << 8 ) | ( ( GetTime_M() + SleepTimer ) % 60 );
	}

	#ifdef DEBUG_TIME
	dPrintf("\r\n++(SetSleepTimer) SleepTime:0x%x__", (WORD)SleepTime);
	#endif
}

BYTE OKSleepTime(void)
{
	if( GetTime_H() == ( SleepTime >>8 ) && 
		GetTime_M() == ( SleepTime & 0xff ) )	{
		SleepTimer=0;
		SleepTime = 0xffff;
		return 1;
	}
	return 0;
}

WORD DiffTime_ms( WORD stime, WORD etime )
{
	//#ifdef DEBUG
	//dPrintf("\r\n(DiffTime) stime:%d, etime:%d", (WORD)stime, (WORD)etime );
	//#endif
	if( etime < stime ) {			// resetted
		return etime + (6000 - stime);
	}
	else {
		return etime - stime;
	}
}

// cCount X 0.01 sec  delay 
void SetDelayCount(BYTE cCount)
{
	cDelayCounter = cCount;
}

BYTE GetDelayCount(void)
{
	return cDelayCounter;
}

// cCount X 0.01 sec  delay 
// Don't call this function between "ssMeasureSetup" state and "ssModeDetect" state.
void WaitDelay(BYTE cWaitCount)
{
	cDelayCounter = cWaitCount;
	do {
		;
	} while(cDelayCounter);
}

⌨️ 快捷键说明

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