main.c

来自「CS8955控制TV软件。用MCU做模拟电视的控制。」· C语言 代码 · 共 819 行 · 第 1/2 页

C
819
字号
#else
// Init sys pwr


void vSysModeSwitch(BYTE mode)
{
	switch (mode)
	{
		case DVD_MODE:
    			mTVDisable();
		 	break;
		case TV_MODE:
			vInitTV();
			break;
	}
}
#endif
#ifndef MARTIN_MCU_NO_IR   //martin 08May08
/////////////////// IR interrupt service routines////////////////////
void ISR_EXINT0(void) interrupt 0 
{
    BYTE bKey;

    EA = 0;

    // Scan the remote control
    bKey = bRemoteDetect();

    // key is detected
    if (bKey != IR_NONE)
    {
        if ((bKey == IR_LONGPUSH) && (_bIRLongPush == IR_NONE)
		&& (_bIRKey0!=IR_LONGPUSH) )
    	{
          	_bIRLongPush = _bIRKey0;
    	}

    	if (bKey != IR_LONGPUSH)
    	{
      		_bIRLongPush = IR_NONE;
        	_bIRKey0 = bKey;
     	       _fgIRKeyValid = TRUE;
    	}
       // long push
	else	 if (_bIRLongPush!=IR_NONE)
	{
		_bIRKey0 = Key2IR(TRUE,_bIRLongPush);
      		_bIRLongPush = IR_NONE;
     	       _fgIRKeyValid = TRUE;
	  }
    }	

    EA = 1;	
}
#endif
//System Clock  20ms
void ISR_Timer0(void) interrupt 1  // 20ms task 
{
     EA = 0;
     TH0=0xEC;   //timer 0 high byte
     TL0=0x78;    //timer 0 low byte
	
    if (!(--wTimer0Count))
    {
       bTimer20ms = 1;
       wTimer0Count = 5;
    }

    if (EEP_Wait>0)
        --EEP_Wait;

     TF0 = 0;
     EA = 1;
}
BYTE uart_data;  //04Sep08 test

#ifdef ENABLE_UART
void ISR_UART(void) interrupt 4 // Uart
{
/*
   EA = 0;
   if(RI)
   {
	if (SBUF!=0x0d && SBUF!=0x0a)
	{
		UartRxBuf[UartRxIndex++] = SBUF;
      		if (UartRxIndex>=UART_BUF_SIZE)
			UartRxIndex = 0;
	}		
    	RI = 0;
   }
   EA = 1;
*/


	if (RI == 1) 
	{				                 /* if reception occur */
	  RI = 0; 			           /* clear reception flag for next reception */
	  uart_data = SBUF;          /* Read receive data */
	  SBUF = uart_data; 	        /* Send back same data on uart*/
	  while(TI==0);
	  TI=1;
	
	}	
  		                        /* clear emission flag for next emission*/	
   
}
#endif

    #ifndef MARTIN_DVD_COMM_NOT_SUPPORT_INT	

// DVD communication
void ISR_INT2(void) interrupt 2
{
#ifndef MARTIN_DVD_COMM_NOT_SUPPORT_INT	
    BYTE i, count;
#endif

#ifndef MARTIN_SYSTEM_ONLY_TVMODE	
    EA = 0;
    if (SysMode!=PWR_DOWN_MODE)  //needn't judge  mode
#endif		
    {

	while (mReadDvdClk())
	{
	           if (mReadDvdCs())
	           {
                      goto _EINT2_EXIT;
	           }	
	}
	for (i=0;i<(COMDVD_BYTE);i++)
	{
	    DvdRxIndex = i;
           DvdRxBuf[DvdRxIndex] = 0;
      	    for (count=0x80;count>0;count>>=1)
           {
          	// data out      
         	if (DataOutValid)
         	{
            	    if ( DataOut[DvdRxIndex]&count )
	           {
  	           	mSetDvdIr();
	           }   
	           else
	           {
  	               mClrDvdIr();
	           }		   
              }
	       else
	       {
	     		if (DvdRxIndex<=1)
	     		{
  	           		mSetDvdIr();
	     		}	   
		    	else	
			{ 
  	           		mClrDvdIr();
			}	   
	   	}
	       while (!mReadDvdClk())
	       {
	           if (mReadDvdCs())
	           {
                      goto _EINT2_EXIT;
	           }	
	       }
	   	// data in
	   	DvdRxBuf[DvdRxIndex] |= (mReadDvdDat() ? count : 0);
	       while (mReadDvdClk())
	       {
	           if (mReadDvdCs())
	           {
                      goto _EINT2_EXIT;
	           }	
	       }
	    }	   
      }   
      mClrDvdIr();
	if (DvdChecksumOk())
	{
	       for (count=1;count<DVD_STATUS_BYTE;count++)
	       {
	           ShadowDvdInfo[count-1] = DvdRxBuf[count];
	       } 
	#ifndef MARTIN_MCU_AND_DVD_PROTOCOL   //martin 14May08
	       for (count=0;count<CAR_INFO_BYTE;count++)
	       {
	           if ((ShadowCarInfo[count]&0xf0)==0)
  	               ShadowCarInfo[count] = DvdRxBuf[DVD_STATUS_BYTE+count];
	       }
	#endif	   
	}
_EINT2_EXIT:    	
    	if (DataOutValid>0)  
    	{
	   	--DataOutValid;
      	}	

		
    }
    EA = 1;
	 
}
 #endif


