/*--------------------------------------------------------------------------------------------------------------------
读寄存器1
msb lsb
RF BLF PLL13 PLL12 PLL11 PLL10 PLL9 PLL8
1:发现电台 1:波段到头 PLL13->PLL8
or搜索到头 0:波段未到头 搜索或预置电台频率高6位
0:未发现电台
--------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------
读寄存器2
msb lsb
PLL7 PLL6 PLL5 PLL4 PLL3 PLL2 PLL1 PLL0
PLL7->PLL0
搜索或预置电台频率低8位
--------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------
读寄存器3
msb lsb
STERE0 IF6 IF5 IF4 IF3 IF2 IF1 IF0
1:立体声 IF6->IF0
0:单声道 中频IF计数器结果
--------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------
读寄存器4
msb lsb
LEV3 LEV2 LEV1 LEV0 CI3 CI2 CI1 CI0
LEV3->LEV0 CI3->CI0
ADC输出电平 芯片识别(均为0)
--------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------
读寄存器5
均为保留位
--------------------------------------------------------------------------------------------------------------------*/
void Convert_Frequency()
{
frequency=radio_read[0]&0x3f;
frequency<<=8;
frequency|=radio_read[1];
frequency=frequency*8192-225000;
}
void Radio_Ing(void)
{
static bit k=0;
bit i=0;
uint8 n=0;
uint16 j;
if(!k)
{
k=1;
radio_write[3]=0x17;
}
Convert_PLL();
SendString(RADIO_ADDRESS,radio_write,5);
Display_8x16(0,0,frequency%100000000/10000000);
Display_8x16(8,0,frequency%10000000/1000000);
Display_8x16(16,0,10);
Display_8x16(24,0,frequency%1000000/100000);
/*ReceiveString(RADIO_ADDRESS,radio_read,5);
Display_8x16(0,0,(radio_read[3]&0x80)>>7);
Display_8x16(8,0,(radio_read[3]&0x40)>>6);
Display_8x16(16,0,(radio_read[3]&0x20)>>5);
Display_8x16(24,0,(radio_read[3]&0x10)>>4);*/
for(j=0;j<500;j++)
Display();
while(1)
{
if(ir_value==0x16||ir_value==0x0c||ir_value==0x18||ir_value==0x5e||ir_value==0x08||ir_value==0x1c||ir_value==0x5a||ir_value==0x42||ir_value==0x52||ir_value==0x4a)
{
while(1)
{
if(!i)
{
i=1;
ClearBuf();
//Display_8x16(16,0,10);
}
//if(n==4) frequency*=10;
if(ir_value==0x16)
{ir_value=0xff;Display_8x16(8*n,0,0);if(!n)frequency=0;n++;}
else if(ir_value==0x0c)
{ir_value=0xff;Display_8x16(8*n,0,1);if(!n)frequency=100000000;else if(n==1)frequency+=10000000;else if(n==2) frequency+=1000000;else if(n==3)frequency+=100000;n++;}
else if(ir_value==0x18)
{ir_value=0xff;Display_8x16(8*n,0,2);if(!n)frequency=2*100000000;else if(n==1)frequency+=2*10000000;else if(n==2) frequency+=2*1000000;else if(n==3)frequency+=2*100000;n++;}
else if(ir_value==0x5e)
{ir_value=0xff;Display_8x16(8*n,0,3);if(!n)frequency=3*100000000;else if(n==1)frequency+=3*10000000;else if(n==2) frequency+=3*1000000;else if(n==3)frequency+=3*100000;n++;}
else if(ir_value==0x08)
{ir_value=0xff;Display_8x16(8*n,0,4);if(!n)frequency=4*100000000;else if(n==1)frequency+=4*10000000;else if(n==2) frequency+=4*1000000;else if(n==3)frequency+=4*100000;n++;}
else if(ir_value==0x1c)
{ir_value=0xff;Display_8x16(8*n,0,5);if(!n)frequency=5*100000000;else if(n==1)frequency+=5*10000000;else if(n==2) frequency+=5*1000000;else if(n==3)frequency+=5*100000;n++;}
else if(ir_value==0x5a)
{ir_value=0xff;Display_8x16(8*n,0,6);if(!n)frequency=6*100000000;else if(n==1)frequency+=6*10000000;else if(n==2) frequency+=6*1000000;else if(n==3)frequency+=6*100000;n++;}
else if(ir_value==0x42)
{ir_value=0xff;Display_8x16(8*n,0,7);if(!n)frequency=7*100000000;else if(n==1)frequency+=7*10000000;else if(n==2) frequency+=7*1000000;else if(n==3)frequency+=7*100000;n++;}
else if(ir_value==0x52)
{ir_value=0xff;Display_8x16(8*n,0,8);if(!n)frequency=8*100000000;else if(n==1)frequency+=8*10000000;else if(n==2) frequency+=8*1000000;else if(n==3)frequency+=8*100000;n++;}
else if(ir_value==0x4a)
{ir_value=0xff;Display_8x16(8*n,0,9);if(!n)frequency=9*100000000;else if(n==1)frequency+=9*10000000;else if(n==2) frequency+=9*1000000;else if(n==3)frequency+=9*100000;n++;}
else if(ir_value==0x43)
{ir_value=0xff;Convert_PLL();SendString(RADIO_ADDRESS,radio_write,5);n=0;i=0;break;}
//if(n==2)
//n++;
for(j=0;j<100;j++)
Display();
}
}
else if(ir_value==0x15)
{
ir_value=0xff;//清除
frequency=frequency+100000;
Convert_PLL();
SendString(RADIO_ADDRESS,radio_write,5);
break;
}
else if(ir_value==0x07)
{
ir_value=0xff;
frequency=frequency-100000;
Convert_PLL();
SendString(RADIO_ADDRESS,radio_write,5);
break;
}
else if(ir_value==0x44||ir_value==0x40)//自动搜台
{
while(1)
{
if(ir_value==0x40)//向上自动搜台
{frequency+=100000;if(frequency>108000000)frequency=78000000;}
else {frequency-=100000;if(frequency<78000000)frequency=108000000;}
Convert_PLL();
SendString(RADIO_ADDRESS,radio_write,5);
if(frequency>108000000||frequency<78000000)break;
ReceiveString(RADIO_ADDRESS,radio_read,5);
Convert_Frequency();
if(((radio_read[2]&0x7f<0x3E)&(radio_read[2]&0x7f>0x31)|(radio_read[3]>>4)>5|(radio_read[0]&0x80)))
break;
else if(ir_value==0x43){break;}
Display_8x16(0,0,frequency%100000000/10000000);
Display_8x16(8,0,frequency%10000000/1000000);
Display_8x16(16,0,10);
Display_8x16(24,0,frequency%1000000/100000);
Display();
}
ir_value=0xff;
break;
}
else if(ir_value==0x46)//待机or正常
{
if(radio_write[3]&0x40)
radio_write[3]&=0xbf;
else radio_write[3]|=0x40;
ir_value=0xff;
//i=0;
break;
}
else if(ir_value==0x43||matrix.S==FIRST)
{
ir_value=0xff;
// i=0;
k=0;
//Radio_Init();不待机即可后台运行
matrix.S=FIRST;
break;
}
}
}
void Radio_Key(void)
{
if(!KEY_ENTER)
{
DelayMs(SCAN_DELAY);
if(!KEY_ENTER)
{
while(!KEY_ENTER)
;
matrix.S=FIRST;
}
}
}
/*
void Radio_Read1()
{
ReceiveString(0xc0,radio_read,5);
Convert_Frequency();
if(radio_read[0]&0x80)
temp[6]=duanma[1];
else temp[6]=duanma[0];
if(radio_read[0]&0x40)
{
temp[7]=duanma[1];
}
else temp[7]=duanma[0];
temp[0]=duanma[frequency/100];
temp[1]=duanma[frequency%100/10];
temp[2]=duanma[frequency%10];
}
*/
#endif