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

📄 tea5757.c

📁 收音芯片TEA5757驱动!我不太懂
💻 C
📖 第 1 页 / 共 4 页
字号:
              stop_RDS_display_timeout=3;
              if (!search_stop_flag && !auto_search_flag)
              {
                     vfd_osd_timeout=0;
		       tuner_current_freq_disp();
		       #ifdef PHILIPS_GUI
		       if (!search_ante_flag && absolute_search_flag)
		       {
			       amp_vfd_backup();
			       VFD_msg(VFDMSG_prog_end);
		       }
		       #endif
		       absolute_search_flag=0;      
              }
              if (search_stop_flag)
              {
                    if(absolute_search_flag)
                    {
                          absolute_search_flag=0;
                          station_counter = 1 ;			     
        		     read_freq_from_eeprom(station_counter);                                            
                          hand_tuner();    
                          write_current_freq();		  
	                   tuner_current_freq_disp();
       	            demute_proc();	
       	            #ifdef M62446
       	            M62446_demute();
       	            #endif
                    }
                    else if (auto_search_flag)
                    {        
	                   check_frequency();
                          hand_tuner();    	  
	                   tuner_current_freq_disp();
       	            demute_proc();
       	            #ifdef M62446
       	            M62446_demute();
       	            #endif       	            
                    }                    	
                    tdm_adc_turn_off();
                    tdm_adc_turn_on();
                    auto_search_flag=0;
                    search_stop_flag=0; 
              }
	} 
}

/************************************************************************
停台检测:
            检测收音机是否收到台
*************************************************************************/
static void check_station()
{
	 int cnt,i,j,k;
	 unsigned long temp,temp1,temp2,temp4;	   
	 int temp3;
	 TRISTATE_5757DI ;
	 for( i=0; i<60000; i++ )
	 for( j=0; j<10; j++ )
			 k = 1;
	 if( auto_search_flag )
	 {	 
		if(!TEA5757DI_IS_HIGH)
		{	
			delay_5ms();
			delay_5ms();	//tzh 921off for debug
			temp = read_TEA5757() ;
			temp = temp &0x7fff ;
			if( fm_am_flag)
			{											 				 
				   if(fm_freq_step ==20)
				   {
				         temp += 0x08 ;
					  cur_fm_freq= ((temp>>4)-0x1EB)*fm_freq_step +fm_freq_min ; 
				    }
				   else if(fm_freq_step ==10)
				  {
				         temp += 0x04 ;
					  cur_fm_freq= ((temp>>3)-0x3D6)*fm_freq_step +fm_freq_min ; 
                               }
				   else if(fm_freq_step ==5)
				   {
				         temp += 0x02;
					  cur_fm_freq= ((temp>>2)-0x7ac)*fm_freq_step +fm_freq_min ; 
				   } 		   
			          if(auto_search_flag==2)					  /*auto up*/
			          {
						if((cur_fm_freq>(fm_freq_max+fm_freq_step))||(cur_fm_freq<(fm_freq_min -fm_freq_step)))	
						{
                      	               	  if((absolute_search_flag)&&(cur_fm_freq>(fm_freq_max+fm_freq_step)))         // FM all_auto_search 12-10
                            		      	  {             
                                                           #ifdef TUNER_AM
                                                           //开始跳转至AM段内收台
	                                                    fm_am_flag = TUNER_MODE_AM ;      
			                                      cur_am_freq = am_freq_min-6*am_freq_step ;
              						   hand_tuner();
        						          delay_100ms();       
        						          write_frequency() ;     
                                                           #else
								   search_finish();
              	                                      #endif                   	                                      
                                            	}
                                     	 	else  
                         	               	{
						       	 cur_fm_freq = (fm_freq_min-6*fm_freq_step);  
						        	 hand_tuner();
					                      delay_100ms(); 
							        write_frequency() ;	  					        
					             }
					     }
		    		            else          ///////////have station
				            {
                                                 proc_find_station();
		    	                   }
        				     tdm_adc_turn_off();  
					     tdm_adc_turn_on();				    		            
		    	           }
				    else		  /*auto down*/
	 			    {
					     if((cur_fm_freq<fm_freq_min-fm_freq_step)||
					        (cur_fm_freq>fm_freq_max+fm_freq_step))	  
					     {	
							  cur_fm_freq = fm_freq_max +6*fm_freq_step;
					  		  hand_tuner();
							  delay_100ms(); 
							  write_frequency() ;							  
				 	     }
			   		     else      ///////////have station
				  	     {
                                        		  proc_find_station();			 
					     }   
					     tdm_adc_turn_off();  
					     tdm_adc_turn_on();	  			   		     
			 	  }
			  }
	                else 	  /**AM auto search */ 
		         {
				cur_am_freq = temp+am_freq_min -0x3d5 ; 
				if (cur_am_freq%am_freq_step) 
				{
					 temp1=((cur_am_freq/am_freq_step)*am_freq_step);
					 temp2=cur_am_freq-temp1;
					 if (temp2<=4)  
					 {
					 	cur_am_freq=temp1;
					 }
			 		 else
			 		 {
			 		 	cur_am_freq=temp1+am_freq_step;
			 		 }
			 	}
				if(auto_search_flag==2) 					/*auto up*/
				{
			 		if ((cur_am_freq>am_freq_max+am_freq_step)||
			 		    (cur_am_freq<am_freq_min-am_freq_step))	
					{	
					        if((absolute_search_flag) && (cur_am_freq>(am_freq_max+am_freq_step))) 
					        {
					                      /*FM~AM search finished*/
								 search_finish();			        
					        }
					        else
					        {
								cur_am_freq = am_freq_min-6*am_freq_step;								
								hand_tuner();
								delay_100ms();
								write_frequency() ;	
					        }
					}
			      	       else                   ///////////have station
					{
                                            proc_find_station();		
					}
					tdm_adc_turn_off();  
				       tdm_adc_turn_on();	  			      	       
				}
				else	 /*auto down*/
				{
					if ((cur_am_freq<am_freq_min-am_freq_step)||
					    (cur_am_freq>am_freq_max+am_freq_step))	
					{		
						  cur_am_freq = am_freq_max+6*am_freq_step;
						  hand_tuner(); 
						  delay_100ms(); 
						  write_frequency() ; 					  
					}
					else         ///////////have station
					{
 						  proc_find_station();		
				       } 
					tdm_adc_turn_off();  
				       tdm_adc_turn_on();	  					
			     }							
	   	       }		   
            }
       }
}

