APP Team
/
app3
led example with 2 timers
demodulator.cpp@1:6e31c704f4d6, 2014-02-10 (annotated)
- Committer:
- passelin
- Date:
- Mon Feb 10 16:33:35 2014 +0000
- Revision:
- 1:6e31c704f4d6
- Child:
- 2:124a066878cc
in progress..
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
passelin | 1:6e31c704f4d6 | 1 | #include "main.h" |
passelin | 1:6e31c704f4d6 | 2 | |
passelin | 1:6e31c704f4d6 | 3 | extern Serial pc; |
passelin | 1:6e31c704f4d6 | 4 | DigitalOut myled2(LED2); |
passelin | 1:6e31c704f4d6 | 5 | volatile unsigned short timer1_count; |
passelin | 1:6e31c704f4d6 | 6 | |
passelin | 1:6e31c704f4d6 | 7 | void Demodulator_init(void) |
passelin | 1:6e31c704f4d6 | 8 | { |
passelin | 1:6e31c704f4d6 | 9 | myled2 = 0; |
passelin | 1:6e31c704f4d6 | 10 | |
passelin | 1:6e31c704f4d6 | 11 | LPC_SC->PCONP |=1<<2; //timer1 power on |
passelin | 1:6e31c704f4d6 | 12 | LPC_TIM1->MR0 = 2398000; //100 msec |
passelin | 1:6e31c704f4d6 | 13 | LPC_TIM1->MCR = 3; //interrupt and reset control |
passelin | 1:6e31c704f4d6 | 14 | //3 = Interrupt & reset timer1 on match |
passelin | 1:6e31c704f4d6 | 15 | //1 = Interrupt only, no reset of timer0 |
passelin | 1:6e31c704f4d6 | 16 | NVIC_EnableIRQ(TIMER1_IRQn); //enable timer1 interrupt |
passelin | 1:6e31c704f4d6 | 17 | LPC_TIM1->TCR = 1; //enable Timer1 |
passelin | 1:6e31c704f4d6 | 18 | pc.printf("Done timer1_init\n\r"); |
passelin | 1:6e31c704f4d6 | 19 | } |
passelin | 1:6e31c704f4d6 | 20 | |
passelin | 1:6e31c704f4d6 | 21 | extern "C" void TIMER1_IRQHandler (void) |
passelin | 1:6e31c704f4d6 | 22 | { |
passelin | 1:6e31c704f4d6 | 23 | if((LPC_TIM1->IR & 0x01) == 0x01) // if MR0 interrupt, proceed |
passelin | 1:6e31c704f4d6 | 24 | { |
passelin | 1:6e31c704f4d6 | 25 | LPC_TIM1->IR |= 1 << 0; // Clear MR0 interrupt flag |
passelin | 1:6e31c704f4d6 | 26 | timer1_count++; //increment timer_count |
passelin | 1:6e31c704f4d6 | 27 | |
passelin | 1:6e31c704f4d6 | 28 | // pc.printf("timer1_count %d \n\r", timer1_count); |
passelin | 1:6e31c704f4d6 | 29 | if (timer1_count >= 20) //Set timer_count for about 8 seconds |
passelin | 1:6e31c704f4d6 | 30 | { |
passelin | 1:6e31c704f4d6 | 31 | if (myled2 == 1) //If LED off, turn it on & |
passelin | 1:6e31c704f4d6 | 32 | { |
passelin | 1:6e31c704f4d6 | 33 | myled2 = 0; |
passelin | 1:6e31c704f4d6 | 34 | timer1_count = 0; //reset count |
passelin | 1:6e31c704f4d6 | 35 | } |
passelin | 1:6e31c704f4d6 | 36 | else |
passelin | 1:6e31c704f4d6 | 37 | { |
passelin | 1:6e31c704f4d6 | 38 | myled2 = 1; //If LED on, turn it off & |
passelin | 1:6e31c704f4d6 | 39 | timer1_count = 0; //reset count |
passelin | 1:6e31c704f4d6 | 40 | } |
passelin | 1:6e31c704f4d6 | 41 | } |
passelin | 1:6e31c704f4d6 | 42 | } |
passelin | 1:6e31c704f4d6 | 43 | } |
passelin | 1:6e31c704f4d6 | 44 | |
passelin | 1:6e31c704f4d6 | 45 | void Demodulator_thread(void const *args) |
passelin | 1:6e31c704f4d6 | 46 | { |
passelin | 1:6e31c704f4d6 | 47 | Demodulator_init(); |
passelin | 1:6e31c704f4d6 | 48 | |
passelin | 1:6e31c704f4d6 | 49 | while(1) |
passelin | 1:6e31c704f4d6 | 50 | { |
passelin | 1:6e31c704f4d6 | 51 | // wait forever... |
passelin | 1:6e31c704f4d6 | 52 | } |
passelin | 1:6e31c704f4d6 | 53 | } |