Microcontroller drives radio module program

Publisher:幸福梦想Latest update time:2015-06-25 Source: 51heiKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
This is  a subroutine intercepted from http://www.51hei.com/bbs/dpj-20623-1.html . Please download the attachment to call the function.


The radio.h file is as follows:
#ifndef _RADIO_H_
#define _RADIO_H_


uint8 radio_read[5]; //define two five-byte arrays to store memory space for writing control registers and reading data
uint8 radio_write[5]={0x00,0x00,0xd0,0x17,0x00};
//uint16 pll; //14-bit PLL value is stored in one word
static unsigned long frequency; //Radio frequency save variable

/*-----------------------------------------------------------------------------------------------------------------------------------
Write register 1
msb lsb
MUTE SM PLL13 PLL12 PLL11 PLL10 PLL09 PLL08
1: Mute 1: Search mode PLL13->PLL8
0: Normal 0: Non-searching Preset or search for radio station frequency value high 6 bits
--------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------
Write register 2
msb lsb
PLL7 PLL6 PLL5 PLL4 PLL3 PLL2 PLL1 PLL0
PLL7->PLL0
preset or search for radio station frequency low 8 bits
--------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------
Write register 3
msb lsb
SUD SSL1 SSL0 HLSI MS ML MR SWP1
1: Upward search 0 0: No search 1: Local oscillator is higher than the radio station 1: Mono 1: Left channel muted 1: Right channel mute Programmable output port settings 
0: Downward search 0 1: ADC is 5 stop 225KHz 0: Stereo 0: Right channel normal 0: Right channel normal 1: SWPOR1 high
    1 0: ADC is 7 stop 0: Local oscillator is lower than the radio station 0: SWPOR1 low
    1 1: ADC is 10 stop 225KHz
------------------------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------
Write register 4
msb lsb
SWP2 STBY BL XTAL SMUTE HHC SNC SI
Programmable output port 1: Standby 1: 76~91MHz 1: Crystal oscillator 32768Hz 1: Software mute on 1: High level cutting on 1: Stereo noise cancellation on 
1: SWPOR2 high 0: Normal 0: 87.5~108MHz 0: 13MHz 0: Software mute off 0: High level cutting off 0: Stereo noise cancellation off
0: SWPOR2 low
------------------------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------
Write register 5
msb lsb
PLLREF DTC - - - - - -
    1: De-emphasis time 75uS
    0: De-emphasis time 50uS
--------------------------------------------------------------------------------------------------------------------*/
/*---------------------------------------------------------
Function function: Conversion of radio frequency to PLL
Call form: Convert_PLL();
Parameters:
Return value:
Modification time:
Remarks: HLSI is 1, high local oscillator state, XTAL=1,32.768KHz, PLLREF=0
---------------------------------------------------------*/
void Convert_PLL(void)
{
uint16 pll;
uint8 pll1, pll2; //high and low pll values ​​are temporarily stored in variables
pll=((frequency+225000)*4)/32768; //The unit is Hz
pll1=pll/256;
pll2=pll%256;
radio_write[0]=pll1;
radio_write[1]=pll2;
}

/*---------------------------------------------------------
Function: Initialize RADIO module
Call form: Radio_Init();
Parameters:
Return value:
Modify time:
Remarks: Convert PLL value, write control word
---------------------------------------------------------*/
void Radio_Init(void)
{
//frequency=93400000; //Initial radio frequency 93.4MHz
//radio_write[0]=0x00;
//radio_write[1]=0x00;
//radio_write[2]=0xf0;
radio_write[3]=0x40;
//radio_write[4]=0x00;
//Convert_PLL();
frequency=93400000;
SendString(RADIO_ADDRESS,radio_write,5);
}

