微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 单片机驱动收音机模块程序

单片机驱动收音机模块程序

时间:11-30 来源:互联网 点击:

void Radio_Ing(void)
{
static bit k=0;
biti=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;
elseradio_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;
}
}
}

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

网站地图

Top