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

📄 tunner.c

📁 sanyo1787 and TEF6606 source code
💻 C
📖 第 1 页 / 共 2 页
字号:
     if((Radio.store==1)&&(j<18))
       {
        j++;
        FMTable[j] = i+1;   //FM-874        
       }
    }
  FMTable[0]=j;
  if((j!=0)&&(Radio.stop==0))
    {
     Radio.fm = FMTable[1]+874;    //p[1] = FM-874
     Radio.chanel=1;
     Radio.band=0;
    }
  Radio.stop = 1;
  k = (Radio.fm+107)*4;
  RadioTune(FM_D0,FM_D2,k);          
  WriteTC9257(0xd2,IF_STOP,FM_ST_RQ); 
  Radio.smode= LastRadioMode;         
  LCD_radio_display(Radio.fm);
  Mute_OFF();
}

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//handle up/down tune AM
void HandleTuneAM(void)
{
  unsigned int k;
  Radio.chanel=0;
  if(Radio.down)
    Radio.am=Radio.am-9;
   else
    Radio.am=Radio.am+9;
  if(Radio.am<531)
    Radio.am = 1629;
  if(Radio.am>1629)
    Radio.am = 531;
  k = (Radio.am+10710)/9 ;
  k = k<<4;                     //eaqual ((fr.am+10710)/9)*16 
  RadioTune(AM_D0,AM_D2,k);          //d0,d2,frequency
  WriteTC9257(0xd2,IF_STOP,AM_ST_RQ);         //FM_ST_RQ  0x0e  
  LCD_radio_display(Radio.am);
}

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//auto up/down one step tune AM
void AutoTuneAM(void)
{
  unsigned char i;
  unsigned int k,lastfrequce;
  Mute_ON();
  Radio.chanel=0;
  Radio.am = (Radio.am/9)*9;
  lastfrequce = Radio.am;
  for(i=0;i<123;i++)                   //step hz
    {
     if(Radio.stop)
       break;    
     if(Radio.down)
       Radio.am=Radio.am-9;
      else
       Radio.am=Radio.am+9;
     if(Radio.am<531)
       Radio.am = 1629;
     if(Radio.am>1629)
       Radio.am = 531;
     k = (Radio.am+10710)/9 ;
     k = k<<4;                     //eaqual ((fr.am+10710)/9)*16 
     RadioTune(AM_D0,AM_D2,k);          //d0,d2,frequency
     WriteTC9257(0xd2,IF_STOP,AM_ST_RQ);         //FM_ST_RQ  0x0e  
     LCD_radio_display(Radio.am);
     if((IF<0x7050)||(IF>0x70c0))    //Test PLL ,450KHZ(0x7080)  1khz
       {
         IF = 0;
         continue ;
       }
     /*if(Radio.down)
       {
        if(Radio.am==lastfrequce-9)     // repeat chanel check
          {
           IF = 0;          
           continue ;
          }
       }
      else
       {
        if(Radio.am==lastfrequce+9)     // repeat chanel check
          {
           IF = 0;          
           continue ;
          }
       }*/
     break;
    }
  Radio.stop=1; 
  RadioStateDis();    //search ending,undisplay state information
  Mute_OFF();
}

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//up/down scan tune AM
void ScanTuneAM(void)
{
  unsigned char i,timer,LastRadioMode;
  unsigned int k,lastfrequce;
  Mute_ON();
  Radio.chanel=0;
  LastRadioMode = Radio.smode;
  Radio.smode = 1;
  Radio.am = (Radio.am/9)*9;
  lastfrequce = Radio.am;
  for(i=0;i<123;i++)                   //step hz
    {
     if(Radio.stop)
       break;    
     if(Radio.down)
       Radio.am=Radio.am-9;
      else
       Radio.am=Radio.am+9;
     if(Radio.am<531)
       Radio.am = 1629;
     if(Radio.am>1629)
       Radio.am = 531;
     k = (Radio.am+10710)/9 ;
     k = k<<4;                     //eaqual ((fr.am+10710)/9)*16 
     RadioTune(AM_D0,AM_D2,k);          //d0,d2,frequency
     WriteTC9257(0xd2,IF_STOP,AM_ST_RQ);         //FM_ST_RQ  0x0e  
     LCD_radio_display(Radio.am);
     if((IF<0x7050)||(IF>0x70c0))    //Test PLL ,450KHZ(0x7080)  1khz
       {
         IF = 0;
         continue ;
       }
     /*if(Radio.down)
       {
        if(Radio.am==lastfrequce-9)     // repeat chanel check
          {
           IF = 0;          
           continue ;
          }
       }
      else
       {
        if(Radio.am==lastfrequce+9)     // repeat chanel check
          {
           IF = 0;          
           continue ;
          }
       }*/
     lastfrequce = Radio.am; 
      
     timer=watch.second+5;     //PLAY 5 SECONDS
     if(timer>59)
       timer=timer-60;
	 Mute_OFF();
     while(1)
       {
        if(Radio.stop)
          break;    
        if(Radio.down)
          {
           if(watch.ms125%8<4)      //down           
             SEG22_COM0=1;             
            else
             SEG22_COM0=0;                   
          }
         else
          {
           if(watch.ms125%8<4)         //up        
             SEG30_COM0=1;             
            else
             SEG30_COM0=0;                   
          }
        if(timer==watch.second)
         {
           Mute_ON();
           break;
         }
       }
    }
  Radio.stop = 1;
  Radio.am=lastfrequce;            //Retain the last chanel
  k = ((Radio.am+10710)/9)<<4 ;
  RadioTune(AM_D0,AM_D2,k);
  WriteTC9257(0xd2,IF_STOP,AM_ST_RQ); 
  Radio.smode= LastRadioMode;        
  LCD_radio_display(Radio.am);
  Mute_OFF();
}

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//up scan and store tune AM
void ScanSaveAM(void)
{
  unsigned char i,j,timer,LastRadioMode;
  unsigned int k,lastfrequce;
  Mute_ON();
  Radio.chanel=0;
  lastfrequce=0;
  LastRadioMode = Radio.smode;
  Radio.smode = 3;
  Radio.down = 0;
  AMTable[0]=0;
  for(j=1;j<13;j++)
   AMTable[j]=1;
  j=0;
  k=19968;     //(522+10710)/9*16
  for(i=0;i<123;i++)                   //step hz
    {
     if(Radio.stop)
       break; 
     k = k+16;          //eaqual (am+10710)/9*16 
     RadioTune(AM_D0,AM_D2,k);          //d0,d2,frequency
     WriteTC9257(0xd2,IF_STOP,AM_ST_RQ);         //FM_ST_RQ  0x0e
     switch(j/6)
        {
          case 0: Radio.band=3;  //AM1
                  break;            
          case 1: Radio.band=4;  //AM2
                  break;
        }  
     Radio.am=k/16*9-10710;
     LCD_radio_display(Radio.am);
     if((IF<0x7050)||(IF>0x70c0))    //Test PLL ,450KHZ(0x7080)  1khz
       {
         IF = 0;
         continue ;
       }
    /* if(k==lastfrequce+16)     // repeat chanel check
       {
         IF = 0;          
         continue ;
       }*/
     lastfrequce = k;

     Radio.store = 1;      //default--store the chanel
     timer=watch.second+5;     //PLAY 5 SECONDS
     if(timer>59)
       timer=timer-60;
	 Mute_OFF();
     while(1)
       {
        if(Radio.stop||!Radio.store)
          break;
        if(watch.ms125%8<4)           // up arrow        
           SEG30_COM0=1;             
         else
           SEG30_COM0=0;
        if(j<12)          
          LCD_NO_display(8,(j%6)+1);
        if(timer==watch.second||!Radio.store)
         {
           Mute_ON();
           break;
         }
       }
     if((Radio.store==1)&&(j<13))
       {
        j++;
        AMTable[j] = i+1;   // AM/9-58     
       }
    }
    
  AMTable[0]=j;
  if(j!=0&&Radio.stop==0)
    {
     Radio.am = (AMTable[1]+58)*9;    //
     Radio.chanel=1;
     Radio.band=3;
    }
  Radio.stop = 1;
  k = (Radio.am+10710)/9 ;
  k = k<<4;                        
  RadioTune(AM_D0,AM_D2,k);          
  WriteTC9257(0xd2,IF_STOP,AM_ST_RQ);
  Radio.smode= LastRadioMode;           
  LCD_radio_display(Radio.am);
  Mute_OFF();
}

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
void Radio_Init(void)
{
  unsigned int k;
  LCD_Clear_all();  
  Radio.store = 0;  //1 =store
  Radio.stop = 1;   //0=run,1=stop 
  Radio.down = 0;  //0=up,1=down
  S_Meter_On_Off=0;
  Radio.chanel=0;
  if(Radio.band>4)   
    Radio.band=0;
  System.Special_disp_Mode=dSpecial_disp_Rotator;
  System.RotatorMode=dRotator_Volume;
  System.Special_disp_Timer=0;
  if(Radio.band/3)
    {
     k = (Radio.am+10710)/9 ;
     k = k<<4;                        
     RadioTune(AM_D0,AM_D2,k);          
     WriteTC9257(0xd2,IF_STOP,AM_ST_RQ);           
     LCD_radio_display(Radio.am);
    }
   else
    {
     k = (Radio.fm+107)*4;
     RadioTune(FM_D0,FM_D2,k);          
     WriteTC9257(0xd2,IF_STOP,FM_ST_RQ);          
     LCD_radio_display(Radio.fm);
    }
  Radio_Audio();
}

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
void LoadChanle(unsigned char i)
{
  unsigned int k;
  unsigned char j;
  LCD_Special_Disp_SET(dSpecial_disp_OFF);
  if(Radio.stop)
    {
     j=Radio.band*6+i;
     if(j<19)    //FM
       {
           Radio.chanel=i;
           Radio.fm=FMTable[j]+874;
           k = (Radio.fm+107)*4;
           RadioTune(FM_D0,FM_D2,k);          
           WriteTC9257(0xd2,IF_STOP,FM_ST_RQ);          
           LCD_radio_display(Radio.fm);
       }
      else    //AM
       {
           j=j-18;
           Radio.chanel=i;
           Radio.am=(AMTable[j]+58)*9;
           k = (Radio.am+10710)/9 ;
           k = k<<4;                        
           RadioTune(AM_D0,AM_D2,k);          
           WriteTC9257(0xd2,IF_STOP,AM_ST_RQ);           
           LCD_radio_display(Radio.am);
       }
	 Mute_OFF();
    } 
}

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
void SaveChanle(unsigned char i)
{
  unsigned char j,k;
  if(Radio.stop)
    {
     j=i+Radio.band*6;
     if(j<19)               //FM
       {
        if(j>FMTable[0])
          FMTable[0]=j;
         else            //insert a FM chanel
          {
           FMTable[0]++;
           for(k=FMTable[0];k>j;k--)
             FMTable[k]=FMTable[k-1];
          } 
        FMTable[j]=Radio.fm-874;
        Radio.chanel=i;
        LCD_NO_display(8,i);
       }
      else       //AM
       {
        j=j-18;
        if(j>AMTable[0])
          AMTable[0]=j;
         else        //insert a AM chanel
          {
           AMTable[0]++;
           for(k=AMTable[0];k>j;k--)
             AMTable[k]=AMTable[k-1];
          }  
        AMTable[j]=Radio.am/9+1;
        Radio.chanel=i;
        LCD_NO_display(8,i);  
       }
    } 
}
#endif
#ifdef TEF6606
//void  Set_Slaver_Addr(unsigned char slaver_address)
//{
  	//IAAR0 = (slaver_address >>1);
