For NTHU_Racing MCU tutorial Learn to use timer inturrupt
Dependencies: mbed
Diff: sample_timebase.cpp
- Revision:
- 1:5968363c5d23
- Parent:
- 0:d68e088dfbcd
--- a/sample_timebase.cpp Fri Jul 15 09:14:36 2016 +0000 +++ b/sample_timebase.cpp Thu Jan 19 07:42:30 2017 +0000 @@ -2,20 +2,20 @@ //~~~~~~~~~~~~~~~~~~~~~~~~~~~GPIO registor~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// DigitalOut led = D13; //link leg -DigitalOut TT_main_ext = D12; //linl leg //~~~~~~~~~~~~~~~~~~~~~~~~~~~end of GPIO registor~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// //~~~~~~~~~~~~~~~~~~~~~~~~~~~Varible registor~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// -Ticker TT; //call a timer -int count = 0; //one second counter for extrenal led blink +Ticker TT1; //call a timer +Ticker TT2; //call a timer //~~~~~~~~~~~~~~~~~~~~~~~~~~~end of Varible registor~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// //~~~~~~~~~~~~~~~~~~~~~~~~~~~Function registor~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// void init_IO(); //initialize IO state void init_TIMER(); //set TT_main{} rate -void TT_main(); //timebase function rated by TT +void TT1_main(); //timebase function rated by TT1 +void TT2_main(); //timebase function rated by TT2 //~~~~~~~~~~~~~~~~~~~~~~~~~~~end of Function registor~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// @@ -23,42 +23,37 @@ int main() { init_IO(); //initialized value - init_TIMER(); //start TT_main + init_TIMER(); //initialized Timer Inturrupt rate while(1) { //main() loop - if(count >= 1000) { //check if main working - count=0; - led = !led; - } - } } //~~~~~~~~~~~~~~~~~~~~~~~~~~~end of main funtion~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// - - - - //~~~~~~~~~~~~~~~~~~~~~~~~~~~init_IO funtion~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// void init_IO(void) //initialize { led = 1; - TT_main_ext = 1; } //~~~~~~~~~~~~~~~~~~~~~~~~~~~end of init_IO funtion~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// //~~~~~~~~~~~~~~~~~~~~~~~~~~~Timebase funtion~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// -void init_TIMER() //set TT_main{} rate +void init_TIMER() //set TTx_main{} rate { - TT.attach_us(&TT_main, 1000); + TT1.attach_us(&TT1_main, 1000); + TT2.attach_us(&TT2_main, 1010); } -void TT_main() //interrupt function by TT +void TT1_main() //interrupt function by TT1 { - TT_main_ext = !TT_main_ext; //indicate TT_main() function working - count = count+1; //one second counter + led = !led; +} + + void TT2_main() //interrupt function by TT2 +{ + led = !led; } //~~~~~~~~~~~~~~~~~~~~~~~~~~~end of Timebase funtion~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// \ No newline at end of file