For NTHU_Racing MCU tutorial Learn to use Serial Oscilloscope & analog pin

Dependencies:   mbed

Fork of Practice_3_example by NTHU_Racing

Committer:
open4416
Date:
Thu Jan 19 07:42:30 2017 +0000
Revision:
1:5968363c5d23
Parent:
0:d68e088dfbcd
For NTHU_racing MCU tutorial

Who changed what in which revision?

UserRevisionLine numberNew contents of line
open4416 0:d68e088dfbcd 1 #include "mbed.h"
open4416 0:d68e088dfbcd 2
open4416 0:d68e088dfbcd 3 //~~~~~~~~~~~~~~~~~~~~~~~~~~~GPIO registor~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
open4416 0:d68e088dfbcd 4 DigitalOut led = D13; //link leg
open4416 0:d68e088dfbcd 5 //~~~~~~~~~~~~~~~~~~~~~~~~~~~end of GPIO registor~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
open4416 0:d68e088dfbcd 6
open4416 0:d68e088dfbcd 7
open4416 0:d68e088dfbcd 8 //~~~~~~~~~~~~~~~~~~~~~~~~~~~Varible registor~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
open4416 1:5968363c5d23 9 Ticker TT1; //call a timer
open4416 1:5968363c5d23 10 Ticker TT2; //call a timer
open4416 0:d68e088dfbcd 11 //~~~~~~~~~~~~~~~~~~~~~~~~~~~end of Varible registor~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
open4416 0:d68e088dfbcd 12
open4416 0:d68e088dfbcd 13
open4416 0:d68e088dfbcd 14 //~~~~~~~~~~~~~~~~~~~~~~~~~~~Function registor~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
open4416 0:d68e088dfbcd 15 void init_IO(); //initialize IO state
open4416 0:d68e088dfbcd 16 void init_TIMER(); //set TT_main{} rate
open4416 1:5968363c5d23 17 void TT1_main(); //timebase function rated by TT1
open4416 1:5968363c5d23 18 void TT2_main(); //timebase function rated by TT2
open4416 0:d68e088dfbcd 19 //~~~~~~~~~~~~~~~~~~~~~~~~~~~end of Function registor~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
open4416 0:d68e088dfbcd 20
open4416 0:d68e088dfbcd 21
open4416 0:d68e088dfbcd 22 //~~~~~~~~~~~~~~~~~~~~~~~~~~~main funtion~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
open4416 0:d68e088dfbcd 23 int main()
open4416 0:d68e088dfbcd 24 {
open4416 0:d68e088dfbcd 25 init_IO(); //initialized value
open4416 1:5968363c5d23 26 init_TIMER(); //initialized Timer Inturrupt rate
open4416 0:d68e088dfbcd 27
open4416 0:d68e088dfbcd 28 while(1) { //main() loop
open4416 0:d68e088dfbcd 29 }
open4416 0:d68e088dfbcd 30 }
open4416 0:d68e088dfbcd 31 //~~~~~~~~~~~~~~~~~~~~~~~~~~~end of main funtion~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
open4416 0:d68e088dfbcd 32
open4416 0:d68e088dfbcd 33
open4416 0:d68e088dfbcd 34 //~~~~~~~~~~~~~~~~~~~~~~~~~~~init_IO funtion~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
open4416 0:d68e088dfbcd 35 void init_IO(void) //initialize
open4416 0:d68e088dfbcd 36 {
open4416 0:d68e088dfbcd 37 led = 1;
open4416 0:d68e088dfbcd 38 }
open4416 0:d68e088dfbcd 39 //~~~~~~~~~~~~~~~~~~~~~~~~~~~end of init_IO funtion~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
open4416 0:d68e088dfbcd 40
open4416 0:d68e088dfbcd 41
open4416 0:d68e088dfbcd 42
open4416 0:d68e088dfbcd 43 //~~~~~~~~~~~~~~~~~~~~~~~~~~~Timebase funtion~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
open4416 1:5968363c5d23 44 void init_TIMER() //set TTx_main{} rate
open4416 0:d68e088dfbcd 45 {
open4416 1:5968363c5d23 46 TT1.attach_us(&TT1_main, 1000);
open4416 1:5968363c5d23 47 TT2.attach_us(&TT2_main, 1010);
open4416 0:d68e088dfbcd 48 }
open4416 0:d68e088dfbcd 49
open4416 1:5968363c5d23 50 void TT1_main() //interrupt function by TT1
open4416 0:d68e088dfbcd 51 {
open4416 1:5968363c5d23 52 led = !led;
open4416 1:5968363c5d23 53 }
open4416 1:5968363c5d23 54
open4416 1:5968363c5d23 55 void TT2_main() //interrupt function by TT2
open4416 1:5968363c5d23 56 {
open4416 1:5968363c5d23 57 led = !led;
open4416 0:d68e088dfbcd 58 }
open4416 0:d68e088dfbcd 59 //~~~~~~~~~~~~~~~~~~~~~~~~~~~end of Timebase funtion~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//