APP3 / Mbed 2 deprecated APP4

Dependencies:   mbed mbed-rtos

Revision:
1:8b93b2102ac5
Parent:
0:529210499c6d
Child:
2:1665cd4c922c
--- a/main.cpp	Thu Mar 02 19:38:47 2017 +0000
+++ b/main.cpp	Sat Mar 04 18:40:17 2017 +0000
@@ -1,12 +1,40 @@
 #include "mbed.h"
+#define clock_max 96000000
 
 DigitalOut myled(LED1);
 
-int main() {
-    while(1) {
-        myled = 1;
-        wait(0.2);
-        myled = 0;
-        wait(0.2);
+extern "C" void TIMER2_IRQHandler (void)
+{
+if((LPC_TIM2->IR & 0x01) == 0x01)   // if MR0 interrupt, proceed
+    {
+        LPC_TIM2->IR |= 1 << 0;         // Clear MR0 interrupt flag
     }
 }
+
+void init_clk()
+{
+    LPC_PINCON->PINSEL0 |=3<<12;            //P0.6 = MAT2.0  // p8
+    LPC_SC->PCLKSEL1 |=1<<12;               //pclk timer2 = cclk 
+    LPC_SC->PCONP |=1<<22;                  //timer2 power on
+    LPC_TIM2->MR0 = clock_max / 2;          // 1 sec period
+    LPC_TIM2->MCR = 3;                      //interrupt and reset control
+                                            //3 = Interrupt & reset timer2 on match
+                                            //1 = Interrupt only, no reset of timer0
+    LPC_TIM2->EMR =3<<4;                    //EMC0 = 11 (Toogle)
+    NVIC_EnableIRQ(TIMER2_IRQn);            //enable timer2 interrupt
+    LPC_TIM2->TCR = 1;                      //enable Timer2
+}
+
+int mainRaph()
+{
+    init_clk();
+}
+
+void tick()
+{
+    myled = !myled;   
+}
+int main() {
+    Ticker ticker;
+    ticker.attach(&tick, 0.5);
+}