For NTHU_Racing MCU tutorial Learn to use PinInterrupt

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
open4416
Date:
Sun Jan 22 05:08:15 2017 +0000
Commit message:
Not funtional yet

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 21fdaaa57d18 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Jan 22 05:08:15 2017 +0000
@@ -0,0 +1,68 @@
+#include "mbed.h"
+
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~GPIO registor~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
+DigitalOut  led(D13);                   //link leg
+InterruptIn button(PC_13);              //same as "button(USER_BUTTON)"
+Serial      pc(D1, D0);                 //Serial reg
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~end of GPIO registor~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
+
+
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~Varible registor~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
+Ticker  TT;                             //call a timer
+int     count;                          //numbers of pressed
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~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 pressed();                         //program run when pointed to here
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~end of Function registor~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
+
+
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~main funtion~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
+int main()
+{
+    init_IO();                          //initialized value and IRQ(Interrupt request)
+    init_TIMER();                       //start TT_main
+    pc.baud(9600);                      //set baud rate
+
+    while(1) {                          //main() loop
+    }
+
+}
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~end of main funtion~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
+
+
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~init_IO funtion~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
+void init_IO(void)                      //initialize
+{
+    led = 0;
+    count = 0;
+    button.fall(&pressed);
+}
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~end of init_IO funtion~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
+
+
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~Timebase funtion~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
+void init_TIMER()                       //set TT_main{} rate
+{
+    TT.attach_us(&TT_main, 500000);     //rate set to 0.5 sec
+}
+
+void TT_main()                          //interrupt function by TT
+{
+    led = !led;                         //just to make sure program runnung
+    //print out data
+}
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~end of Timebase funtion~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
+
+
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~IRQ funtion~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
+void pressed()                          //do these shit when triger
+{
+    //these will be run if pressed() executed
+}
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~end of IRQ funtion~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
\ No newline at end of file
diff -r 000000000000 -r 21fdaaa57d18 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun Jan 22 05:08:15 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/ad3be0349dc5
\ No newline at end of file