#ifdef  MARTIN_DVD_COMM_NOT_SUPPORT_INT
void  McuDvdComm(void) large
{
    BYTE i, count;
	
   // EA = 0;
 if (!mReadDvdCs())
    {
  //    fgDVDTVCMD=1;//02Aug08
      mClrDvdIr();
     TVRaCurrDataOut();
 //    bDataUpdateEn=1;    
	while (mReadDvdClk())
	{
	           if (mReadDvdCs())
	           {
	      //     fgDVDTVCMD=0; //02Aug08
	           mSetDvdIr();//02Aug08
                      goto _EINT2_EXIT;
	           }	
	}
	bTempIrKey=0xff;
	for (i=0;i<(COMDVD_BYTE);i++)
	{
	    DvdRxIndex = i;
           DvdRxBuf[DvdRxIndex] = 0;
      	    for (count=0x80;count>0;count>>=1)
           {
             if ( DataOut[DvdRxIndex]&count )     // data Out
	           {
  	           	mSetDvdIr();
	           }   
	           else
	           {
  	               mClrDvdIr();
	           }		   
             		
	       while (!mReadDvdClk())
	       {
	           if (mReadDvdCs())
	           {
	     //      fgDVDTVCMD=0; //02Aug08
	           mSetDvdIr();//02Aug08
                      goto _EINT2_EXIT;
	           }	
	       }
	   	
	   	DvdRxBuf[DvdRxIndex] |= (mReadDvdDat() ? count : 0);  // data in
            
          
           while (mReadDvdClk())
	       {
	           if (mReadDvdCs())
	           {
	      //     fgDVDTVCMD=0; //02Aug08
	           mSetDvdIr();//02Aug08
                      goto _EINT2_EXIT;
	           }	
	       }
	    }	 
    
         /*  //27Aug08 test
         if(DvdChecksumOk())
         {
          
         for (count=1;count<COMDVD_BYTE;count++)
         	       {
         	           ShadowDvdInfo[count-1] = DvdRxBuf[count];
         		//	   if(DvdRxBuf[1] == 0x81)
         		//	   _bIRKey0=IR_SYSTEM;
         	       } 
         }
         else
         {
         ShadowDvdInfo[0]=0xff;
         }
         */
    } 

	
      mClrDvdIr();
	 
         
_EINT2_EXIT:   
 	mSetDvdIr();//02Aug08
 //	 fgChangeTV=0;//02Aug08
   //   fgDVDTVCMD=0; //02Aug08
  //   bDataUpdateEn=0;
    	if (DataOutValid>0)  
    	{
	   	--DataOutValid;
      	}	

       if(DvdChecksumOk())     //27Aug08
         {        
           for (count=1;count<COMDVD_BYTE;count++)
       	   {
       	      ShadowDvdInfo[count-1] = DvdRxBuf[count];
                  } 
	     #ifdef OPEN_PRINTF
             DRS232LogS("DVD Comm OK.\n"); 	
          #endif	   
         }
      else
          {
             ShadowDvdInfo[0]=0xff;
	    #ifdef OPEN_PRINTF
            DRS232LogS("DVD Comm Fail.\n"); 	
           #endif		 
           }		
    }
 else  //080808
 	{
           mSetDvdIr(); //080808
 	}
 	
  //  EA = 1;
}

#endif
//*****************************************************************************************
//                                    Main Entrance
//*****************************************************************************************
void main(void)
{	
  
       CS8955_SEL = 0x80;   // ALE disable
	EA = 0;         //enable all interrupt	
    	vInitCPU();  //27Aug08  (ON);   

       vInitSys();   //martin 12May08   

   
  	while(1)
  	{  

	/////*************   communication for dvd	***************************//////	  

            #ifdef MARTIN_DVD_COMM_NOT_SUPPORT_INT
	//	 if((!fgDVDTVCMD)/*&&(!fgChangeTV)*/)	//02Aug08     
	           McuDvdComm(); 
		  #endif
      ///****************************************************************//////
		  
    ////************************   TV search state	************************////	  
    		
    		if (_bSearchState>0)
    		{
 	     	   vTVSearch(_fgSearchDir);		
    		}		
     ////*****************************************************************////

    /////************************  tasks  **********************************////
     		
		if (bTimer20ms)
		{ 
		      TaskProc();
           		if (_bRemoteTimer>0)
              		--_bRemoteTimer;
  	    		bTimer20ms = 0;	

                      #ifdef MARTIN_TEST_CHANNNEL_NUMBER_SHOW
                           vFreAFCAdjLoop();
			#else		  
			    if(fgAFCADJCnt !=  0x00)
			      {
				  fgAFCADJCnt--;
                               vFreAFCAdj(); //02Aug08
			       }
			#endif
			
              #ifdef MARTIN_TUNER_XF6A_PAL_M_NOT_SYNC
                 if((fgTunerType == TV_TYPE_XF6A) &&(_bSearchState == S_STATE_IDLE ))
                 	{
                       vPalMBugAdj();  //17Sep08
                 	}
		#endif
		
     	           #if 0 //#ifdef OPEN_PRINTF			
     	             if(_bSearchState == S_STATE_IDLE)	
     		         {
       		     if(bReadAdcCnt < 0xf0)
       			{
       			bReadAdcCnt++;
       			}
       		
       		    if(bReadAdcCnt == 0xf0)
       		      {
       			bReadAdcCnt=0x00;
       			   bTvAdcValue=bTV_ADC_Read();
       			    Delay1ms(30);
       			  
       			  DRS232LogS("TV ADC VAULE: .\n"); 	
       	                DRS232LogB(bTvAdcValue,bTvAdcValue,bTvAdcValue,0xff);  
                  		 }
     		         }		
     		      #endif
	  }	
       ///****************************************************************////			
     }
}

⌨️ 快捷键说明

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