APP 4

Dependencies:   mbed CRC16 mbed-rtos

Committer:
vinbel93
Date:
Sat Feb 20 19:14:36 2016 +0000
Revision:
1:f212b6676849
Parent:
APP_match.cpp@0:ac5e42371639
Child:
2:1250280a511b
initial structure

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vinbel93 0:ac5e42371639 1 #include "mbed.h"
vinbel93 0:ac5e42371639 2 #include "LPC17xx.h"
vinbel93 0:ac5e42371639 3
vinbel93 0:ac5e42371639 4 #define CLOCKS_TO_SECOND 96000000
vinbel93 0:ac5e42371639 5
vinbel93 0:ac5e42371639 6 Serial pc(USBTX, USBRX);
vinbel93 0:ac5e42371639 7
vinbel93 0:ac5e42371639 8 int state = 0;
vinbel93 0:ac5e42371639 9 float tempsHaut = 0.4;
vinbel93 0:ac5e42371639 10 float tempsBas = 0.1;
vinbel93 0:ac5e42371639 11
vinbel93 1:f212b6676849 12 int benchmark(void (*function) (void))
vinbel93 0:ac5e42371639 13 {
vinbel93 0:ac5e42371639 14 int counter = LPC_TIM2->TC;
vinbel93 0:ac5e42371639 15 function();
vinbel93 0:ac5e42371639 16 return LPC_TIM2->TC - counter;
vinbel93 0:ac5e42371639 17 }
vinbel93 0:ac5e42371639 18
vinbel93 1:f212b6676849 19 extern "C" void TIMER2_IRQHandler()
vinbel93 0:ac5e42371639 20 {
vinbel93 0:ac5e42371639 21 if ((LPC_TIM2->IR & 0x01) == 0x01) // if MR0 interrupt, proceed
vinbel93 0:ac5e42371639 22 {
vinbel93 0:ac5e42371639 23 if (state == 0)
vinbel93 0:ac5e42371639 24 {
vinbel93 0:ac5e42371639 25 state = 1;
vinbel93 0:ac5e42371639 26 LPC_TIM2->MR0 = (int) CLOCKS_TO_SECOND * tempsHaut;
vinbel93 0:ac5e42371639 27 }
vinbel93 0:ac5e42371639 28 else if (state == 1)
vinbel93 0:ac5e42371639 29 {
vinbel93 0:ac5e42371639 30 state = 0;
vinbel93 0:ac5e42371639 31 LPC_TIM2->MR0 = (int) CLOCKS_TO_SECOND * tempsBas;
vinbel93 0:ac5e42371639 32 }
vinbel93 0:ac5e42371639 33
vinbel93 0:ac5e42371639 34 LPC_TIM2->IR |= 1 << 0; // Clear MR0 interrupt flag
vinbel93 0:ac5e42371639 35 }
vinbel93 0:ac5e42371639 36 }
vinbel93 0:ac5e42371639 37
vinbel93 1:f212b6676849 38 void initTimer()
vinbel93 0:ac5e42371639 39 {
vinbel93 0:ac5e42371639 40 LPC_SC->PCLKSEL1 |= (1 << 12); // pclk = cclk timer2
vinbel93 0:ac5e42371639 41 LPC_SC->PCONP |= (1 << 22); // timer2 power on
vinbel93 0:ac5e42371639 42 LPC_TIM2->MR0 = 9600000; // 100 msec
vinbel93 0:ac5e42371639 43 LPC_TIM2->MCR = 1; // interrupt and reset control
vinbel93 0:ac5e42371639 44 // 3 = Interrupt & reset timer2 on match
vinbel93 0:ac5e42371639 45 // 1 = Interrupt only, no reset of timer0
vinbel93 0:ac5e42371639 46 LPC_TIM2->EMR = (3 << 4); // EMC0 = 11 (Toogle)
vinbel93 0:ac5e42371639 47 NVIC_EnableIRQ(TIMER2_IRQn); // enable timer2 interrupt
vinbel93 0:ac5e42371639 48 LPC_TIM2->TCR = 1; // enable Timer2
vinbel93 0:ac5e42371639 49 }
vinbel93 0:ac5e42371639 50
vinbel93 1:f212b6676849 51 int main()
vinbel93 0:ac5e42371639 52 {
vinbel93 0:ac5e42371639 53 LPC_PINCON->PINSEL0 |= (3 << 12); // P0.6 = MAT2.0
vinbel93 0:ac5e42371639 54
vinbel93 1:f212b6676849 55 initTimer();
vinbel93 0:ac5e42371639 56
vinbel93 0:ac5e42371639 57 while(1)
vinbel93 0:ac5e42371639 58 {
vinbel93 0:ac5e42371639 59 wait(1.0);
vinbel93 0:ac5e42371639 60 }
vinbel93 0:ac5e42371639 61 }