TimerInterruptExample
Published 09 Feb 2010, by
Simon Ford

No tags
« Back to documentation index
Show/hide line numbers
main.cpp Source File
main.cpp
00001
00002
00003 #include "mbed.h"
00004
00005 DigitalOut myled(LED1);
00006 DigitalOut irqled(LED2);
00007
00008 void myhandler() {
00009
00010 irqled = !irqled;
00011
00012
00013 LPC_TIM0->IR = 1;
00014 }
00015
00016 int main() {
00017
00018 LPC_SC->PCONP |= 1 << 1;
00019
00020
00021 LPC_TIM0->TCR = 0x2;
00022 LPC_TIM0->CTCR = 0x0;
00023
00024
00025 LPC_TIM0->PR = 0;
00026
00027
00028 uint32_t period = SystemCoreClock / 4;
00029
00030
00031 LPC_TIM0->MR0 = period;
00032 LPC_TIM0->MCR |= 1 << 0;
00033 LPC_TIM0->MCR |= 1 << 1;
00034
00035
00036 NVIC_SetVector(TIMER0_IRQn, (uint32_t)&myhandler);
00037 NVIC_EnableIRQ(TIMER0_IRQn);
00038
00039
00040 LPC_TIM0->TCR = 1;
00041
00042
00043 while(1) {
00044 myled = 1;
00045 wait(0.2);
00046 myled = 0;
00047 wait(0.2);
00048 }
00049 }