Created
December 17, 2014 07:58
-
-
Save jitomesky/6290350861746bb4f2c3 to your computer and use it in GitHub Desktop.
mbed LPC1768でRTCの割り込みで1秒間隔でLチカするコードサンプル
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "mbed.h" | |
DigitalOut myled(LED1); | |
void led_blink(void){ | |
static int led = 0; | |
led = !led; | |
myled = led; | |
} | |
void rtc_irq_handler(void){ | |
__disable_irq(); | |
// reset Interrupt flag | |
LPC_RTC->ILR |= 0x01; | |
// RTCの未解決フラグを下ろす | |
NVIC_ClearPendingIRQ(RTC_IRQn); | |
led_blink(); | |
__enable_irq(); | |
} | |
int main() { | |
// RTCで1秒毎に割り込みを入れてLEDを点滅させる | |
// Ensure power is on | |
// 9: PCRTC | |
LPC_SC->PCONP |= 0x01 << 9; | |
// CTCRST: internal oscillator divider reset | |
LPC_RTC->CCR = 0x01; | |
// RTCCIF: Counter Increment Interrupt reset | |
LPC_RTC->ILR |= 0x01; | |
//IMSEC: When 1, an increment of the Second value generates an interrupt. | |
LPC_RTC->CIIR |= 0x01; | |
NVIC_SetVector(RTC_IRQn, (uint32_t)rtc_irq_handler); | |
NVIC_SetPriority(RTC_IRQn,0); | |
NVIC_EnableIRQ(RTC_IRQn); | |
while(1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment