Hello world example program. This program exercises many of the peripherials including serial (prints hello world), as well as pushbutton and LED usage.

Dependencies:   mbed

Fork of frdm_helloworld by Freescale

Committer:
Kojto
Date:
Thu Apr 03 08:36:21 2014 +0000
Revision:
0:4f3ac9922229
initial version of complete lab 1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Kojto 0:4f3ac9922229 1 #include "mbed.h"
Kojto 0:4f3ac9922229 2
Kojto 0:4f3ac9922229 3 DigitalOut led_red(LED_RED);
Kojto 0:4f3ac9922229 4 DigitalOut led_green(LED_GREEN);
Kojto 0:4f3ac9922229 5 DigitalIn sw2(SW2);
Kojto 0:4f3ac9922229 6 DigitalIn sw3(SW3);
Kojto 0:4f3ac9922229 7 Serial pc(USBTX, USBRX);
Kojto 0:4f3ac9922229 8
Kojto 0:4f3ac9922229 9 void check_sw2(void)
Kojto 0:4f3ac9922229 10 {
Kojto 0:4f3ac9922229 11 if (sw2 == 0) {
Kojto 0:4f3ac9922229 12 pc.printf("SW2 button pressed. \n");
Kojto 0:4f3ac9922229 13 led_red = 0;
Kojto 0:4f3ac9922229 14 led_green = 1;
Kojto 0:4f3ac9922229 15 }
Kojto 0:4f3ac9922229 16 }
Kojto 0:4f3ac9922229 17
Kojto 0:4f3ac9922229 18 void check_sw3(void)
Kojto 0:4f3ac9922229 19 {
Kojto 0:4f3ac9922229 20 if (sw3 == 0) {
Kojto 0:4f3ac9922229 21 pc.printf("SW3 button pressed. \n");
Kojto 0:4f3ac9922229 22 led_green = 0;
Kojto 0:4f3ac9922229 23 led_red = 1;
Kojto 0:4f3ac9922229 24 pc.printf("5 characters will be echoed. Start typing. \n");
Kojto 0:4f3ac9922229 25 for (uint32_t i = 0; i < 5; i++) {
Kojto 0:4f3ac9922229 26 pc.putc(pc.getc());
Kojto 0:4f3ac9922229 27 }
Kojto 0:4f3ac9922229 28 pc.putc(13); /* CR */
Kojto 0:4f3ac9922229 29 pc.putc(10); /* LF */
Kojto 0:4f3ac9922229 30 }
Kojto 0:4f3ac9922229 31 }
Kojto 0:4f3ac9922229 32
Kojto 0:4f3ac9922229 33 int main() {
Kojto 0:4f3ac9922229 34 led_green = 1;
Kojto 0:4f3ac9922229 35 led_red = 1;
Kojto 0:4f3ac9922229 36 pc.baud(115200);
Kojto 0:4f3ac9922229 37 pc.printf("Hello World from FRDM-K64F board.\n");
Kojto 0:4f3ac9922229 38
Kojto 0:4f3ac9922229 39 while (true) {
Kojto 0:4f3ac9922229 40 check_sw2();
Kojto 0:4f3ac9922229 41 check_sw3();
Kojto 0:4f3ac9922229 42 wait(0.3);
Kojto 0:4f3ac9922229 43 }
Kojto 0:4f3ac9922229 44 }