微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > STM32 模拟IIC协议驱动TEA5767

STM32 模拟IIC协议驱动TEA5767

时间:12-02 来源:互联网 点击:

Search_Over=0;

static unsigned char Radio_Search_Flag=0;

unsigned char Radio_Mute=Mute_Off;

void Write_TEA5767(void)

{

uchar i=0;

delay_us(0);

IIC_Start();

IIC_Send_Byte(W_TEA5767);

if(!IIC_Wait_Ack())

{

for(i=0;i<5;i++)

{

IIC_Send_Byte(Radio_Write_Buf[i]);

if(IIC_Wait_Ack())

{

GUI_DispStringAt("Write buffer Failed !",10,100);

break;

}

}

}

else

{

GUI_DispStringAt("Failed !",10,80);

}

IIC_Stop();

}

void Read_TEA5767(void)

{

uchar i=0;

IIC_Start();

IIC_Send_Byte(0xc1);

if (!IIC_Wait_Ack()) //chip addr of read data

{

for (i=0;i<5;i++)

Radio_Read_Buf[i] =(i==4)? IIC_Read_Byte(0):IIC_Read_Byte(1); //the last byte with ACK.

IIC_Stop();

// GUI_DispStringAt("Read TEA5767 Completed !",10,100);

}

else IIC_Stop();

pll=(Radio_Read_Buf[0]&0x3f)*256+Radio_Read_Buf[1]+1; ////!!!!! +1

if(Radio_Write_Buf[2]&0x10)

{

Frequency_Read=pll*8192-225000;

}

else

{

Frequency_Read=pll*8192+225000;

}

}

void Radio_Set_Frequency(void)

{

if(Radio_Write_Buf[2]&0x10)

{

pll=(((Frequency_Write*1000)+225000)*4)/32768;

}

else

{

pll=(((Frequency_Write*1000)-225000)*4)/32768;//本例为低边带接收方式

}

Radio_Write_Buf[0] = pll/256;

Radio_Write_Buf[1] = pll%256;

Radio_Write_Buf[0]&= 0x3F;//不静音不搜索

if(Radio_Mute==Mute_On)

Radio_Write_Buf[0]|=0x80;//

else

Radio_Write_Buf[0]&=0x7f;//

Radio_Write_Buf[2] = 0x00;

Radio_Write_Buf[3] = 0x12;

Radio_Write_Buf[4] = 0x00;

Write_TEA5767();

}

void Radio_Manual_Search(void)

{

if(Search_Mode_Flag)

{

Frequency_Write+=100; //步进100KHZ

if(Frequency_Write>Max_frequency)

{

Frequency_Write=Min_frequency;

}

}

else

{

Frequency_Write-=100;

if(Frequency_Write

{

Frequency_Write=Max_frequency;

}

}

Radio_Set_Frequency();

}

void Radio_Search (void)

{

switch(Radio_Search_Flag)

{

case 0:

{

Radio_Mute=Mute_On; //静音打开

Radio_Manual_Search();

Radio_Search_Flag=1;

}

case 1:

{

unsigned char Radio_If;

// _delay_ms(100);

Read_TEA5767();

Radio_If=Radio_Read_Buf[2]&0x7f;

if((Radio_Read_Buf[3]>>4)>4) //ADC大于4停止

{

if((Radio_If>0x30)&&(Radio_If<0x3a)) //比较IF

{

Radio_On_Flag=0; //关闭搜索

Radio_Write_Buf[0]&=0x7f; //静音关闭

Write_TEA5767();

}

Radio_Search_Flag=0;

}

else //ADC小于4继续

{

Radio_Search_Flag=0;

}

Radio_Frequency_Display();

Radio_Power_Display();

}

}

}

void Radio_Power_Display(void)

{

unsigned char Temp;

Temp = (Radio_Read_Buf[3]>>4);//RF信号强度ADC

GUI_GotoXY(140,0);

GUI_DispString("RF:");

GUI_DispDec(Temp,2);

Temp = (Radio_Read_Buf[2]&0x7f);//中频计数结果,正确调谐时在之间

GUI_GotoXY(200,0);

GUI_DispString("IF:");

GUI_DispHex(Temp,2);

if((Temp>=0x31)&&(Temp<=0x3e))

GUI_DispStringAt("Good",200,20);

else

GUI_DispStringAt("Bad ",200,20);

}

void Radio_Frequency_Display(void)

{

char Display_Bit[9]="000.0MHz ";

Frequency_Read=Frequency_Read/1000;

Display_Bit[0] = Frequency_Read / 100000;

if ( Display_Bit[0] == 0 )

{

Display_Bit[0] = 0;

}

else

{

Display_Bit[0] += 0x30;

}

Display_Bit[1] = (Frequency_Read/ 10000)%10 +0x30;

Display_Bit[2] = (Frequency_Read/ 1000)%10 +0x30;

Display_Bit[4] = (Frequency_Read / 100)%10 +0x30;

GUI_DispStringAt(Display_Bit,140,20);

}

void TEA5767(void)

{

static uchar i=0;

if(!i)

{

IIC_Init();

delay_us(0);

IIC_Stop();

i++;

Frequency_Write= 93600;

Radio_Set_Frequency();

}

Read_TEA5767();

Radio_Frequency_Display();

Radio_Power_Display();

GUI_GotoXY(10,0);

GUI_DispString("W:");

TFT_DispHexStringAt(6*2+10,0 ,Radio_Write_Buf,5);

GUI_GotoXY(10,20);

GUI_DispString("R:");

TFT_DispHexStringAt(6*2+10,20,Radio_Read_Buf ,5);

// GUI_DispDecAt(ack_cnt,10,40,3);

}

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


Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top