APP3 / Mbed 2 deprecated APP4

Dependencies:   mbed mbed-rtos

Committer:
ShaolinPoutine
Date:
Sat Mar 04 18:40:17 2017 +0000
Revision:
1:8b93b2102ac5
Parent:
0:529210499c6d
Child:
2:1665cd4c922c
Separation of mains

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ShaolinPoutine 0:529210499c6d 1 #include "mbed.h"
ShaolinPoutine 1:8b93b2102ac5 2 #define clock_max 96000000
ShaolinPoutine 0:529210499c6d 3
ShaolinPoutine 0:529210499c6d 4 DigitalOut myled(LED1);
ShaolinPoutine 0:529210499c6d 5
ShaolinPoutine 1:8b93b2102ac5 6 extern "C" void TIMER2_IRQHandler (void)
ShaolinPoutine 1:8b93b2102ac5 7 {
ShaolinPoutine 1:8b93b2102ac5 8 if((LPC_TIM2->IR & 0x01) == 0x01) // if MR0 interrupt, proceed
ShaolinPoutine 1:8b93b2102ac5 9 {
ShaolinPoutine 1:8b93b2102ac5 10 LPC_TIM2->IR |= 1 << 0; // Clear MR0 interrupt flag
ShaolinPoutine 0:529210499c6d 11 }
ShaolinPoutine 0:529210499c6d 12 }
ShaolinPoutine 1:8b93b2102ac5 13
ShaolinPoutine 1:8b93b2102ac5 14 void init_clk()
ShaolinPoutine 1:8b93b2102ac5 15 {
ShaolinPoutine 1:8b93b2102ac5 16 LPC_PINCON->PINSEL0 |=3<<12; //P0.6 = MAT2.0 // p8
ShaolinPoutine 1:8b93b2102ac5 17 LPC_SC->PCLKSEL1 |=1<<12; //pclk timer2 = cclk
ShaolinPoutine 1:8b93b2102ac5 18 LPC_SC->PCONP |=1<<22; //timer2 power on
ShaolinPoutine 1:8b93b2102ac5 19 LPC_TIM2->MR0 = clock_max / 2; // 1 sec period
ShaolinPoutine 1:8b93b2102ac5 20 LPC_TIM2->MCR = 3; //interrupt and reset control
ShaolinPoutine 1:8b93b2102ac5 21 //3 = Interrupt & reset timer2 on match
ShaolinPoutine 1:8b93b2102ac5 22 //1 = Interrupt only, no reset of timer0
ShaolinPoutine 1:8b93b2102ac5 23 LPC_TIM2->EMR =3<<4; //EMC0 = 11 (Toogle)
ShaolinPoutine 1:8b93b2102ac5 24 NVIC_EnableIRQ(TIMER2_IRQn); //enable timer2 interrupt
ShaolinPoutine 1:8b93b2102ac5 25 LPC_TIM2->TCR = 1; //enable Timer2
ShaolinPoutine 1:8b93b2102ac5 26 }
ShaolinPoutine 1:8b93b2102ac5 27
ShaolinPoutine 1:8b93b2102ac5 28 int mainRaph()
ShaolinPoutine 1:8b93b2102ac5 29 {
ShaolinPoutine 1:8b93b2102ac5 30 init_clk();
ShaolinPoutine 1:8b93b2102ac5 31 }
ShaolinPoutine 1:8b93b2102ac5 32
ShaolinPoutine 1:8b93b2102ac5 33 void tick()
ShaolinPoutine 1:8b93b2102ac5 34 {
ShaolinPoutine 1:8b93b2102ac5 35 myled = !myled;
ShaolinPoutine 1:8b93b2102ac5 36 }
ShaolinPoutine 1:8b93b2102ac5 37 int main() {
ShaolinPoutine 1:8b93b2102ac5 38 Ticker ticker;
ShaolinPoutine 1:8b93b2102ac5 39 ticker.attach(&tick, 0.5);
ShaolinPoutine 1:8b93b2102ac5 40 }