Creating source codes for mbed board

advertisement
Design & Development of IOT/Embedded application
using ARM(LPC11U24 ) based mbed board
A Practical Approach
(Experimental Manual ForB.Tech & M.Tech Students)
For SoC and Embedded systems in association with
ARM university program and ITRA
Designed & Developed By: Ms. Nidhi Agarwal
Under the Guidance of: Dr. SRN Reddy, Associate Professor, CSE
Computer Science & Engineering Department
Indira Gandhi Delhi Technical University for Women
Kashmere Gate, Delhi-110006
1
LIST OF EXPERIMENTS
Exp No.
Description of experiment
Page No.
Exp. 1
To familiarize with ARM mbed board and understand the
procedure of creation and compilation of C++ source code.
3-10
Exp. 2
To write C++ source code for creating different LED patterns
and use ARM mbed board, on-board LEDs for checking
output.
11-12
Exp. 3
To write C++ source code for interfacing LEDs and push to on
switch with ARM mbed board at different GPIO pins.
13-15
Exp. 4
To write C++ source code for interfacing 16x2 LCD with ARM
mbed board at different GPIO pins.
16-18
Exp. 5
To write C++ source code for using analog input at GPIO pin
with ARM mbed board.
19-20
2
ARM MBED SYSTEM BOARD
mbed NXP LPC11U24
Experiment 1
Objective: To familiarize with ARM mbed board and understand the procedure of creation and
compilation of C++ source code.
Software Requirement: Internet access.
Hardware Requirement: Target board mbed NXP LPC11U24, USB Cable
Procedure:
1. Connect ARM mbed board with PC using proper USB cable.
2. Upon connection there appears a drive at My Computer of PC. E.g. MBED (E:) here figure
1.1.
Mbed drive
Mbed html link
Source code files
Figure 1.1 mbed drive on My computer
3. A click on mbed drive will show html link for mbed.org and all source code files (if board is
used earlier, for first time users no file will be there) saved into this board.
4. Click on html link and you will be redirected to mbed website.
5. First time user should create their login to use online compiler.
6. Click on Platform and select mbed LPC11U24. Figure 1.2, 1.3.
3
LED1-LED4
(on board)
GPIO pins
Programming
status LED
GPIO pins
USB connector
Reset Switch
Figure 1.2 LPC 11U24 ARM mbed board
7. All the documents related to concerned platform will be available there.
8. Pin diagram showing mapping of LPC11U24 pins with mbed LPC11U24 board with all
functions, is as shown in figure 1.4 and 1.5
Figure 1.3 LPC 11U24 ARM mbed board pin outs
4
Figure 1.4 Mapping of LPC 11U24 pins with ARM mbed board pin outs
5
Figure 1.5 Mapping of LPC 11U24 pins with ARM mbed board pin outs
The mbed NXP LPC11U24 microcontroller board in particular is designed for prototyping low cost
USB devices, battery powered applications and 32-bit ARM Cortex-M0 based designs. It is
packaged as a small DIP form-factor for prototyping with through-hole PCBs and breadboard and
includes a built-in USB FLASH programmer. The pin-out above shows the commonly used
interfaces and their locations. All the numbered pins (p5-p30) can also be used as DigitalIn and
DigitalOut interfaces. It includes a built-in USB programming interface for easy programming.
Features of mbed board and mbed.org website support
1. NXP LPC11U24 MCU
1.1. Low power ARM Cortex-M0 Core
1.2. 48MHz, 8KB RAM, 32KB FLASH
1.3. USB Device, 2xSPI, I2C , UART, 6xADC, GPIO
2. Prototyping form-factor
2.1. 40-pin 0.1" pitch DIP package, 54x26mm
2.2. 5V USB, 4.5-9V supply or 2.4-3.3V battery
2.3. Built-in USB drag 'n' drop FLASH programmer
3. mbed.org Developer Website
3.1. Lightweight Online Compiler
6
3.2. High level C/C++ SDK
3.3. Cookbook of published libraries and projects
Creating source codes for mbed board:1.
2.
3.
4.
5.
6.
7.
8.
9.
Connect to mbed.org website.
Login and open online Compiler.
Click New for new program creation. Then Empty program and provide some name. Figure
1.6, 1.7.
Add new file for source code with .cpp extension and library file mbed.h. Figure 1.8.
Open newly created .cpp file and write C++ source code at editor. Figure 1.9. Take any
source code of experiment 2.
Compile source code by pressing compile tab. Figure 1.9.
After compilation, when prompted choose save as and save .bin file only into mbed drive
at my computer. Figure 1.10, 1.11.
mbed board will be programmed then with .cpp source code. Program LED (Figure 1.2)
will be seen blinking during programming process..
Press reset switch (Figure 1.2) to start source code operation.
Figure 1.6 New Program creation
Figure 1.7 New Program creation
7
Figure 1.8 New Program creation, Addition of new source code file
Compile tab
C++ source code
written in editor
window
Figure 1.9 New Program creation
8
Figure 1.10 Compiling .cpp source code
Figure 1.11 Saving .bin source code
9
Click here and press
Save As
Result :- Compilation and programming of ARM mbed board is done and process understood.
Conclusion :- Using online compiler and editor it is easy to program ARM board anywhere, with
only mandatory requirement of internet access.
Remark :- Pin outs available at ARM mbed board is actually different from actual LPC11U24
processor. This should be kept in mind while preparing source codes.
Reference:1. www. mbed.org
10
Experiment 2
Objective: To write C++ source code for creating different LED patterns and use ARM mbed board
on-board LEDs for checking output.
Software Requirement: Internet access.
Hardware Requirement: Target board ARM mbed NXP LPC11U24, USB Cable
Procedure:
1. Write desired C++ source code
2. Compile using online compiler as described in experiment1.
Source Code 1: Table 2.1
;Program written using C++ for mbed LPC11U24 board
;This program will blink all four onboard LEDs,define all 4
LEDs ;using name myledx.
myled1 = 1;
myled2 = 1;
myled3 = 1;
myled4 = 1;
wait(0.2);
myled1 = 0;
myled2 = 0;
myled3 = 0;
myled4 = 0;
wait(0.2);
}
#include "mbed.h"
DigitalOut myled1(LED1);
DigitalOut myled2(LED2);
DigitalOut myled3(LED3);
DigitalOut myled4(LED4);
int main() {
while(1) {
}
Source Code 2: Table 2.2
;Program written using C++ for mbed LPC11U24 board
;This program will lit all four onboard LEDs in rotating
;manner, ;litting one LED at a time, define all 4 LEDs
;using name myledx.
#include "mbed.h"
DigitalOut myled1(LED1);
DigitalOut myled2(LED2);
DigitalOut myled3(LED3);
DigitalOut myled4(LED4);
int main() {
while(1) {
myled1 = 1;
myled2 = 0;
myled3 = 0;
myled4 = 0;
wait(0.2);
myled1 = 0;
myled2 = 1;
myled3 = 0;
myled4 = 0;
wait(0.2);
myled1 = 0;
myled2 = 0;
myled3 = 1;
myled4 = 0;
wait(0.2);
myled1 = 0;
myled2 = 0;
myled3 = 0;
myled4 = 1;
wait(0.2);
}
}
11
Source Code 3: Table 2.3
;Program written using C++ for mbed LPC11U24 board
;This program will lit two-two onboard LEDs, at a time
;Outputs given here as port and not as bits.
#include "mbed.h"
BusOut ledchk(LED1,LED2,LED3,LED4);
int main() {
while(1) {
ledchk = 12;
wait(0.5);
ledchk = 3;
wait(0.5);
}
}
Source Code 4: Table 2.4
;Program written using C++ for mbed LPC11U24 board
int main() {
;This program will lit all four onboard LEDs, showing
while(1) {
;hexadecimal counting pattern from 0 to 15( Fh).
for(int i=0; i<16; i++) {
;Outputs given here as port and not as bits.
myleds = i;
wait(1);
#include "mbed.h"
}
BusOut myleds(LED1, LED2, LED3, LED4);
}
}
Result:- Output observed at LEDs, as per compiled C++ source code.
Conclusion :- Small changes in source code may result in saving memory space and programmers
efforts tremendously.
Remark :- ALL available GPIOs can be accessed as individual pins using DigitalOut or as 4 bit/8bit
port using BusOut. All these functions are available in mbed.h library. Here Out describe Output
port. Similarly with DigitalIn and BusIn functions, GPIOs can be used as Input port.
Any available GPIO can be combined to form I/O port. This ease of programming is provided by
mbed board and not by ARM processor.
Reference:1. www.mbed.org
12
Experiment No. 3
Objective: To write C++ source code for interfacing LEDs and push to on switch with ARM mbed
board at different GPIO pins.
Software Requirement: Internet access.
Hardware Requirement: Target board ARM mbed NXP LPC11U24, USB Cable
Procedure:
Interfacing of LED
1. Connect LEDs as per connections given in Figure.
2. Write the desired C++ program and compile using online compiler as described in
experiment1.
Figure 3.1 Interfacing of LEDs at GPIOs
Source Code : Table 3.1
;Program written using C++ for mbed LPC11U24 board
int main() {
;This program will blink LED connected at pin 36 on mbed
while(1) {
board ;GPIO pin.
myled = !myled;
wait(0.2);
#include "mbed.h"
}
DigitalOut myled(p36);
}
13
Source Code : Table 3.2
;Program written using C++ for mbed LPC11U24 board
int main() {
;This program will lit 8 LEDs interfaced at GPIO pins,
while(1) {
showing ;hexadecimal counting pattern from 0 to 65535(
for(int i=0; i<65535; i++) {
FFFFh).
ledchk = !i;
;Outputs given here as port and not as bits.
wait(0.05);
}
#include "mbed.h"
}
BusOut ledchk(p21,p22,p23,p24,p25,p26,p29,p30);
}
Interfacing of push to on switch:
1. Connect switch as per connections given in Figure 3.2
2. Write the desired C++ source code and compile using online compiler as described in
experiment1.
Figure 3.2 Interfacing of push to on switch at GPIO p35
Source Code : Table 3.3
;Program written using C++ for mbed LPC11U24 board
int main() {
;This program will toggle onboard LED1, for every switch
while(1) {
press
if(switchpress) {
; switch connected at GPIO pin, p35.
led = !led;
}
#include "mbed.h"
wait(0.25);
DigitalIn switchpress(p35);
}
DigitalOut led(LED1);
}
Result:- Output observed at GPIO pins. LEDs and switch interfacing achieved at GPIOs as per
compiled C++ source code.
14
Conclusion :- Small changes in source code may result in saving memory space and programmers
efforts tremendously.
Remark :- Any available GPIO can be combined to form I/O port. This ease of programming is
provided by mbed board and not by ARM processor.
Reference:- www.mbed.org
15
Experiment No. 4
Objective: To write C++ source code for interfacing 16x2 LCD with ARM mbed board at different
GPIO pins.
Software Requirement: Internet access.
Hardware Requirement: Target board ARM mbed NXP LPC11U24, USB Cable .
Procedure:
Interfacing of LCD
1. Connect 16x2 LCDs as per connections given in Figure 4.1
2. Write the desired C++ source code
3. Compile using online compiler as described in experiment1.
Figure 4.1 Interfacing of LCD at GPIOs
16
Figure 4.2 Command set of LCD
17
Source Code : Table 4.1
;Program written using C++ for mbed LPC11U24 board
ledchk = lcddata;
;8 bit mode LCD display, lcd commands used are -01h for
wait(0.1);
;clear display, 12h for display on, 06h for entry mode, 28h
ENB = 0;
;for cursor and display shift, 56h for function set
RS = 0;
}
#include "mbed.h"
void lcd_int(void)
BusOut ledchk(p21,p22,p23,p24,p25,p26,p29,p30);
{
DigitalOut RS(p8);
lcd_cmd(01);
DigitalOut ENB(p14);
lcd_cmd(12);
lcd_cmd(06);
unsigned char wel[]={"Hello World"};
lcd_cmd(28);
void lcd_cmd(int lcdcmd)
lcd_cmd(56);
{
}
wait(0.2);
void printf(unsigned char msg[])
RS = 0;
{
ENB = 1;
char chari;
wait(0.05);
int i=0;
ledchk = lcdcmd;
while(msg[i]!='/')
wait(0.05);
{
ENB = 0;
chari=msg[i];
}
lcd_data(chari);
void lcd_data(int lcddata)
i++;}
{
}
wait(0.1);
int main()
RS = 1;
{
ENB = 1;
lcd_int();
wait(0.05);
printf(wel);
while(1)
}
Result: Output “Hello World” observed at 16x2 LCD as per C++ source code written.
Conclusion:- LCD is interfaced with ARM mbed board and is showing messages.
Remark:- With the same procedure 16x4, 20x2, 20x4, 40x4 etc LCD can also be interfaced. Here
care must be taken in selecting LCD display segment address. Through proper segment address one
can display data anywhere on LCD display panel.
Bidirectional communication between LCD and controller can also be done, where one can use LCD
memory space, can create own characters using CGRAM data space of LCD eg hindi character set.
LCD is interfaced here using 8 bit mode. Same LCD can also be interfaced using 4bit mode and
results in saving GPIOs
References:1. www.mbed.org
2. https://www.sparkfun.com/datasheets/LCD/ADM1602K-NSW-FBS-3.3v.pdf
18
Experiment No. 5
Objective: To write C++ source code for using analog input at GPIO pin with ARM mbed board.
Software Requirement: Internet access.
Hardware Requirement: Target board ARM mbed NXP LPC11U24, USB Cable .
Procedure:
1. Connect input as per connections given in Figure 5.1.
2. Write the desired C++ program and compile using online compiler as described in
experiment1.
Figure 5.1 ADC interfacing at GPIO pin 19
Source Code: Table 5.1
;Program written using C++ for mbed LPC11U24 board
; Analog input given at GPIO19
;Output seen at all 4 onboard LEDs
#include "mbed.h"
BusOut ledout(LED1, LED2, LED3, LED4);
AnalogIn ain(p19);
int main()
{
float c = ain.read();
while(1){
c= ain.read();
if (c<0.1)
{
ledout = 0;
else if (c<0.2)
{
ledout = 1;
}
}
else if (c<0.3)
{
ledout = 2;
else if (c<0.4)
{
ledout = 3;
else if (c<0.5)
{
ledout = 4;
else if (c<0.6)
{
ledout = 5;
else if (c<0.7)
{
ledout = 6;
else if (c<0.8)
{
ledout = 7;
else if (c<0.9)
{
ledout = 8;
else if (c<1.0)
{
ledout = 9;
}}
}
}
}
}
}
}
}
}
Result: Output is observed at all 4 on board LEDs as per variations in analog input voltage.
19
Conclusion:- Analog voltage inputs are taken by ARM mbed board and corresponding Digital data
is stored into internal registers.
Remark:- All six analog to digital channels can be used in same project. Range for analog inputs
data should be in the range of 0.1 to 1.0 Volts only.
Reference:
1. Datasheet LPC 11U series
2. www.mbed.org
20
Download