app3 prob

Dependencies:   mbed

Revision:
0:6517bada7928
Child:
1:cb05875a0960
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Feb 07 20:16:21 2014 +0000
@@ -0,0 +1,81 @@
+#include "mbed.h"
+
+Serial pc(USBTX, USBRX);
+DigitalIn in(p29);
+
+bool trame[16] = {false, true, false, true, true, true, true, false, false, false, true, false, false, true, true, true};
+
+void ThatsTheSpirit() {
+    
+    pc.printf("Duree impulsion : %d microsecondes.\n\r", LPC_TIM2->CR1/(SystemCoreClock/1000000));
+    
+    LPC_TIM2->TC = 0;
+    LPC_TIM2->PC = 0;
+    LPC_TIM2->PR = 0;
+    LPC_TIM2->IR = 0xFF;
+}
+
+void SendMessage() {
+    
+    LPC_SC->PCONP |= (1 << 6);      // Enable power on PWM1
+    LPC_SC->PCLKSEL0 |= (3 << 12);  // Run PWM1
+    
+    LPC_PINCON->PINSEL4 |= (1 << 2);
+    LPC_PINCON->PINMODE3 |= (2 << 14) | (2 << 8);
+    
+    LPC_PWM1->MCR |= (0 << 8) | ( 0 << 7) | (0 << 6) | (1 << 1);
+    LPC_PWM1->CTCR |= (0 << 0);
+    LPC_PWM1->PCR |= (1 << 12) | (1 << 10) | (1 << 4) | (1 << 2);
+    
+    LPC_PWM1->MR0 = SystemCoreClock/8;
+    LPC_PWM1->LER |= (0x6);
+    LPC_PWM1->TCR |= (0x9);
+    
+    for (int a = 0; a < 16; a++) {
+        if (trame[a]) {
+            LPC_PWM1->MR1 = 0;
+            LPC_PWM1->MR2 = SystemCoreClock/16;
+        } else {
+            LPC_PWM1->MR1 = SystemCoreClock/16;
+            LPC_PWM1->MR2 = 0;
+        }
+        
+        pc.printf("trame: %d\n\r", trame[a]);
+        
+        wait(1);
+    }
+}
+
+int main() {
+    
+    SendMessage();
+    
+    /*LPC_PINCON->PINSEL0 |= 0xF00;
+    NVIC_SetVector(TIMER2_IRQn, uint32_t(ThatsTheSpirit));
+    
+    LPC_SC->PCONP |= (1 << 22);
+    LPC_SC->PCLKSEL1 |= (1 << 12);
+    
+    
+    LPC_TIM2->TC = 0;       // Initialise Time Counter
+    LPC_TIM2->PC = 0;       // Initialise Prescale Counter
+    LPC_TIM2->PR = 0;       // Initialise Prescale Register
+    LPC_TIM2->TCR = 0x02;   // Reset Timer Control Register
+    LPC_TIM2->IR = 0xFF;    // Initialise Interrupt Register
+    LPC_TIM2->CCR |= 0x29;  // Initialise Capture Control Register
+    
+    LPC_TIM2->TCR = 0x01;   // Start Timer Control Register
+    
+    while(1) {
+        
+        while (in.read() == 0);
+        
+        NVIC_EnableIRQ(TIMER2_IRQn);
+        NVIC_DisableIRQ(TIMER2_IRQn);
+        
+        while (in.read() == 1);
+        
+        NVIC_EnableIRQ(TIMER2_IRQn);
+        NVIC_DisableIRQ(TIMER2_IRQn);
+    }*/
+}