APP 4

Dependencies:   mbed CRC16 mbed-rtos

Revision:
8:60499583959f
Parent:
7:733d500dbe5c
Parent:
6:3181f546e812
Child:
9:b937f9c6d682
Child:
10:51ee22e230c7
--- a/APP.cpp	Sun Feb 21 18:50:45 2016 +0000
+++ b/APP.cpp	Sun Feb 21 18:58:52 2016 +0000
@@ -2,9 +2,10 @@
 #include "Manchester.h"
 
 Serial pc(USBTX, USBRX);
+DigitalIn in(p9);
 
-bool messageReady = false;
-bitset<2 * FRAMESIZE> message;
+bool clockTick = false;
+bitset<FRAMESIZE> message(string("1000111011110101011100000000000111011010101001111111011110011010"));
 int counter = 0;
 
 int benchmark(void (*function) (void))
@@ -19,14 +20,17 @@
     if ((LPC_TIM2->IR & 0x01) == 0x01) // if MR0 interrupt, proceed
     {
         LPC_TIM2->IR |= 1 << 0;        // Clear MR0 interrupt flag
-        
-        if (messageReady)
+        clockTick = !clockTick;
+        LPC_TIM2->EMR = encode(message[counter], clockTick);
+
+        if (clockTick)
         {
-            LPC_TIM2->EMR = ((message[counter++] + 1) << 4);
+            counter++;
         }
-        else
+
+        if (counter >= FRAMESIZE)
         {
-            LPC_TIM2->EMR = (1 << 4);   // output 0
+            counter = 0;
         }
     }
 }
@@ -36,30 +40,32 @@
     //Timer 2 (match)
     LPC_SC->PCLKSEL1 |= (1 << 12);     // pclk = cclk timer2
     LPC_SC->PCONP |= (1 << 22);        // timer2 power on
-    LPC_TIM2->MR0 = 9600000;           // 100 ms
+    LPC_TIM2->MR0 = CLOCKS_TO_SECOND / 10;           // 100 ms
     LPC_TIM2->MCR = 3;                 // interrupt and reset control
                                        // Interrupt & reset timer2 on match
+    LPC_TIM2->EMR = (2 << 4);              // toggle
     NVIC_EnableIRQ(TIMER2_IRQn);       // enable timer2 interrupt
     LPC_TIM2->TCR = 1;                 // enable Timer2
     
     //Timer 1 (cap)
     LPC_SC->PCLKSEL1 |= (1 << 4);     // pclk = cclk timer2
     LPC_SC->PCONP |= (1 << 2);        // timer1 power on
-    LPC_TIM1->MR0 = 9600000;           // 100 ms
+    LPC_TIM1->MR0 = CLOCKS_TO_SECOND / 10;           // 100 ms
     LPC_TIM1->MCR = 3;                 // interrupt and reset control
                                        // Interrupt & reset timer1 on match
     NVIC_EnableIRQ(TIMER1_IRQn);       // enable timer1 interrupt
     LPC_TIM1->TCR = 1;                 // enable Timer1
+
 }
 
 int main()
 {
     LPC_PINCON->PINSEL0 |= (3 << 12);  // P0.6 = MAT2.0
-
-    initTimer();
+    initTimers();
 
     while (true)
     {
-        wait(1.0);
+        pc.printf("%i", decode(in.read(), clockTick));
+        wait(0.2);
     }
 }