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
Diff: main.cpp
- Revision:
- 2:893e9004c547
- Parent:
- 0:b0927d62ef70
- Child:
- 3:1220287bcbd7
diff -r 2bca6370ae45 -r 893e9004c547 main.cpp
--- a/main.cpp Wed Apr 29 07:33:32 2015 -0700
+++ b/main.cpp Sat May 23 14:48:15 2015 +0000
@@ -1,15 +1,173 @@
+/*
+RDA5807M FM RDS Radio using the EFM32 Gecko Segment LCD
+RDS information is displayed using a PC terminal
+
+Use:
+switches PB0 and PB1 for frequency search
+Volume controlled by the Touch Slider
+Indicators:
+Signal level - Ring Segement Display
+Stereo received - Antenna Segment Display
+RDS available - LED0
+*/
+
#include "mbed.h"
+#include "RDA5807M.h"
+#include "EFM32_SegmentLCD.h"
+#include "EFM32_CapSenseSlider.h"
+
+
+RDA5807M radio(PC4, PC5); // sda - scl
+
+Serial pc(USBTX, USBRX);
+
+InterruptIn scan_up(SW1);
+InterruptIn scan_down(SW0);
+
+DigitalOut led1(LED1);
+DigitalOut led0(LED0);
+
+silabs::EFM32_SegmentLCD segmentDisplay;
+silabs::EFM32_CapSenseSlider capSlider;
+
+Timer t1;
-DigitalOut myled(LED1);
-LowPowerTicker toggleTicker;
+int n,i,l,signal,lastsignal,volume,lastrds,laststereo,rdstextgood;
+float lastfreq;
+char Station[10],lastStationName[10],vol[4];
+char RDStxt[70],RDStxt1[70],RDStxt2[70],text1[50],lasttext1[50],text2[50],lasttext2[50];
+
+void displayrefresh(),getrds();
+
+void scan_upIRQ() {
+ radio.SeekUp();
+}
+
+void scan_downIRQ() {
+ radio.SeekDown();
+}
-void ledToggler(void) {
- myled = !myled;
+void slideCallback(void) {
+ volume = capSlider.get_position()/3;
+ if(volume > 15){volume = 15;}
+ if(volume < 0){volume = 0;}
+ radio.Volume(volume);
+ sprintf(vol,"Vol %d", volume);
+ segmentDisplay.Write(vol);
+ t1.reset();t1.start();
+}
+
+int main() {
+
+ radio.Reset(); // reset and power up radio chip
+ segmentDisplay.Write("RdA5807");
+ wait(1);
+ segmentDisplay.Write("RDS FM");
+ wait(1);
+ segmentDisplay.Write("Radio");
+ capSlider.start();
+ capSlider.attach_slide(-1, slideCallback);
+ scan_up.fall(scan_upIRQ);
+ scan_down.rise(scan_downIRQ);
+ wait(1);
+
+ while(1){
+ radio.processData();
+ displayrefresh();
+ getrds();
+ wait_ms(50);
+ if(t1.read()>3){strcpy(lastStationName," ");t1.stop();}
+ }
}
+
+void displayrefresh()
+{
+ if (strcmp(lastStationName, radio.StationName) != 0){
+ if(strlen(radio.StationName)<9){
+ n=0;for(i=0;i<(8);i++){ // remove non-printable ASCCi error characters
+ if(radio.StationName[i] > 31){
+ Station[n] = radio.StationName[i];
+ n++;
+ }
+ }
+ segmentDisplay.Write(Station);
+ strcpy(lastStationName,radio.StationName);
+ }
+ }
+ if(lastfreq != radio.freq/1000){lastfreq = radio.freq/1000;
+ if(radio.freq<100000){
+ segmentDisplay.Number(radio.freq/10);segmentDisplay.Symbol(LCD_SYMBOL_DP10,1);
+ }
+ else {segmentDisplay.Number(radio.freq/100);segmentDisplay.Symbol(LCD_SYMBOL_DP10,0);}
+ rdstextgood=0;lastrds=!lastrds;
+ }
+ if(laststereo != radio.stereo){
+ if(radio.stereo){segmentDisplay.Symbol(LCD_SYMBOL_ANT,1);}
+ else{segmentDisplay.Symbol(LCD_SYMBOL_ANT,0);}
+ laststereo = radio.stereo;
+ }
+ if(lastsignal != radio.signal){
+ signal=radio.signal;
+ for (i = 0; i < 8; i++)
+ {segmentDisplay.ARing(i, 0);}
+ if(signal>4){segmentDisplay.ARing(0, 1);}
+ if(signal>9){segmentDisplay.ARing(1, 1);}
+ if(signal>14){segmentDisplay.ARing(2, 1);}
+ if(signal>19){segmentDisplay.ARing(3, 1);}
+ if(signal>25){segmentDisplay.ARing(4, 1);}
+ if(signal>30){segmentDisplay.ARing(5, 1);}
+ if(signal>35){segmentDisplay.ARing(6, 1);}
+ if(signal>40){segmentDisplay.ARing(7, 1);}
+ lastsignal=radio.signal;
+ }
+ if(lastrds != radio.rds){
+ if(radio.rds){
+ if(rdstextgood){led0=1;}
+ else{led0=0;}
+ }
+ else{led0=0;rdstextgood=0;}
+ lastrds=radio.rds;
+ }
+ if (strcmp(text1, lasttext1) != 0){
+ pc.printf(Station);
+ pc.printf("\n %s\n",text1);
+ memset(lasttext1, '\0', sizeof(lasttext1));strcpy(lasttext1, text1);}
+ if (strcmp(text2, lasttext2) != 0){
+ pc.printf(" %s\n\n",text2);
+ memset(lasttext2, '\0', sizeof(lasttext2));strcpy(lasttext2, text2);}
+}
+
+void getrds()
+{
+ if(strlen(radio.RDSText)==64 && signal>23){
+ memset(text1, '\0', sizeof(text1));
+ memset(text2, '\0', sizeof(text2));
+ if(!rdstextgood){rdstextgood=1;lastrds=!lastrds;}
+ // remove non-printable ASCCi error characters
+ n=0;
+ for(i=0;i<(64);i++){
+ if(radio.RDSText[i] > 31){
+ RDStxt[n] = radio.RDSText[i];
+ n++;
+ }
+ }
+ // slit into 2 lines of text seperated by 'space'
+ strcpy(RDStxt1,RDStxt);
+ for ( i = 0; i < (n); i++ ){
+ if (i>30 && (RDStxt1[i] == ' ') ){
+ RDStxt1 [strlen(RDStxt1) - (n-i)] = '\0';
+ l=strlen(RDStxt1);
+ i=n;
+ } }
+ strcpy (RDStxt2, RDStxt + l);
+ while(RDStxt2[0]==' '){
+ strcpy (RDStxt2, (RDStxt2 + 1));
+ }
+ if(strlen(RDStxt1)<40){strcpy (text1, RDStxt1);}
+ if(strlen(RDStxt2)<40){strcpy (text2, RDStxt2);}
+
+ memset(radio.RDSText, '\0', sizeof(radio.RDSText));
+ }
+}
+
-int main() {
- toggleTicker.attach(&ledToggler, 0.2f);
- while(1) {
- sleep();
- }
-}
\ No newline at end of file