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

📄 main_func.c

📁 2.4G无线音箱的接收程序,采用ATMEGA8单片机和STS公司的无线模块完成
💻 C
📖 第 1 页 / 共 2 页
字号:
		/*******************/
		/*** Free Button ***/
		/*******************/
    	if (Use_MU_CU_Swap == 1) 
    		{
			Handle_MU_CU_Swap_MainLoop();
    		}
		else
			{
				if (Use_ModuleMode == MU)
				{
					Handle_ABCD_Flip_MainLoop(); /* Flip RX Channels ABCD on Streams WXYZ */
				}
			}
	
	if (Use_NackReport)
	{
		/**********************/
		/*** NACK Procedure ***/
		/**********************/
		Handle_Auto_NAMG_MainLoop();
		Handle_Auto_NAMG_RXMsg_TimeOut();
	}
	
	if (Use_Own_WLAN_Detection)
	{
		/************************************/
		/*** Own WLAN Detection Procedure ***/
		/************************************/
		Handle_Own_WLAN_Detection_MainLoop();
	}
	
	/**************************************/
	/*** Handle Incoming Data Message's ***/
	/**************************************/
	if (Handle_Received_Packet() == 1) /* parse message */
	{
		#ifdef DEBUG
			putstring("RXmsg: ");
			puthex(RX_Data_recv_array[0]);
			putchar(' ');
			puthex(RX_Data_recv_array[1]);
			putchar(' ');
			puthex(RX_Data_recv_array[2]);
			putchar('\r');
		#endif
				
     	
       		Handle_Volume_RXMsg();

			Handle_Connect_RXMsg();
			
   			Handle_MU_CU_Swap_RXMsg();  
			
			if(Use_Auto_Config)
			{
				Handle_MU_Change_Config_RXMsg();			
			}
		if (Use_NackReport)
		{
    			Handle_Auto_NAMG_RXMsg();
   		}
		//**********检测有没有音频信号**********************
              if (Use_ModuleMode == MU)
		{
			/*###### MU ######*/	

          		//WM100 Modification to the data received
          		if( RX_Data_recv_array[0] == 0xa5)  //无音频信息
			{
				//SYNC_LED_OFF;
                                Mute_flag = 1 ;
                                NoAudio_flag = 1 ;  //置无Audio 信息标记                            
                                // mute   在这里加上 mute 操作
                                key_mute= 1 ;		//Allan Add//
          		}	
                     else if(RX_Data_recv_array[0] == 0xaa) //有音频信息
                     {
                              //恢复声音
                              Mute_flag = 0 ;
                              NoAudio_flag = 0 ;  //置有Audio 信息标记
							  key_mute= 0 ; 	  //Allan Add//
                              //在这里加上关闭mute操作
                      }  
          	}
		//*********** end of 检测有没有音频信号***************
		
	} /* Handle_Received_Packet */
        //**********检测有没有RF同步信号**********************
        if(InSync_Detected == 0)
        {
            if(NoSync_cnt == 0)
            {
                NoSync_cnt = 200 ;  
                Mute_flag = 1 ;   //置已经 mute标记
                 // mute	在这里加上 mute 操作
				 key_mute= 1 ;		 //Allan Add//
            }            
        }  
        else
        {
            if(NoAudio_flag ==0)  //如果是有Auido, 则要关闭mute
            {   
                if(Mute_flag == 1)  //如果已经mute了,要关闭 mute, 这里防止频繁启用关闭 mute操作
                {   
                    Mute_flag = 0 ;
                    //在这里加上关闭mute操作
					key_mute= 0 ;		//Allan Add//
                }
            }
        }  
        //*********** end of 检测有没有RF同步信号***************
    	if((Use_Audio_Detection == 1) &&(Sleep_Timer==0))
    	{
        	Handle_Wake_up_Sleep_Interrupt();
        	Sleep_Timer=SLEEP_TIMER_RELOAD_VALUE;
    	}
        
	#ifdef CODEC_CS4341
		if(key_mute)	//Mute DAC////mute key active  //PB1=0; mute
			{
				pd5_mute_ctrl(0);
				pb0_mute_delay_count1=0;

				if(pb0_mute_delay_count0<100)
					{
						pb0_mute_delay_count0++;
					}
					else
					{
						PORTB = PORTB & 0xFE;	//PB0=0//
					}
			}
		else			//Open DAC////no mute key active   //PB1=1; no mute
			{
				pd5_mute_ctrl(1);
				pb0_mute_delay_count0=0;
				if(pb0_mute_delay_count1<100)
					{
						pb0_mute_delay_count1++;
					}
					else
					{
						if(PB0_Delay_High_Count==300)PORTB=PORTB | 0x01;			//PB0=0//
					}
			}
	#endif

	return;
} /* END Check_Application_Events */


