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

📄 main.c

📁 此程序为twell8806驱动程序
💻 C
📖 第 1 页 / 共 5 页
字号:
				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
}
/*
#ifdef SUPPORT_TV
BYTE OKWakeupTime(void)
{
	if( GetTime_H() == ( WakeupTime >>8 ) && 
		GetTime_M() == ( WakeupTime & 0xff ) )	
		return 1;
	return 0;
}
#endif	//SUPPORT_TV
*/
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;
	}
}

#ifdef SUPPORT_CCD_VCHIP
void SetLastBlockedTime(void)
{
	LastBlockedTime = SystemClock;
}

BYTE EnoughBlockedTime(void)
{
	if( LastBlockedTime != 0xffffffff && ( SystemClock - LastBlockedTime ) >=5 )	
		return TRUE;
	return FALSE;
}

#ifdef SUPPORT_TW88_CC_DECODER
void SetLastCCTime(void)
{
	if( LastCCTime != SystemClock ) {
		LastCCTime = SystemClock;
		#ifdef DEBUG_CCEDS
//		dPrintf("(LastCCTime:%ld)", LastCCTime );
		#endif
	}
}

BYTE WaitEnoughForCC(void)
{
//	#ifdef DEBUG_CCEDS
//	dPrintf("\r\n(WaitEnoughForCC) LastCCTime:%ld, SystemClock:%ld", LastCCTime, SystemClock );
//	#endif

	if( LastCCTime != 0xffffffff && ( SystemClock - LastCCTime ) >=5 )	{		// 5 sec
		#ifdef DEBUG_CCEDS
		dPrintf("((WaitEngoughForCC!! SystemClock:%ld))", SystemClock );
		#endif
		return TRUE;
	}
	return FALSE;
}
#endif

#endif // SUPPORT_CCD_VCHIP

#if defined SUPPORT_TV
BYTE WantToStopTVScan(void)
{
	BYTE AutoKey=0, ret=0, _RemoDataCode=0;

	ret = GetKey(1); 

	if( ret == MENUKEY ) {
		//Printf("\r\n(WantToStopTVScan) Pushed Menu Key!!");
		return 1;
	}

	if( !ret )
		ret = IsRemoDataReady(&_RemoDataCode, &AutoKey);

	if( _RemoDataCode==REMO_MENU  )	ret = 1;
	else	ret = 0;

	#if defined DEBUG_KEYREMO || defined DEBUG_TV
	dPrintf("\r\n(WantToStopTVScan) ret:0x%x, RemoDataCode:0x%x", (WORD)ret, (WORD)_RemoDataCode);
	#endif

	return ret;
}
#endif		//SUPPORT_TV
//*****************************************************************************
//      Serial Interrupt                                                   
//*****************************************************************************
#ifdef SERIAL

INTERRUPT(4, serial_int)
{
	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(1) 
	{
		if(!RS_Xbusy) 
		{
			SBUF = tx_buf;
			RS_Xbusy=1;
			break;
		}
	}
}
//=============================================================================
//		Serial Output string											   
//=============================================================================
void NewLine(void)
{
	Puts("\r\n");								    
}

void PutsP(PDATA_P BYTE *ptr)
{
	BYTE ch;
	while(*ptr!='\0') {
		ch = *ptr++;
		RS_tx(ch);
	}
}

#else

#define	NewLine		;//
#define PutsP		;//

#endif	// SERIAL
//=============================================================================
//                            Initialize CPU                                                   
//=============================================================================
void InitCPU(void)
{
	CHPENR = 0x87;		// Enable AUX RAM in Winbond(W78E516B)
	CHPENR = 0x59;		//
	CHPCON = 0x10;		//
	CHPENR = 0x00;		// Write Disable

	SystemClock=0;			//00:00
	LastBlockedTime=0xffffffff;		//00:00	//ljy010904...CC_FIX_CLEAR_ON_TIME..oops! previous vchip clear error 
	#ifdef SUPPORT_TW88_CC_DECODER
	LastCCTime=0xffffffff;			//ljy010904...CC_FIX_CLEAR_ON_TIME
	#endif
	//WakeupTime=0xffff;
	//WakeupPR = 0;
	OffTime=0xffff;
	SleepTimer=0;
	SleepTime=0xffff;

	/*----- Initialize interrupt -------------*/

	TH1 = 0xff; 		//    SMOD = 0      SMOD =1						
						// 0ffh :57600 bps				
						// 0fdh : 9600 bps	0fdh :19200 bps				
						// 0fah : 4800 bps								
						// 0f4h : 2400 bps								
						// 0e8h : 1200 bps								

	SCON = 0x50;		// 0100 0000 mode 1 - 8 bit UART				
						// Enable serial reception						
    TMOD = 0x22;		// 0010 0010 timer 0 - 8 bit auto reload		
						// timer 1 - baud rate generator				
    TCON = 0x55;		// 0101 0001 timer 0,1 run						
						// int 0,  edge triggered						
						// int 1,  edge triggered						
						// TF1 TR1 TF0 TR0	EI1 IT1 EI0 IT0				
	TH0 = TL0 = 64;		// 64=4608 Hz at 11.0592MHz

	PCON = 0x80;		// 0000 0000 SMOD(double baud rate bit) = 1		
	IP	 = 0x02;		// 0000 0000 interrupt priority					
						// -  - PT2 PS PT1 PX1 PT0 PX0	 		         

	#ifdef SERIAL
	IE	 = 0x92;		// 1001 0010 interrupt enable:Serial,TM0		
  						// EA - ET2 ES ET1 EX1 ET0 EX0					

	TI	 = 1;			// LJY000724 // For Starting Serial TX 
	ES   = 1;			// LJY000724
	#else
	IE   = 0x82;
	#endif // SERIAL

	//------------ Timer 2 for Remocon --------------------------------
	T2CON  = 0x00;				// Timer2 Clear
	TR2	   = 0;
	ET2    = 1;
	//-----------------------------------------------------------------
	
	SEL_DVI=  1;		// disable Digital VGA

	ResetKey();

	#ifdef SERIAL
	RS_in = RS_out = 0;
	commdptr = bptr	= 0;
	#endif	// SERIAL
	
	DebugLevel		= 0;
	RemoDataReady	= 0;
	I2CAddressDeb   = DECODERADDRESS;	//TW88I2CAddress;

}