static void search_finish(void)
{
       #ifdef PHILIPS_GUI
       if (station_counter<2)
       {
		search_ante_flag=1;
       }
       #endif
       auto_search_flag = 0 ;        
       station_counter = 1 ;			     
       read_freq_from_eeprom(station_counter);                                            
       hand_tuner();    
       delay_100ms();
       write_current_freq();		  
	tuner_current_freq_disp();
       demute_proc();	     
       #ifdef M62446
       M62446_demute();
       #endif
}

static unsigned char proc_find_station(void)
{
	  if(absolute_search_flag)         // FM all_auto_search 12-10
         {
        	  if(station_counter<=40)
	         {       
                	      write_freq_to_eeprom(station_counter);          
	             	      if(station_counter==40)
       	      	      {
              	      		 VFD_msg(VFDMSG_prog_full);
	                     	 tuner_program_timeout =3 ;
        	                      auto_search_flag = 0 ;
	       	               absolute_search_flag=0;
                     	        station_counter = 1 ;			     
        		       	 read_freq_from_eeprom(station_counter);  
	        		        hand_tuner() ;
                    		}
	                     else
                    		{
                            	if (fm_am_flag==TUNER_MODE_FM)
                            	{
                            		cur_fm_freq += fm_freq_step;
	                            }
       	                     else
              	              {
                     	       	cur_am_freq += am_freq_step;
                            	}
	                            hand_tuner();    
       	               	delay_100ms(); 
					write_frequency() ;
					#ifdef PHILIPS_GUI
					extern unsigned char station_counter_temp;
					station_counter_temp=station_counter;
					amp_vfd_backup();
					tuner_current_freq_disp();
					VFD_segment_station(1);
					#endif
	              	       station_counter ++;
                   	     }
	                   write_e2prom(FM_AM_FLAG_ADDRESS,fm_am_flag);
          	 } 							                           
         }
	  else  
         {		
			auto_search_flag = 0 ;
			if (fm_am_flag==TUNER_MODE_FM)
			{
				if(cur_fm_freq>fm_freq_max) 
				{
			 		cur_fm_freq=fm_freq_max;  
				}
				if(cur_fm_freq<fm_freq_min)
				{
					cur_fm_freq=fm_freq_min; 
				}
			}
			else
			{
				if(cur_am_freq>am_freq_max) 
				{
			 		cur_am_freq=am_freq_max;  
				}
				if(cur_am_freq<am_freq_min)
				{
					cur_am_freq=am_freq_min; 
				}			
			}			
			hand_tuner() ;			
			write_current_freq();		 
			tuner_current_freq_disp();
			write_e2prom(FM_AM_FLAG_ADDRESS,fm_am_flag);
			demute_proc();	
			#ifdef M62446
			M62446_demute();
			#endif
	}	
}
/*************************************************************************
单步收台:
              处理单步向上或向下收台
***************************************************************************/
void preset_station(void)
{
  	if(preset_up_down_mode==TUNER_UP)
  	{
              freq_increase();
  	}
	else
	{
		freq_decrease();
	}
	hand_tuner();
	write_current_freq();
       tuner_current_freq_disp();
 }

