works fine on STM

Dependencies:   mbed

Fork of Sample_manerine_SPI_LSM9DS0 by SHENG-HEN HSIEH

Revision:
0:d68e088dfbcd
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sample_timebase.cpp	Fri Jul 15 09:14:36 2016 +0000
@@ -0,0 +1,64 @@
+#include "mbed.h"
+
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~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
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~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
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~end of Function registor~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
+
+
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~main funtion~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
+int main()
+{
+    init_IO();                          //initialized value
+    init_TIMER();                       //start TT_main
+
+    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
+{
+    TT.attach_us(&TT_main, 1000);
+}
+
+void TT_main()                          //interrupt function by TT
+{
+    TT_main_ext = !TT_main_ext;         //indicate TT_main() function working
+    count = count+1;                    //one second counter
+}
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~end of Timebase funtion~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
\ No newline at end of file