//}
void Init_Hardware_I2C(void)
{
  
   //Set_Slaver_Addr(0xC0);
   Write_Buff[0]=\
   Write_Buff[1]=\
   Write_Buff[2]=\
   Write_Buff[3]=\
   Write_Phase=0;
   Read_Buff[0]=\
   Read_Buff[1]=\
   Read_Buff[2]=\
   Read_Buff[3]=\
   Read_Buff[4]=\
   Read_Phase=0;
   Write_Length=0;
   IIC_Error=0;
   ICCR0=0xa4;	//Enable IIC and Set clk =100kHz;
   IBCR00=0x84;	//Disable AACKX in Master Mode, Enable stop interrupt 
   IBCR10=0x4A;	//Enable Bus Error Int, Date Ack,Transfer Compeletion Int, set  Slave mode for not start IIC
   				//Disable SCC Function
}
//////////////////////////////////////////
void Start_Hardware_I2C(void)
{
	IBCR10_MSS=1;
}
/////////////////////////////////////////
void Stop_Hardware_I2C(void)
{
	IBCR10_MSS=0;
}
/////////////////////////////////////////
void Set_Write_Buf_Freq(void)
{
	Write_Buff[0]=0xc0;
	Write_Buff[1]=0x20;
	Write_Buff[2]=0x28;	//fm 103.7MHz
	Write_Buff[3]=0x1a;
	Write_Buff[4]=0x00;
}
////////////////////////////////////////
void Write_Tef(unsigned char length)
{
	if(IBSR0_BB==0 && Write_Phase==0)
		{
			IDDR0=Write_Buff[Write_Phase++];
			Write_Length=length;
			Start_Hardware_I2C();
		}
}
///////////////////////////////////////////////////////
void Read_Tef(void)
{
	if(IBSR0_BB==0 && Read_Phase==0)
		{
			IDDR0=0xC1;
			Read_Phase=0xff;		//Send Device Address
			Start_Hardware_I2C();
		}
}
///////////////////////////////////////////////////////
void TEF_Preset(unsigned char freq1,unsigned char freq2)
{
	Write_Buff[0]=0xc0;
	Write_Buff[1]=0x20;
	Write_Buff[2]=freq1;	//band and frequence
	Write_Buff[3]=freq2;
	Write_Tef(0x04);
}
////////////////////////////////////////////////////
void TEF_Search(unsigned char freq1,unsigned char freq2)
{
	Write_Buff[0]=0xc0;
	Write_Buff[1]=0x40;
	Write_Buff[2]=freq1;	//band and frequence
	Write_Buff[3]=freq2;
	Write_Tef(0x04);
}
////////////////////////////////////////////////////
#if 0
void TEF_No_Action(void)
{
	Write_Buff[0]=0xc0;
	Write_Buff[1]=0x00;
	Write_Tef(0x02);
}
#endif 
//////////////////////////////////////////////////////
void TEF_Stop(void)
{
	Write_Buff[0]=0xc0;
	Write_Buff[1]=0xe0;
	Write_Tef(0x02);
}
/////////////////////////////////////////////////////
void TEF_AF_Updata(unsigned char freq1,unsigned char freq2)
{
	Write_Buff[0]=0xc0;
	Write_Buff[1]=0x60;
	Write_Buff[2]=freq1;	//band and frequence
	Write_Buff[3]=freq2;
	Write_Tef(0x04);
}
/////////////////////////////////////////////////////
void TEF_AF_Jump(unsigned char freq1,unsigned char freq2)
{
	Write_Buff[0]=0xc0;
	Write_Buff[1]=0x80;
	Write_Buff[2]=freq1;	//band and frequence
	Write_Buff[3]=freq2;
	Write_Tef(0x04);
}
////////////////////////////////////////////////////////
void TEF_AF_Check(unsigned char freq1,unsigned char freq2)
{
	Write_Buff[0]=0xc0;
	Write_Buff[1]=0xa0;
	Write_Buff[2]=freq1;	//band and frequence
	Write_Buff[3]=freq2;
	Write_Tef(0x04);
}
/////////////////////////////////////////////////////////
void TEF_Image_Test(void)
{
	Write_Buff[0]=0xc0;
	Write_Buff[1]=0xc0;
	Write_Tef(0x02);
}
/////////////////////////////////////////////////////////
void TEF_Wtite_Any(unsigned char address, unsigned char data)
{
	Write_Buff[0]=0xc0;
	Write_Buff[1]=address;
	Write_Buff[2]=data;
	Write_Tef(0x03);
}
#endif

⌨️ 快捷键说明

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