Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 // Example to set up an interrupt based on the LPC TIMER0 match register, sford 00002 00003 #include "mbed.h" 00004 00005 DigitalOut myled(LED1); 00006 DigitalOut irqled(LED2); 00007 00008 void myhandler() { 00009 // do something! 00010 irqled = !irqled; 00011 00012 // clear the TIMER0 interrupt 00013 LPC_TIM0->IR = 1; 00014 } 00015 00016 int main() { 00017 // power up TIMER0 (PCONP[1]) 00018 LPC_SC->PCONP |= 1 << 1; 00019 00020 // reset and set TIMER0 to timer mode 00021 LPC_TIM0->TCR = 0x2; 00022 LPC_TIM0->CTCR = 0x0; 00023 00024 // set no prescaler 00025 LPC_TIM0->PR = 0; 00026 00027 // calculate period (1 interrupt every second) 00028 uint32_t period = SystemCoreClock / 4; 00029 00030 // set match register and enable interrupt 00031 LPC_TIM0->MR0 = period; 00032 LPC_TIM0->MCR |= 1 << 0; // interrupt on match 00033 LPC_TIM0->MCR |= 1 << 1; // reset on match 00034 00035 // enable the vector in the interrupt controller 00036 NVIC_SetVector(TIMER0_IRQn, (uint32_t)&myhandler); 00037 NVIC_EnableIRQ(TIMER0_IRQn); 00038 00039 // start the timer 00040 LPC_TIM0->TCR = 1; 00041 00042 // hang around! 00043 while(1) { 00044 myled = 1; 00045 wait(0.2); 00046 myled = 0; 00047 wait(0.2); 00048 } 00049 }
Generated on Tue Jul 12 2022 21:34:46 by
1.7.2