/************************************************************************
检查频率:
          对越界处理
*************************************************************************/
static void check_frequency()
{
	if( fm_am_flag == TUNER_MODE_FM )
	{
		if( cur_fm_freq < fm_freq_min ) 
		{
			cur_fm_freq =fm_freq_max;
		}
		else if ( cur_fm_freq > fm_freq_max )	
		{
			cur_fm_freq = fm_freq_min;
		}
	}
	else
	{
		if( cur_am_freq < am_freq_min )
		{
			cur_am_freq = am_freq_max;
		}
		else if ( cur_am_freq > am_freq_max )
		{
			cur_am_freq = am_freq_min;
		}
	}
	write_current_freq() ;
}

static void write_frequency() 
{
    	  unsigned long temp1=0;
    	  unsigned long temp2=0;

    	  temp2=tuner_sensitive;    	  
	  if( fm_am_flag )	/* FM mode */
	  {   
              if(fm_freq_step ==20 ) //200k   0x1EB= 0x1eb0>>4 
              {
                  temp1 = (((cur_fm_freq /fm_freq_step)+0x1EB)-(fm_freq_min/fm_freq_step)) ;  /*step :100k*/
                  temp1 = temp1<< 4 ;        /* 6d6 0x7ac; 0x1eb0 ;         87.5+10.7MHZ*/
              }
              else if(fm_freq_step ==10 ) //step: 100k      0x3D6= 0x1eb0>>3 
              {
                  temp1 = (((cur_fm_freq /fm_freq_step)+0x3D6)-(fm_freq_min/fm_freq_step)) ;  /*step :100k*/
                  temp1 = temp1<< 3 ;        /* 6d6 0x7ac; 0x1eb0 ;         87.5+10.7MHZ*/
              }
              else if(fm_freq_step ==5 )
              {
                  temp1 = (((cur_fm_freq /fm_freq_step)+0x7ac)-(fm_freq_min/fm_freq_step)) ;  /*step : 50k*/
                  temp1 = temp1<< 2 ;        /* 6d6 0x7ac; 0x1eb0 ;         87.5+10.7MHZ*/
              }
              if(auto_search_flag)
              {
                     if( auto_search_flag==2)
                     {
                           temp1 = 0x1800000|temp1 | ((temp2 & 0xf0)<<12);       /*  indicate auto tuner up*/
                     }
                     else
                     {
                  	      temp1 = 0x1000000|temp1 | ((temp2 & 0xf0)<<12);        /*indicate auto tuner down*/
                     }
              }             
          }
          else         /* AM mode */
          {
	        temp1 = cur_am_freq+0x3d5 -am_freq_min ;   /* 0.5 to 10Mhz */
	        temp1 = 0x520000|temp1 ;
	        if(auto_search_flag)
	        {
		            if( auto_search_flag==2)
		            {
		                  temp1 = 0x1d00000 |temp1 | ((temp2 & 0x0f)<<16);        /*indicate auto tuner up*/     
		            }
		            else
		            {
		                  temp1 = 0x1500000|temp1 | ((temp2 & 0x0f)<<16);        /* indicate auto tuner down*/
		            }
	         }      
	    }    
	    write_TEA5757(temp1);
	    CLEAR_FREQ_HOP ;   
}
  
  /*******************************************************
	 function: Hand step, first write control word and 
				   current frequency to TEA5757
  
  ********************************************************/
void hand_tuner(void)
{   
	 unsigned long reg1,data1 ;	
	 pty_avail_flag=0;        //tzh 040408 add for show pty  
	 
	 CLEAR5757CE;
	 SET5757CLK;
	 TRISTATE_5757DI;	
	 if( fm_am_flag==TUNER_MODE_FM)
        {
               CLEAR_FREQ_HOP;
        	 if(!stereo_mono_flag)
        	 {
	          	 reg1 = 0x440000 ;         //forced to mon state
        	 }

⌨️ 快捷键说明

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