#ifdef SERIAL
//=============================================================================
//		I2C Edit Read		                                               
//=============================================================================
void MonWriteI2C(BYTE addr, BYTE index, BYTE val) 
{
	Printf("Write %02xh to [Adrs(%02xh)Index(%02xh)] ", (WORD)val, (WORD)addr, (WORD)index);
	WriteI2C(addr, index, val);
}

void MonWriteI2Cn_(BYTE addr, BYTE *val, BYTE cnt) 
{
	BYTE i;

	Printf("Write ");
	for(i=0; i<cnt; i++) {
		Printf("%02xh ", (WORD)val[i]);
	}
	Printf("to [Adrs(%02xh)", (WORD)addr);
	if( !WriteI2Cn_(addr, val, cnt) )		//LJY001127
		ePuts("---> Fail!! ");	
}
//=============================================================================
//		I2C Edit Read		                                               
//=============================================================================
BYTE MonReadI2C(BYTE addr, BYTE index)
{
	BYTE val;

	val = ReadI2C(addr, index);
	Printf("Read [Adrs:%02xh,%02xh] %02xh", (WORD)addr, (WORD)index, (WORD)val);

	return val;
}

void MonReadI2Cmn(BYTE addr, BYTE *wrdata, BYTE argcnt)
{
	BYTE i, rcnt;

	Printf("Read  [Adrs:%02xh ", (WORD)addr);
	for(i=0; i<argcnt-1; i++)
		Printf(" Index:%02xh ", (WORD)wrdata[i] );
	Printf("] ");

	rcnt = wrdata[argcnt-1];
	ReadI2Cmn(addr, argcnt-1, rcnt, wrdata);

	for(i=0; i<rcnt; i++)
		Printf("%02xh ", (WORD)wrdata[i]);
}
//=============================================================================
//		Convert ASCII to Binery                                             
//=============================================================================
BYTE Asc1Bin(BYTE asc)
{
	if(asc>='0' && asc <='9') return (asc - '0');
	if(asc>='a' && asc <='f') return (asc - 'a' + 0x0a);
	if(asc>='A' && asc <='F') return (asc - 'A' + 0x0a);
}

BYTE Asc2Bin(PDATA_P BYTE *s)
{
	BYTE bin;

	bin = 0;
	while(*s != '\0' && *s !=' ') {
		bin = bin<<4;
		bin = bin + Asc1Bin(*s);
		s++;
	}
	return (bin);
}
#endif // SERIAL


///////////////////////////////////////////////////////////////////////////////

//=============================================================================
//		Prompt				                                               
//=============================================================================
#include <stdio.h>
void Prompt(void)
{
	Printf("\r\nI2C[%02x]>", (WORD)I2CAddressDeb);
}

#define FPHS_P_T		5

#ifdef SERIAL
void DebugKeyIn(BYTE ikey)
{
	BYTE i; 
	static bit comment=0;

	//----- if comment, echo back and ignore -----
	if( comment ) 
	{
		if( ikey=='\r' ) 
			comment = 0;
		else 
		{
			RS_tx(ikey);
			return;
		}
	}
	else if( ikey==';' ) 
	{
		comment = 1;
		RS_tx(ikey);
		return;
	}

	//----- command ------------------------------
	if ((ikey == '\r')||(ikey == '/'))
	 {

		comment = 0;

		if (ikey == '/')
		 {      // Repeat 
			PutsP(commdbuf);
			commdptr = bptr;
			commdbuf[0]=arg[0];
		}
		commdbuf[commdptr] = '\0';
		bptr = commdptr;
		commdptr = 0; 
		argn = 0;
		eol	= 0;
		cerror = 0;
							// Ex) I2C[xx]>C 00 0 00 								
		while(commdbuf[commdptr]==' ') commdptr++;

		if (commdbuf[commdptr]=='\0') eol = 1;

		arg[argn++] = commdbuf[commdptr++];

		while(!cerror && !eol) 
		{
			if (commdbuf[commdptr]!=' '&& commdbuf[commdptr] !='\0')
			 {
				cerror = 1;break;
			}
			while(commdbuf[commdptr]==' ') commdptr++;
			if (commdbuf[commdptr] =='\0')
			{
				eol = 1;break;
			}
			arg[argn++] = Asc2Bin(&commdbuf[commdptr]);
			while(commdbuf[commdptr]!=' ' && commdbuf[commdptr]!='\0' ) 
			{
				commdptr++;
			}
		}

		if (cerror) 
		{
			Puts(" <- Error!!");
			Prompt();
			commdptr = 0;
			commdbuf[0]='\0';
		}
		else 
		{
			//--------------------------------------------------
			// Check Indirect command
			switch(arg[0]) {
			case 'i':	
			case 'I':
			case 'o':
			case 'O':
					indirect=1;	break;
			case ',':
			case '>':
			case '<':
			case '.':			break;
			default: indirect=0;	break;
			}

			//--------------------------------------------------	

⌨️ 快捷键说明

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