APP 4
Dependencies: mbed CRC16 mbed-rtos
APP.cpp
- Committer:
- vinbel93
- Date:
- 2016-02-21
- Revision:
- 6:3181f546e812
- Parent:
- 3:3ffa14e75b8a
- Child:
- 8:60499583959f
File content as of revision 6:3181f546e812:
#include "APP.h" #include "Manchester.h" Serial pc(USBTX, USBRX); DigitalIn in(p9); bool clockTick = false; bitset<FRAMESIZE> message(string("1000111011110101011100000000000111011010101001111111011110011010")); int counter = 0; int benchmark(void (*function) (void)) { int count = LPC_TIM2->TC; function(); return LPC_TIM2->TC - count; } extern "C" void TIMER2_IRQHandler() { if ((LPC_TIM2->IR & 0x01) == 0x01) // if MR0 interrupt, proceed { LPC_TIM2->IR |= 1 << 0; // Clear MR0 interrupt flag clockTick = !clockTick; LPC_TIM2->EMR = encode(message[counter], clockTick); if (clockTick) { counter++; } if (counter >= FRAMESIZE) { counter = 0; } } } void initTimer() { LPC_SC->PCLKSEL1 |= (1 << 12); // pclk = cclk timer2 LPC_SC->PCONP |= (1 << 22); // timer2 power on LPC_TIM2->MR0 = CLOCKS_TO_SECOND / 10; // 100 ms LPC_TIM2->MCR = 3; // interrupt & reset timer2 on match LPC_TIM2->EMR = (3 << 4); // toggle NVIC_EnableIRQ(TIMER2_IRQn); // enable timer2 interrupt LPC_TIM2->TCR = 1; // enable timer2 } int main() { LPC_PINCON->PINSEL0 |= (3 << 12); // P0.6 = MAT2.0 initTimer(); while (true) { pc.printf("%i", decode(in.read(), clockTick)); wait(0.2); } }