Now follow the sequence of instructions below. The purpose of this tutorial is to explain the main
steps in getting a program running on the mbed. We will look into the detail of the program in the
next chapter.
Step 1. Connecting the mbed to the PC
Connect the mbed to the PC using the USB lead. The Status light will come on, indicating that the
mbed has power. After a few seconds of activity, the PC will recognize the mbed as a standard
removable drive, and it will appear on the devices linked to the computer, as seen in
Figure 2.4. Locating the mbed: (a) Windows XP example; (b) Mac OS X example
Step 2. Creating an mbed Account
Open the MBED.HTM file found on the mbed in your web browser and click the Create a new mbed
Account link. Follow the instructions to create an mbed Account. This will lead you to the website, as
seen in Figure 2.5. From here you can link to the compiler, libraries and documentation.
As seen in Figure 2.6a, right-click (Mac users, Ctrl-click) on My Programs and select New
Program ..
Choose and enter a name for the new program (for example Prog_Ex_2_1) and click OK. Do not
leave spaces in the program name.
Your new program folder will be created under My Programs.
Click on the main.cpp file in your new program to open it in the file editor window, as seen in
Figure 2.6b. This is the main source code file in your program. Whenever you create a new program
it always contains the same simple code. This is shown here as Program Example 2.1. This program
will be examined in the next chapter.
Figure 2.6. Opening a new program: (a) selecting New Program; (b) opening the main
source file
The other item in the program folder is the mbed library. This provides all the functions used to
start up and control the mbed, such as the DigitalOut interface used in this example.
proceed with the compilation, as it perceives that the program has stepped outside the rules of the
language, and hence cannot reliably interpret the code that is written.
Downloading the Program Binary Code
Step 5. Downloading the Program Binary Code
After a successful compile, the program code, in binary form, can be downloaded to the mbed. Save
it to the location of the mbed drive. You should see the Status LED (as seen in Figure 2.1) flash as
the program downloads. Once the Status LED has stopped flashing, press the reset button on the
mbed to start your program running. You should now see LED1 flashing on and off every 0.2
seconds.
In general, C code will compile on a C compiler, but not the other way round.
Using C
C is usually the language of choice for any embedded program of low or medium complexity, so will
suit us well in this book. For simplicity, therefore, we aim to use only C in the programs we develop.
It should be recognized, however, that the mbed API is written in C and uses the features of that
language to the full. We will aim to outline any essential features when we come to them.
This book does not assume that you have any knowledge of C or C, although you
have an advantage if you do. We aim to introduce all new features of C as they come
up, flagging this by using the symbol alongside. If you see that symbol and you are a C
expert, then it means you can probably skim through that section. If you are not an
expert, you will need to read the section with care and refer to Appendix B, which summarizes all
the C features used. Even if you are a C expert, you may not have used it in an embedded context. As
you work through the book you will see a number of tricks and techniques that are used to optimize
the language for this particular environment.
Chapter Review
Quiz
1.
2.
3.
4.
5.
6.
7.
10. By not connecting all the LPC1768 microcontroller pins to the mbed external pins, a number of
microcontroller peripherals are lost for use. Identify which ones these are, for ADC, UART,
CAN, I2C, SPI and DAC.
References
2.1. The mbed home site. http://mbed.org/
2.2. MBED Circuit Diagrams. 26/08/2010. http://mbed.org/media/uploads/chris/mbed-005.1.pdf
2.3. NXP B.V. LPC1768/66/65/64 32-bit ARM Cortex-M3 microcontroller. Objective data sheet. Rev.
6.0. August 2010. http://www.nxp.com/
2.4. NXP B.V. LPC17xx User Manual. Rev. 02. August 2010. http://www.nxp.com/
Be sure to continue to next chapter in this except: ARM mbed analog-to-digital conversion.
Copyright 2014 Elsevier, Inc. All rights reserved.
Printed with permission from Newnes, a division of Elsevier. Copyright 2014. For more
information on this title and other similar books, please visit www.newnespress.com.