led example with 2 timers

Dependencies:   mbed mbed-rtos

Revision:
4:af325c921e79
Parent:
2:124a066878cc
Child:
5:726d7857fd33
--- a/receiver.cpp	Tue Feb 11 06:37:34 2014 +0000
+++ b/receiver.cpp	Tue Feb 11 20:38:43 2014 +0000
@@ -2,43 +2,32 @@
 
 extern Serial pc;
 DigitalOut myled2(LED2);
-volatile unsigned short timer1_count;
+
 
 void Receiver_init(void)
 {
     myled2 = 0;
     
-    LPC_SC->PCONP |=1<<2;            //timer1 power on
-    LPC_TIM1->MR0 = 2398000;        //100 msec
-    LPC_TIM1->MCR = 3;              //interrupt and reset control
+    LPC_SC->PCONP |=1<<22;            //timer1 power on
+    LPC_TIM2->MR0 = 2398000;        //100 msec
+    LPC_TIM2->MCR = 3;              //interrupt and reset control
                                     //3 = Interrupt & reset timer1 on match
                                     //1 = Interrupt only, no reset of timer0
-    NVIC_EnableIRQ(TIMER1_IRQn);    //enable timer1 interrupt
-    LPC_TIM1->TCR = 1;              //enable Timer1
-    //pc.printf("Done timer1_init\n\r");
+    NVIC_EnableIRQ(TIMER2_IRQn);    //enable timer1 interrupt
+    LPC_TIM2->TCR = 1;              //enable Timer1
 }
 
-extern "C"  void TIMER1_IRQHandler (void)
+extern "C"  void TIMER2_IRQHandler (void)
 {
-if((LPC_TIM1->IR & 0x01) == 0x01)   // if MR0 interrupt, proceed
+
+
+    if((LPC_TIM2->IR & 0x01) == 0x01)   // if MR0 interrupt, proceed
     {
-    LPC_TIM1->IR |= 1 << 0;         // Clear MR0 interrupt flag
-    timer1_count++;                  //increment timer_count
+        LPC_TIM2->IR |= 1 << 0;         // Clear MR0 interrupt flag
     
-   // pc.printf("timer1_count %d \n\r", timer1_count);
-    if (timer1_count >= 20)      //Set timer_count for about 8 seconds
-            {
-            if (myled2 == 1)             //If LED off, turn it on &
-                {
-                myled2 = 0;
-                timer1_count = 0;        //reset count
-                }
-            else
-                {
-                myled2 = 1;              //If LED on, turn it off &
-                timer1_count = 0;        //reset count
-                }
-            }
+        
+        myled2 =!myled2;
+    
     }
 }