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:
2:674e2dd56e7d
Parent:
1:bb881a434906
Child:
3:f0cd7c22ca94
--- a/main.cpp	Mon Nov 16 17:11:20 2015 +0000
+++ b/main.cpp	Fri Nov 20 14:36:14 2015 +0000
@@ -38,9 +38,10 @@
 //define REC_IN 32
 
 int startbit;
-int toggle;
-int toggle1;
-int toggle2;
+int toggle;                 // this is the 3rd bit position in the input stream and checks for 
+                            // subsequent button depresses from the r/control
+int toggle1;                // temorary storage in the volume UP and volume DOWN functions
+int toggle2;                // temprary storage of the PB in the mute function
 int standby;
 int address;
 int command;
@@ -62,6 +63,8 @@
 int select_save = 1;        // we save the status of select drive here. Initial value is 1
 int select_rot = 1;         // rotary encoder pulse counter
 
+//int loop_counter = 0;       // debug loop counter
+
 // declare function prototypes here
 void select_out (void);
 void rc5isr(void);
@@ -110,7 +113,7 @@
     wait_ms(1);
 }
 /********************************** stdby_isr *************************************/
-void stdby_isr (void)
+void stdby_isr(void)
 {
     FLAG4 = TRUE;
 }
@@ -136,16 +139,18 @@
         recloop_int.fall(NULL);
         muteind = LOW;
         muteout = LOW;
-        recloop_out = LOW;
+        recloop_out = HIGH;             // make sure the recloop is OFF [its active HIGH]
         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);
-        muteind = HIGH;`
+        muteind = HIGH;
         standbyflag = FALSE;            // set it up for the next power cycle
 
+
+
     } else if (standbyflag == FALSE) {  // was OFF so we will turn it ON
-        //printf("i should be here!\n");
+        //printf("Going thru power up\n\r");
         //power_ind = HIGH;
         muteind = LOW;
         rc5int.rise(&rc5isr);           // trigger int on rising edge - go service it at rc5dat
@@ -155,14 +160,15 @@
         wait(2);
         select_drv = select_save;       // recall the input select setting
         wait(2); 
-        muteind = HIGH;                       // let things settle a bit
+        muteind = HIGH;                 // let things settle a bit
         muteout = HIGH;
         standbyflag = TRUE;
-
+    //printf("Finished powering up in standby_out\n\r");
     }
-    //printf("STDB ISR\n");
     wait_ms(5);
-    stdby_int.fall(&stdby_isr);         // re-enable the standby interrupt
+     stdby_int.fall(&stdby_isr);        // re-enable the standby interrupt
+    //printf("exiting standby_out handler now\n\r");
+             
 }
 
 /********************************** record loop isr *******************************/
@@ -190,8 +196,7 @@
 {
     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()
@@ -201,12 +206,14 @@
         wait_ms(20);                    //simple debounce for when mute is via the f/p p/b switch
         do {
             (1);                        //wait here until the button is released
-        } while (mute != 1);
-        muteout = !muteout;
+        } while (mute != 1);            
+        muteout = !muteout;             // flip the mute relay
+        muteind = !muteout;             // Turn the indicator LED ON - it inverted compared to muteout
         wait_ms(20);
 
     }
     toggle2 = toggle;
+    //toggle = toggle2;
     mute_int.fall(&mute_isr);
 }
 
@@ -357,20 +364,28 @@
 /************************************ 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;
+    mute_int.mode(PullUp);                  // pin 11 on LPC1114
+    rc5dat.mode(PullUp);                // pin 15
+    sela.mode(PullUp);                  // pin 28
+    selb.mode(PullUp);                  // pin 27
+    stdby.mode(PullUp);                 // pin 26
+    recloop_in.mode(PullUp);            // pin 15
+    //TXD.mode(PullUp);                 // pin 16
+    
+    
+    //muteind = LOW;
     muteout = LOW;                      // mute the output while we go through  power-up sequence
-    recloop_out = LOW;                  // make sure initial recloop condition is delected
+    recloop_out = HIGH;                  // make sure initial recloop condition is delected - this is open drain O/PO
     //power_ind = LOW;                    // power control; HIGH = power up
-    wait(.2);
-    //Serial pc(USBTX, USBRX);            // for debuging only - comment out on production
+    //wait(.2);
+    //Serial pc(USBTX, USBRX);           // for debuging only - comment out on production
     FLAG1 = FALSE;
     FLAG2 = FALSE;
-    FWD1=0;
-  //  FWD2=0;
+    FWD1=0;                             //make sure the volume control motor is OFF
     REV1=0;
-  //  REV2=0;                            //make sure the volume control motor is OFF
+                              
 
                                         // set up the ISR's we will be using
     rc5int.rise(&rc5isr);               // trigger int on rising edge - go service it at rc5dat
@@ -384,19 +399,21 @@
     mute_int.fall(NULL);
     recloop_int.fall(NULL);
 
-//printf("diable ISR\n");
+//printf("disable 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 = 2;                    // CD will be selected when power is first turned on
-    muteind = HIGH;                    
+    //muteind = HIGH;                    
     __enable_irq();
 
 
     // all ready and in standby from this point forward
 
 LOOP:                                   // this is the main operating loop
-//printf("WFI\n");
+
+
+//printf("WFI . . . . %i\n\r", loop_counter);
     __WFI();                            // wait here until interrupt
 
     if (FLAG1 == TRUE) {                // FLAG1 indicates remote control was used
@@ -422,15 +439,16 @@
         FLAG3 = FALSE;
         __enable_irq();
     }
-//printf("B4stdby\n");
+//printf("B4stdby\n\r");
     if (FLAG4 == TRUE) {
         __disable_irq();
         standby_out(); 
-                                        // standby
-        FLAG4 = FALSE;
-// printf("back from isr\n"); 
-        __enable_irq();
-        //printf("renable isr\n");   
+       FLAG4 = FALSE;
+        __enable_irq();                                // standby
+        
+// printf("back from isr\n\r"); 
+        //__enable_irq();
+//printf("re-enable isr straight after back from standby\n\r");   
     }
 //printf("finished with STBY\n");
     if (FLAG5 == TRUE) {
@@ -440,11 +458,13 @@
         __enable_irq();
     }
 
-    wait_us(5);
-//printf("loop to WFI\n");
+   wait_us(5);
+//printf("loop to WFI\n\r");
+//    loop_counter++;
     goto LOOP;
 
 }
 
 
 
+