![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
led example with 2 timers
Diff: main.cpp
- Revision:
- 1:6e31c704f4d6
- Parent:
- 0:11dd239703cc
- Child:
- 2:124a066878cc
--- a/main.cpp Fri Feb 07 19:55:57 2014 +0000 +++ b/main.cpp Mon Feb 10 16:33:35 2014 +0000 @@ -1,94 +1,21 @@ -#include "mbed.h" +#include "main.h" InterruptIn signal(p15); Serial pc(USBTX,USBRX); - -DigitalOut myled(LED1); -DigitalOut myled2(LED2); -volatile unsigned short timer_count, timer1_count; - -extern "C" void TIMER0_IRQHandler (void) -{ -if((LPC_TIM0->IR & 0x01) == 0x01) // if MR0 interrupt, proceed - { - LPC_TIM0->IR |= 1 << 0; // Clear MR0 interrupt flag - timer_count++; //increment timer_count - - // pc.printf("timer_count %d \n\r", timer_count); - if (timer_count >= 80) //Set timer_count for about 8 seconds - { - if (myled == 1) //If LED off, turn it on & - { - myled = 0; - timer_count = 0; //reset count - } - else - { - myled = 1; //If LED on, turn it off & - timer_count = 0; //reset count - } - } - } -} -extern "C" void TIMER1_IRQHandler (void) -{ -if((LPC_TIM1->IR & 0x01) == 0x01) // if MR0 interrupt, proceed - { - LPC_TIM1->IR |= 1 << 0; // Clear MR0 interrupt flag - timer1_count++; //increment timer_count - - // pc.printf("timer1_count %d \n\r", timer1_count); - if (timer1_count >= 20) //Set timer_count for about 8 seconds - { - if (myled2 == 1) //If LED off, turn it on & - { - myled2 = 0; - timer1_count = 0; //reset count - } - else - { - myled2 = 1; //If LED on, turn it off & - timer1_count = 0; //reset count - } - } - } -} - -void timer0_init(void) -{ - LPC_SC->PCONP |=1<1; //timer0 power on - LPC_TIM0->MR0 = 2398000; //100 msec - LPC_TIM0->MCR = 3; //interrupt and reset control - //3 = Interrupt & reset timer0 on match - //1 = Interrupt only, no reset of timer0 - NVIC_EnableIRQ(TIMER0_IRQn); //enable timer0 interrupt - LPC_TIM0->TCR = 1; //enable Timer0 - pc.printf("Done timer0_init\n\r"); -} +Queue<char, 16> ReaderQueue; -void timer1_init(void) -{ - LPC_SC->PCONP |=1<<2; //timer1 power on - LPC_TIM1->MR0 = 2398000; //100 msec - LPC_TIM1->MCR = 3; //interrupt and reset control - //3 = Interrupt & reset timer1 on match - //1 = Interrupt only, no reset of timer0 - NVIC_EnableIRQ(TIMER1_IRQn); //enable timer1 interrupt - LPC_TIM1->TCR = 1; //enable Timer1 - pc.printf("Done timer1_init\n\r"); -} - - int main (void) { - myled = 0; - myled2 = 0; - timer0_init(); - timer1_init(); + Thread thread1(Writer_thread); + Thread thread2(Reader_thread); + Thread thread3(Modulator_thread); + Thread thread4(Demodulator_thread); + Thread thread5(Sender_thread); + Thread thread6(Receiver_thread); while(1) { - + // wait forever... } } \ No newline at end of file