Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EFM32_CapSenseSlider EFM32_SegmentLCD RDA5807M mbed-src
main.cpp
00001 /* 00002 RDA5807M FM RDS Radio using the EFM32 Gecko Segment LCD 00003 RDS information is displayed using a PC terminal 00004 00005 Use: 00006 switches PB0 and PB1 for frequency search 00007 Volume controlled by the Touch Slider 00008 Indicators: 00009 Signal level - Ring Segement Display 00010 Stereo received - Antenna Segment Display 00011 RDS available - LED0 00012 */ 00013 00014 #include "mbed.h" 00015 #include "RDA5807M.h" 00016 #include "EFM32_SegmentLCD.h" 00017 #include "EFM32_CapSenseSlider.h" 00018 00019 00020 RDA5807M radio(PC4, PC5); // sda - scl 00021 00022 Serial pc(USBTX, USBRX); 00023 00024 InterruptIn scan_up(SW1); 00025 InterruptIn scan_down(SW0); 00026 00027 DigitalOut led1(LED1); 00028 DigitalOut led0(LED0); 00029 00030 silabs::EFM32_SegmentLCD segmentDisplay; 00031 silabs::EFM32_CapSenseSlider capSlider; 00032 LowPowerTimeout wakeup; 00033 00034 Timer t1; 00035 00036 int x,n,i,l,wake,signal,lastsignal,volume,laststereo; 00037 float lastfreq; 00038 char Station[10],lastStationName[10],vol[4],lastCT[12]; 00039 char RDStxt[70],RDStxt1[70],RDStxt2[70],text1[70],lasttext1[70],text2[70],lasttext2[70]; 00040 00041 void displayrefresh(),getrds(),RTrefresh(); 00042 00043 void scan_upIRQ() { 00044 radio.SeekUp(); 00045 } 00046 00047 void scan_downIRQ() { 00048 radio.SeekDown(); 00049 } 00050 00051 void callback(void) { 00052 wake = 1; 00053 } 00054 00055 void slideCallback(void) { 00056 volume = capSlider.get_position()/3; 00057 if(volume > 15){volume = 15;} 00058 if(volume < 0){volume = 0;} 00059 radio.Volume(volume); 00060 sprintf(vol,"Vol %d", volume); 00061 segmentDisplay.Write(vol); 00062 t1.reset();t1.start(); 00063 } 00064 00065 int main() { 00066 00067 radio.Reset(); // reset and power up radio chip 00068 segmentDisplay.Write("RdA5807"); 00069 wait(1); 00070 segmentDisplay.Write("RDS FM"); 00071 wait(1); 00072 segmentDisplay.Write("Radio"); 00073 capSlider.start(); 00074 capSlider.attach_slide(-1, slideCallback); 00075 scan_up.fall(scan_upIRQ); 00076 scan_down.rise(scan_downIRQ); 00077 wait(1); 00078 00079 while(1){ 00080 radio.ProcessData(); 00081 displayrefresh(); 00082 getrds(); 00083 if(t1.read()>3){strcpy(lastStationName," ");t1.stop();} 00084 wait_ms(1); 00085 wakeup.attach(callback, 0.05f); // MCU average power now 1mA 00086 wake = 0; 00087 while(!wake) sleep(); 00088 } 00089 } 00090 00091 void displayrefresh() 00092 { 00093 if (strcmp(lastStationName, radio.StationName) != 0){ 00094 if(strlen(radio.StationName)<9){ 00095 n=0;for(i=0;i<(8);i++){ // remove non-printable ASCCi error characters 00096 if(radio.StationName[i] > 31){ 00097 Station[n] = radio.StationName[i]; 00098 n++; 00099 } 00100 } 00101 segmentDisplay.Write(Station); 00102 pc.printf("Station:\n%s\n\n",Station); 00103 strcpy(lastStationName,radio.StationName); 00104 } 00105 } 00106 if(lastfreq != radio.freq/1000){lastfreq = radio.freq/1000; 00107 if(radio.freq<100000){ 00108 segmentDisplay.Number(radio.freq/10);segmentDisplay.Symbol(LCD_SYMBOL_DP10,1); 00109 } 00110 else {segmentDisplay.Number(radio.freq/100);segmentDisplay.Symbol(LCD_SYMBOL_DP10,0);} 00111 led0=0; 00112 } 00113 if(laststereo != radio.stereo){ 00114 if(radio.stereo){segmentDisplay.Symbol(LCD_SYMBOL_ANT,1);} 00115 else{segmentDisplay.Symbol(LCD_SYMBOL_ANT,0);} 00116 laststereo = radio.stereo; 00117 } 00118 if(lastsignal != radio.signal){ 00119 signal=radio.signal; 00120 for (i = 0; i < 8; i++) 00121 {segmentDisplay.ARing(i, 0);} 00122 if(signal>4){segmentDisplay.ARing(0, 1);} 00123 if(signal>9){segmentDisplay.ARing(1, 1);} 00124 if(signal>14){segmentDisplay.ARing(2, 1);} 00125 if(signal>19){segmentDisplay.ARing(3, 1);} 00126 if(signal>25){segmentDisplay.ARing(4, 1);} 00127 if(signal>30){segmentDisplay.ARing(5, 1);} 00128 if(signal>35){segmentDisplay.ARing(6, 1);} 00129 if(signal>40){segmentDisplay.ARing(7, 1);} 00130 lastsignal=radio.signal; 00131 } 00132 if(strcmp(RDStxt1, lasttext1) != 0 || strcmp(RDStxt2, lasttext2) != 0){ 00133 RTrefresh(); 00134 } 00135 if(strcmp(lastCT, radio.CTtime) !=0){ 00136 pc.printf("Time: %s\n",radio.CTtime); 00137 strcpy(lastCT,radio.CTtime); 00138 if(led0==1){RTrefresh();} 00139 } 00140 } 00141 00142 void RTrefresh() 00143 { 00144 pc.printf("\n-------------------------------------------\n"); 00145 pc.printf("Station:\n%s\n\n",Station); 00146 pc.printf("RT:\n%s\n",RDStxt1); 00147 pc.printf("%s\n\n",RDStxt2); 00148 pc.printf("Time: %s\n",radio.CTtime); 00149 memset(lasttext1, '\0', sizeof(lasttext1));strcpy(lasttext1, RDStxt1); 00150 memset(lasttext2, '\0', sizeof(lasttext2));strcpy(lasttext2, RDStxt2); 00151 led0=1; 00152 } 00153 00154 void getrds() 00155 { 00156 if(strlen(radio.RDSText)>3){ 00157 memset(RDStxt1, '\0', sizeof(RDStxt1)); 00158 memset(RDStxt2, '\0', sizeof(RDStxt2)); 00159 00160 // format into 2 lines of text seperated by first 'space' after 30 characters 00161 strcpy(RDStxt1,radio.RDSText); 00162 n=strlen(RDStxt1); 00163 for ( i = 0; i < (n); i++ ){ 00164 if (i>30 && (RDStxt1[i] == ' ') ){ 00165 RDStxt1 [strlen(RDStxt1) - (n-i)] = '\0'; 00166 l=strlen(RDStxt1); 00167 x=1; 00168 break; // break if more than 30 characters with space 00169 } 00170 if(i>39){ 00171 RDStxt1 [strlen(RDStxt1) - (n-i)] = '\0'; 00172 l=strlen(RDStxt1); 00173 x=1; 00174 break; //break if more than 39 characters with no spaces 00175 } 00176 } 00177 if(x==1){ 00178 strcpy (RDStxt2, radio.RDSText + l); 00179 while(RDStxt2[0]==' '){ 00180 strcpy (RDStxt2, (RDStxt2 + 1)); 00181 } 00182 x=0; 00183 } 00184 } 00185 }
Generated on Tue Jul 19 2022 02:32:53 by
1.7.2