*

Dependencies:   mbed-STM32F103C8T6 mbed

Committer:
BaserK
Date:
Sat Apr 29 15:30:17 2017 +0000
Revision:
0:6345f9145b9a
*

Who changed what in which revision?

UserRevisionLine numberNew contents of line
BaserK 0:6345f9145b9a 1 #include "stm32f103c8t6.h"
BaserK 0:6345f9145b9a 2 #include "mbed.h"
BaserK 0:6345f9145b9a 3
BaserK 0:6345f9145b9a 4 // Timer and ticker example
BaserK 0:6345f9145b9a 5 // Shows how to use a timer and a ticker
BaserK 0:6345f9145b9a 6
BaserK 0:6345f9145b9a 7 DigitalOut led(PB_12);
BaserK 0:6345f9145b9a 8 Ticker toggler;
BaserK 0:6345f9145b9a 9 Timer timer;
BaserK 0:6345f9145b9a 10 Serial pc(PA_2, PA_3);
BaserK 0:6345f9145b9a 11
BaserK 0:6345f9145b9a 12 void toggle_led();
BaserK 0:6345f9145b9a 13
BaserK 0:6345f9145b9a 14 int main()
BaserK 0:6345f9145b9a 15 {
BaserK 0:6345f9145b9a 16 confSysClock(); //Configure system clock (72MHz HSE clock, 48MHz USB clock)
BaserK 0:6345f9145b9a 17 pc.baud(9600);
BaserK 0:6345f9145b9a 18
BaserK 0:6345f9145b9a 19 // toggle the led every 500 ms
BaserK 0:6345f9145b9a 20 toggler.attach(&toggle_led, 0.5);
BaserK 0:6345f9145b9a 21
BaserK 0:6345f9145b9a 22 timer.start();
BaserK 0:6345f9145b9a 23
BaserK 0:6345f9145b9a 24 while (1)
BaserK 0:6345f9145b9a 25 {
BaserK 0:6345f9145b9a 26
BaserK 0:6345f9145b9a 27 }
BaserK 0:6345f9145b9a 28 }
BaserK 0:6345f9145b9a 29
BaserK 0:6345f9145b9a 30 void toggle_led()
BaserK 0:6345f9145b9a 31 {
BaserK 0:6345f9145b9a 32 // change the state of the led
BaserK 0:6345f9145b9a 33 led = !led;
BaserK 0:6345f9145b9a 34
BaserK 0:6345f9145b9a 35 // get the current time in ms
BaserK 0:6345f9145b9a 36 int time = timer.read_ms();
BaserK 0:6345f9145b9a 37
BaserK 0:6345f9145b9a 38 // print the time
BaserK 0:6345f9145b9a 39 pc.printf("Time is: %d \r\n", time);
BaserK 0:6345f9145b9a 40
BaserK 0:6345f9145b9a 41 // reset the timer
BaserK 0:6345f9145b9a 42 timer.reset();
BaserK 0:6345f9145b9a 43 }