/******************************************************************************
*
* Function Name :   Interrupt_every_10millisec
*
* Purpose       :   Timing 10mSec and counters, led blink sequence
* 					This procedure should be called every 10 millsec in a
*					timer interrupt, it is used for timeouts(Data) and
*					flashing leds
*
* Arguments     :   none
*
* Return value  :   none
*
******************************************************************************/
void Interrupt_every_10millisec(void)
{
	if (TX_Timeout != 0xFF) TX_Timeout++;
	RND_Value++;
	Flip_Counter++;
   Quin_Counter++;
	Error_Prescaler++;
	Sec_Prescaler++;
	MS100_Prescaler++;		
    NAMG_200++;
	AutoConfig_InSync_Leadtime++;		
	AutoConfig_NoSync_Delay_Cntr++;				

	if (
		(Sec_Prescaler == 20) ||
		(Sec_Prescaler == 40) ||
		(Sec_Prescaler == 60) ||
		(Sec_Prescaler == 80)
		)
	{
		NACK_Sample_Time = 1;


	}
    if (Flip_Counter == 20){
      Event_FLIP = 1;
      Flip_Counter = 0;
    }
    //WM100 Display Counter
    if (Quin_Counter== 100){
        //DispMessageVol(1,Volume_Memory);
        //DispQuin();
 //       DispQuinData = 1;
        Quin_Counter = 0;
    }
    if(NAMG_200 == 10)
    {

       NAMG_200 = 0;
	   Handle_Auto_NAMG_Func_Timer();

    }


	if (MS100_Prescaler == 10)
	{
	
		MS100_Prescaler = 0;
        if (RFMR_Cnt != 0xFF) RFMR_Cnt++;
	}
	if (Sec_Prescaler == 100)
	{

		Sec_Event = 1;
		AutoConfig_PDDC_Disable_Cntr++;	
		Sec_Prescaler = 0;
	}
        if(Sleep_Timer!=0)
            Sleep_Timer--;
	
	if (Data_Led_Counter != 0)
	{
		Data_Led_Counter--;
		if (Data_Led_Counter == 0) DATA_LED_OFF;
	}

	if (Sync_Led_Status == LED_OFF)
	{
		SYNC_LED_OFF;					/* SYNC_LED_OFF; */
	}
	else
	if (Sync_Led_Status == LED_ON)
	{
		SYNC_LED_ON;					/* SYNC_LED_ON; */
	}
	else
	if (Sync_Led_Status == LED_CONNECTING)
	{
		if (Sec_Prescaler & 0x08) {SET_RFLEDS(7);}
		else 					  {SET_RFLEDS(0);}
	}
	else
	if (Sync_Led_Status == LED_INIT_ERROR)
	{
		if (
				( ((Error_Prescaler >> 4) & 0x0F) == 1) ||
				(
					(((Error_Prescaler >> 4) & 0x0F) == 3) &&
					(Error_Code > 1)
				) ||
				(
					(((Error_Prescaler >> 4) & 0x0F) == 5) &&
					(Error_Code > 2)
				)
		   ) {SET_RFLEDS(7);}
		else {SET_RFLEDS(0);}
	}
	else
	if (Sync_Led_Status == LED_SYNC_STATUS)
	{
		if (InSync_Detected)
                {                    
                      SYNC_LED_ON;                    
                }
		else
                {SYNC_LED_OFF;}
	}
#ifdef PCB_PNP80_UNIVERSAL_TRX
    else
    /* LED flashes to indicate low battery level */
	if (Sync_Led_Status == LED_LOW_BATT)
	{
		if (Sec_Prescaler & 0x20) {SYNC_LED_ON;}
		else {SYNC_LED_OFF;}
	}
#endif /*PCB_PNP80_UNIVERSAL_TRX*/
        
     if(NoSync_cnt !=0) //--- 没有连接计时器减1
     {
        NoSync_cnt-- ;
     }
} /* END Interrupt_every_10millisec */


/******************************************************************************
*
* Function Name :   Read_RFC
*
* Purpose       :   Read RFC Register
*
* Arguments     :   none
*
* Return value  :   Frequency
*
******************************************************************************/
unsigned char Read_RFC(void)
{
	unsigned char Frequency = I2C_Read_Byte(RFC_ADDR) & 0x03;

	return (Frequency);
}


/******************************************************************************
*
* Function Name :   Update_LED
*
* Purpose       :   Update leds
*
* Arguments     :   Ref_Freq
*
* Return value  :   none
*
******************************************************************************/
void Update_LED(unsigned char Ref_Freq)
{
#ifndef PCB_PNP80_UNIVERSAL_TRX
    if (Ref_Freq == 0) { SET_RFLEDS(1); }
	else
	if (Ref_Freq == 1) { SET_RFLEDS(2); }
	else
	if (Ref_Freq == 2) { SET_RFLEDS(4); }
	else
	if (Ref_Freq == 3) { SET_RFLEDS(4); }
	else
	if (Ref_Freq == 4) { SET_RFLEDS(1); }
	else               { SET_RFLEDS(0); }
#endif
}




⌨️ 快捷键说明

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