An RC5 decoder and preamp controller. Written on the LPC11U24, Ported to LPC1114 and now 100% stable (January 2016)

Dependents:   AppleRemoteController_copy_Production_Version AppleRemoteController_Reference_Only

Revision:
1:bb881a434906
Parent:
0:83d4a20e7bc7
Child:
2:674e2dd56e7d
--- a/main.cpp	Tue Jun 16 11:22:55 2015 +0000
+++ b/main.cpp	Mon Nov 16 17:11:20 2015 +0000
@@ -1,10 +1,10 @@
-/* **************************** RC5 Decoder  and Preamp Controller V1.0 *************************/
-/*                                  Andrew C. Russell (c) 2015                                  */
+/****************************** RC5 Decoder  and Preamp Controller V1.0 *************************/
+/*                                  AndrewR written in 2015                                     */
 /* This RC5 decoder works by reading in the RC5 stream from one of the serial port lines        */
 /* and saving the incoming stream into  an array called stream, after which it is decoded and   */
-/* the command executed. A Marantz RC-68PM R/C was used to develop this program - it            */
+/* the command executed. A Marantz RC-68PM IR R/C was used to develop this program - it         */
 /* should work with any controller complying with the Philips RC5 standard.                     */
-/* See the rc5codes.h header for the codes used. Note the address is 16 which is for a preamp.  */
+/* See the rc5codes.h header for the codes used.                                                */
 
 /* The following audio preamplifier facilities  are catered for:-                               */
 /* 1. Manual volume control adjustment via ALPS RK27 motorized potentiometer                    */
@@ -13,9 +13,11 @@
 /* 4. Record loop via push button actuation                                                     */
 /* 5. Power ON output to drive the /standby input of a system power supply                      */
 /* Facilities 1,2,3 and 5 are supported by an RC5 compliant remote control for preamplifiers    */
+/* The program can be used with either the LPC11U24 or the LPC1114 - just use the appropriate   */
+/* Pindfefxxxx.h file                                                                           */
 
 #include "mbed.h"
-#include "rc5codes.h"       // Philips RC5 code definitions
+#include "rc5codes.h"      // Philips RC5 code definitions
 #include "Pindef1114.h"    // all microcontroller I/O pin assignments defined here    
 
 #define TRUE 1
@@ -116,12 +118,12 @@
 /*********************************** standby **************************************/
 /* this will require supporting hardware functionality to power down the          */
 /* analog board, LED's etc. Best option here is to use regulators with a          */
-/* shutdown option                                                                */
+/* shutdown option. for now,  all the LED's are just turned off.                  */
 
 void standby_out(void)      // both p/button and R/C come in here
 {
     stdby_int.fall(NULL);   // on first power up cycle NO interuppts are accepted
-    // and neither any while this function is executed in any case
+                    // and neither any while this function is executed in any case
     wait_ms(20);            // a very simple debounce
     do {                    // that waits for the depressed button to be released
         (1);
@@ -132,28 +134,33 @@
         select_int.fall(NULL);
         mute_int.fall(NULL);
         recloop_int.fall(NULL);
+        muteind = LOW;
         muteout = LOW;
-        wait(1);
         recloop_out = LOW;
         select_save = select_drv;       // save the status of select_drv
         select_drv = 0;                 // turn all input select realys OFF
+        //power_ind = LOW;                // this is the regulator shutdown control.  HIGH = ON
         wait(1);
-        power_ind = LOW;                // this is the regulator shutdown control.  HIGH = ON
+        muteind = HIGH;`
         standbyflag = FALSE;            // set it up for the next power cycle
 
     } else if (standbyflag == FALSE) {  // was OFF so we will turn it ON
-        power_ind = HIGH;
+        //printf("i should be here!\n");
+        //power_ind = HIGH;
+        muteind = LOW;
         rc5int.rise(&rc5isr);           // trigger int on rising edge - go service it at rc5dat
         select_int.fall(&select_isr);   // input from rotary encoder or input select
         mute_int.fall(&mute_isr);
         recloop_int.fall(&recloop_isr);
         wait(2);
         select_drv = select_save;       // recall the input select setting
-        wait(2);                        // let things settle a bit
+        wait(2); 
+        muteind = HIGH;                       // let things settle a bit
         muteout = HIGH;
         standbyflag = TRUE;
 
     }
+    //printf("STDB ISR\n");
     wait_ms(5);
     stdby_int.fall(&stdby_isr);         // re-enable the standby interrupt
 }
@@ -183,6 +190,8 @@
 {
     FLAG3 = TRUE;
     toggle2 = !toggle2;                 // so the p/button input is recognized in mute_out()
+    if(muteout = HIGH)
+        {muteind = LOW;}
 }
 /*************************** mute - just a simple toggle **************************/
 void mute_out()
@@ -329,6 +338,7 @@
         case 3:
         {} break;
     }
+    
     select_drv = select_rot;    // write the value out to the bus
 }
 
@@ -347,12 +357,14 @@
 /************************************ main() ***************************************/
 int main(void)
 {
-    __disable_irq();                    // just to make sure we can set up correctly without problems
+    disable_irq();                    // just to make sure we can set up correctly without problems
+    
+    muteind = LOW;
     muteout = LOW;                      // mute the output while we go through  power-up sequence
     recloop_out = LOW;                  // make sure initial recloop condition is delected
-    power_ind = LOW;                    // power control; HIGH = power up
+    //power_ind = LOW;                    // power control; HIGH = power up
     wait(.2);
-    Serial pc(USBTX, USBRX);            // for debuging only - comment out on production
+    //Serial pc(USBTX, USBRX);            // for debuging only - comment out on production
     FLAG1 = FALSE;
     FLAG2 = FALSE;
     FWD1=0;
@@ -372,15 +384,19 @@
     mute_int.fall(NULL);
     recloop_int.fall(NULL);
 
-    standbyflag = HIGH;                 // preamp will be set-up first time for OFF
+//printf("diable ISR\n");
+
+    standbyflag = TRUE;                 // preamp will be set-up first time for OFF
     standby_out();                      // go through standby_out for initial set-up
-    select_save = 1;                    // phono will be selected when power is first turned on
+    select_save = 2;                    // CD will be selected when power is first turned on
+    muteind = HIGH;                    
     __enable_irq();
 
+
     // all ready and in standby from this point forward
 
 LOOP:                                   // this is the main operating loop
-
+//printf("WFI\n");
     __WFI();                            // wait here until interrupt
 
     if (FLAG1 == TRUE) {                // FLAG1 indicates remote control was used
@@ -406,14 +422,17 @@
         FLAG3 = FALSE;
         __enable_irq();
     }
-
+//printf("B4stdby\n");
     if (FLAG4 == TRUE) {
         __disable_irq();
-        standby_out();                  // standby
+        standby_out(); 
+                                        // standby
         FLAG4 = FALSE;
+// printf("back from isr\n"); 
         __enable_irq();
+        //printf("renable isr\n");   
     }
-
+//printf("finished with STBY\n");
     if (FLAG5 == TRUE) {
         __disable_irq();
         recloop();                      //recloop
@@ -422,7 +441,7 @@
     }
 
     wait_us(5);
-
+//printf("loop to WFI\n");
     goto LOOP;
 
 }