/*--------------------------------------------------------------------------------------------------------------------
Read Register 1
MSB LSB
RF BLF PLL13 PLL12 PLL11 PLL10 PLL9 PLL8
1: Radio station found 1: Band reached PLL13->PLL8
  or search reached 0: Band not reached Search or preset radio station frequency high 6 bits
0: No radio station found
------------------------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------
Read Register 2
MSB LSB
PLL7 PLL6 PLL5 PLL4 PLL3 PLL2 PLL1 PLL0
PLL7->PLL0
Search or preset radio station frequency low 8 bits
--------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------
Read Register 3
MSB LSB
STERE0 IF6 IF5 IF4 IF3 IF2 IF1 IF0
1: Stereo IF6->IF0
0: Mono IF counter result
------------------------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------
Read register 4
msb lsb
LEV3 LEV2 LEV1 LEV0 CI3 CI2 CI1 CI0
LEV3->LEV0 CI3->CI0
ADC output level Chip identification (all 0)
------------------------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------
Read register 5
, all reserved bits
--------------------------------------------------------------------------------------------------------------------*/
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;
}[page]

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

Keywords:MCU Reference address:Microcontroller drives radio module program

Previous article:Program to realize multi-machine communication between single chip microcomputer and PC
Next article:Homemade Logic Analyzer Using STC12C5A60S2

Recommended ReadingLatest update time:2024-11-16 13:24

[51 microcontroller STC89C52] Timer (interrupt) controls LED
1. Timer/Counter T0 1. Timer/counter related registers 2. Timer/counter control register TCON The TCON format is as follows: 3. Timer/counter operating mode register TMOD Mode selection:   2. Configure related registers 1. Use STC-ISP tool 2. Configuration register Set timer mode (16-bit timer) It is recom
[Microcontroller]
[51 microcontroller STC89C52] Timer (interrupt) controls LED
How to make good use of the memory resources on the microcontroller to realize the storage and access of OD
We know that OD (object dictionary) is the core of CANopen. All functions are carried out around it. It is the data center of the protocol stack. Good OD implementation is the basis for the efficient and stable operation of the protocol stack. The most basic point of OD implementation is how to save it. Because the co
[Microcontroller]
How to eliminate the ghost phenomenon of single chip digital tube
I don't know if you have noticed that the running effects of our two digital tube dynamic display programs do not seem to be so perfect. The first small problem is that if you look carefully, the segments of the digital tube that should not be bright seem to be slightly bright. This phenomenon is called "ghosting". Th
[Microcontroller]
How to eliminate the ghost phenomenon of single chip digital tube
Solid Sands and Taiwan Hanzhi Electronics join forces
Solid Sands and Taiwan Hanzhi Electronics join forces to accelerate MCU microcontroller innovation through high-performance C language compiler Solid Sands, a global leader in C and C++ compiler and library testing and certification, announced today that Taiwan-based Hanzhi Electronics, creator of home
[Embedded]
Solid Sands and Taiwan Hanzhi Electronics join forces
Design of ultrasonic distance measurement based on 51 single chip microcomputer (with temperature compensation)
An ultrasonic rangefinder is made using the STC89C52 microcontroller, ultrasonic module (HC-RS04), DS18B20 digital temperature sensor and LCD1602 liquid crystal display module. The first line of the LCD screen displays the temperature and ultrasonic speed "T:30°C V:349m/s", and the second line displays the measured di
[Microcontroller]
ISP1362OTG design based on ATmega32 microcontroller
0 Introduction With the popularity of consumer products such as PDAs, mobile phones, digital cameras, printers, etc., the high-speed data transmission technology used for these devices and computers, or between devices, has attracted more and more attention. In the past, the data transmission structure
[Microcontroller]
ISP1362OTG design based on ATmega32 microcontroller
ADC learning of CC430 microcontroller
      The storm is coming. To use the general functions of CC430, many modules still need to cooperate. Unity is strength. If you want the rain to fall on time, you must go through the cooperation of all aspects. However, the human brain is not a CPU, and the process cannot be carried out in parallel. The human power
[Microcontroller]
ADC learning of CC430 microcontroller
Optimization Design of Switching Power Supply Based on 89C51 Single Chip Microcomputer
introduction The switching power supply is a new type of voltage-stabilized power supply that uses modern power electronics technology to control the ratio of the time when the power switch tube (MOSFET, IGBT) is turned on and off to stabilize the output voltage. Since the 1990s, switching power supplies have b
[Power Management]
Optimization Design of Switching Power Supply Based on 89C51 Single Chip Microcomputer
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号