Beruflich Dokumente
Kultur Dokumente
LAB REPORT
Date: 12-07-19
Exp. No. : 1 Page No. : 1
Aim:
Give the introduction about Mbed Online Compiler and installation steps
Write an mbed c code using DigitalOut function
General information:
The mbed NXP LPC11U24 Microcontroller 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, stripboard and
breadboard, and includes a built-in USB FLASH programmer as shown in Fig. 1.
For delay:
wait(t) ; where ‘t’ is in seconds
Date: 19-07-19
Exp. No. : 2 Page No. : 1
Aim:
Give the introduction about Mbed Online Compiler and installation steps
Write an mbed c code for the following task using DigitalOut function
Task-1: Lit two-two onboard LEDs at a time
Task-2: Display hexadecimal counting pattern from 0-15 by blinking on the
board LEDs
Task-3: Read the multiple switch values and display status of the switches in
multiple LEDs. If the first two are on then display 0x55 and if the last two are on
display 0x AA
Task-4: Perform half adder
General information:
The mbed NXP LPC11U24 Microcontroller 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, stripboard and
breadboard, and includes a built-in USB FLASH programmer as shown in Fig. 1.
API Used:
For delay:
wait(t) ; where ‘t’ is in seconds
int main() {
while(1) {
myleds=3;
wait(0.4);
myleds=0;
wait(0.4);
}}
Output:
a. LED off b. LED on
2. Display hexadecimal counting pattern from 0-15 by blinking on the board LEDs
#include "mbed.h"
BusOut myleds(LED1, LED2, LED3, LED4);
int main() {
while(1) {
for(int i=0; i<16; i++) {
myleds = i;
wait(0.5);
}
}
}
Output:
0 1 2
3 4 5
6 7 8
9 10 11
12 13 14
15
3. Read the multiple switch values and display status of the switches in multiple LEDs.
If the first two are on then display 0x55 and if the last two are on display 0x AA
#include "mbed.h"
BusOut myled(LED1,LED2,LED3,LED4,p33,p34,p35,p36);
DigitalIn S1(p15); DigitalIn S2(p16); DigitalIn S3(p17); DigitalIn S4(p18); int main() {
while(1)
{
myled1=S1^S3; myled2=S1&S3;
}
}
Output:
00 01 10 11
Result: LED Blinking using mbed compiler was successfully executed and verified.
EXPERIMENT -3
TASK:
1)A Serial program to display a message to the pc.
2)To display the corresponding character you type in Serial Window.
3)To monitor the status of switch connected to pin p5 & to display “Hello” and blink LED1
when the pin p5 is high & to display “Sorry” and switch off LED1 when the pin p5 is low.
4)To use ‘Y’ & ‘N’ keys from PC to make LEDs on the Mbed board to display A & 5
respectively.
Algorithm
2)
#include "mbed.h"
DigitalOut myleds(LED1);
Serial pc(USBTX,USBRX);
int main()
while(1)
char s=pc.getc();
wait(.5);
pc.putc(s);
OUTPUT:
3)
#include "mbed.h"
DigitalOut myled(LED1);
DigitalIn sw(p5);
Serial pc(USBTX,USBRX);
int main() {
while(1) {
if (sw == 1)
{
pc.printf("Hello");
myled = 1;
}
else
{
pc.printf("Sorry");
myled = 0;
}
}
OUTPUT:
4)
#include "mbed.h"
BusOut myleds(LED1,LED2,LED3,LED4);
Serial pc(USBTX,USBRX);
int main()
{
while(1)
{
char s= pc.getc();
wait(.5);
if (s=='Y' || s=='y')
myleds=0xA;
else if(s=='N' || s=='n')
myleds=0x5;
else
myleds=0;
}
}
OUTPUT:
RESULT: Use of Serial API to display different output messages for the inputs
given by the user following the appropriate conditions mentioned.
EXPERIMENT-4
Aim:
Write an mbed c code for the following task using AnalogIn function
Task-1: Attach a potentiometer o/p to pin 20 and display varying input values on
tera-term
Task-2: Using 4 onboard LEDs, display potentiometer levels for 0.2 intervals
Task-3: Using LM35,display temperature on computer
General information:
The mbed NXP LPC11U24 Microcontroller 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, stripboard and
breadboard, and includes a built-in USB FLASH programmer as shown in Fig. 1.
Specifications of LPC11U24:
NXP LPC11U24 MCU
o Low power ARM® Cortex™-M0 Core
o 48MHz, 8KB RAM, 32KB FLASH
o USB Device, 2xSPI, I2C , UART, 6xADC, GPIO
Prototyping form-factor
o 40-pin 0.1" pitch DIP package, 54x26mm
o 5V USB, 4.5-9V supply or 2.4-3.3V battery
o Built-in USB drag 'n' drop FLASH programmer
mbed.org Developer Website
o Lightweight Online Compiler
o High level C/C++ SDK
o Cookbook of published libraries and projects
Task-1: Attach a potentiometer o/p to pin 20 and display varying input values on tera-term
API Used:
For delay:
wait(t) ; where ‘t’ is in seconds
TASK1:
CODE:
#include "mbed.h"
Serial pc(USBTX,USBRX);
AnalogIn A(p20);
float adcdata;
int main()
while(1)
adcdata=A;
pc.printf("%f\n\r",adcdata);
wait(0.5);
}}
OUTPUT:
Task-2: Using 4 onboard LEDs, display potentiometer levels for 0.2 intervals
CODE:
#include "mbed.h"
Serial pc(USBTX,USBRX);
BusOut MYLED(LED1,LED2,LED3,LED4);
AnalogIn A(p20);
float adcdata;
int main()
adcdata=A;
pc.printf("%f\n\r",adcdata);
wait(0.5);
if (adcdata<=0.2)
MYLED=0;
MYLED=8;
MYLED=12;
MYLED=14;
MYLED=15;
else
MYLED=0;
}}
OUTPUT:
Task-3: Using LM35,display temperature on computer
Code:
#include "mbed.h"
Serial pc(USBTX,USBRX);
AnalogIn A(p20);
float adcdata;
float Temp;
int main()
while(1)
adcdata=A;
Temp=adcdata*330;
if(Temp>=55&&Temp<=150)
else
wait(0.5);
}}
OUTPUT:
RESULT:
EXPERIMENT-5
Aim:
Write an mbed c code for the following task using AnalogIn function
Task-1: Create a PWM signal which will generate a 100Hz pulse with a 50% duty cycle.
Task-2: Change the duty cycle to 0.2 and check display
Task-3: Controlling LED brightness with PWM.
Task-4: Use a PWM signal to increase(u) and decrease(d) brightness of the onboard LED
use the Tera term to display brightness value.
Task-5: Piezobuzzer o/p of PWM Set 50% duty cycle and freq=500Hz. Create sound,
change frequency and notice the change in the sound.
General information:
The mbed NXP LPC11U24 Microcontroller 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, stripboard and breadboard, and includes a built-in
USB FLASH programmer as shown in Fig. 1.
Specifications of LPC11U24:
API Used:
For delay:
wait(t) ; where ‘t’ is in seconds
TASK1:
CODE:
#include “mbed.h”;
PwmOut led(p5);
int main(){
led.period(0.10f);
while(1);//led flashing
OUTPUT:
TASK-2:
#include "mbed.h"
PwmOut led(p5);
int main(){
led.period(0.10f);
while(1);//led flashing
OUTPUT:
TASK-3:
#include "mbed.h"
PwmOut led(p5);
float brightness=0.0;
int main() {
while(1){
wait(0.01);
brightness += 0.001;
led = brightness;
wait(0.01);
brightness -= 0.001;
led = brightness;
OUTPUT:
TASK-4:
// host terminal LED dimmer control
#include "mbed.h"
PwmOut led(p5);
float brightness=0.0;
int main() {
while(1) {
char c = pc.getc();
wait(0.001);
brightness += 0.001;
led = brightness; }
brightness -= 0.001;
led = brightness;
TASK-5:
#include "mbed.h"
PwmOut buzzer(p20);
float frequency[]={659,554,659,554,550,494,554,587,494,659,554,440};
//frequency array
float beat[]={1,1,1,1,1,0.5,0.5,1,1,1,1,2};
//beat array
int main() {
while (1) {
for (int i=0; i<=11; i++) {
buzzer.period(1/(frequency[i])); // set PWM period
buzzer=0.5; // set duty cycle
wait(0.5*beat[i]); // hold for beat period
}
}
}
RESULT:
Reg No: 17BEC1090 Mariyam Afshaan Ghani
EXPERIMENT -6
Date:16/08/19
Exp.No-. 6 Page No. : 1
APPARATUS REQUIRED:
Bread board
Servo motor
• A servo is a small rotary position control device, used for example in radio-controlled cars
and airplanes to position controllers such as steering, elevators and rudders
• The servo shaft can be positioned to specific angular positions by sending the servo a
PWM signal
• As long as the modulated signal exists on the input line, the servo will maintain the
angular position of the shaft
• As the modulated signal changes, the angular position of the shaft changes 13
Task 1:
Controlling servo motor position with PWM
#include "mbed.h"
PwmOut ser(p21);
float per=1.25;
int main(){
while(1){
ser.period(0.020f);
for(int i=0;i<100;i++){
int j=0.025;
ser.write(++j);
wait(1);
}
}
}
Task 2:
Light-tracking devices are very important for the capture of solar energy. Often they operate in
three dimensions, and tilt a solar panel so that it is facing the sun as accurately as possible. To start
rather more simply, create a two-dimensional light tracker by fitting two LDRs, angled away from
each other by around 90, to a servo. Connect the LDRs using the circuit of Figure in the next slide
to two ADC inputs. Write a program that reads the light value sensed by the two LDRs and rotates
the servo so that each is receiving equal light. The servo can only rotate 180. This is not, however,
unreasonable, as a sun-tracking system will be located to track the sun from sunrise to sunset, i.e.
not more than 180.
#include "mbed.h"
PwmOut servo(p24);
AnalogIn pot(p15);
int main() {
servo.period_ms(20);
int pw=1.5;
float ain=pot*3.3;
servo.pulsewidth_ms(pw);
while(1) {
if(ain<1.6) {
servo.pulsewidth_ms(pw++);
wait_ms(0.02);
}
else if(ain>=1.6) {
servo.pulsewidth_ms(pw--);
wait(0.02);
}
}
}
Task 3:
• Using the BusOut object, create a program to produce a “Knightrider” sweep effect with
the on-board LEDs.
• Use shift operators, << and >>.S
#include "mbed.h"
BusOut myleds(LED4, LED3, LED2, LED1);
char x=1;
int main()
{ while(1)
{ for(int i=0; i<3;i++){
x=x<<1;
myleds=x;
wait(0.2);
}
for(int i=0; i<3;i++){
x=x>>1;
myleds=x;
wait(0.2);
}}}
Result: Controlling servo motor with pwm experimented and verified.
Verification:
Reg No: 17BEC1090 Mariyam Afshaan Ghani
EXPERIMENT -7
HC-05
Date: 30/08/19 Exp.No- 7
AIM: Transmit any character or string from Smartphone via Bluetooth to the ARM
MBED
APPARATUS REQUIRED:
Bread board
HC 05
Fig. 1 : HC05
4 TX – Transmits Serial Data. Everything received via Bluetooth will be given out
Transmitter by this pin as serial data.
5 RX – Receiver Receive Serial Data. Every serial data given to this pin will be broadcasted
via Bluetooth
6 State The state pin is connected to on board LED, it can be used as a feedback
to check if Bluetooth is working properly.
8 Button Used to control the Key/Enable pin to toggle between Data and command
Mode
Task 1
Transmit any character or string from Smartphone via Bluetooth to the ARM MBED Download
and install a Bluetooth terminal application on your phone and use it to connect to the HC-05
Bluetooth module.
-Data is sent from the Smartphone using the Bluetooth terminal application.
Code;
#include "mbed.h"
Serial pc (USBTX,USBRX);
Serial bt(p9,p10);
int main(){
char ch;
pc.baud(9600);
bt.baud(9600);
pc.printf("Hello World!\n\r");
while(1){
if(bt.readable())
{ch=bt.getc();
pc.printf("%c",ch);}
else if(pc.readable()){
ch=pc.getc(); bt.printf("%c",ch);
Tera Term;
Android Application:
Task 2:
Code:
#include "mbed.h"
Serial pc(USBTX,USBRX);
Serial bt(p9,p10);
DigitalOut myled(LED1);
int main() {
char ch;
myled = 0;
pc.baud(9600);
bt.baud(9600);
while(1) {
if(bt.readable())
ch = bt.getc();
pc.printf("%c",ch);
myled = !(myled);
wait_ms(10);
3. #include "mbed.h"
Serial pc(USBTX,USBRX);
Serial bt(p9,p10);
AnalogIn lm(p20);
int main() {
float ain;
ain = lm;
pc.baud(9600);
bt.baud(9600);
while(1) {
if(bt.readable())
ain = lm.read()*3.3*100;
bt.printf("Temperature: %f\n\r",ain);
pc.printf("Temperature: %f\n\r",ain);
wait(5);
}
Result: Transmitting character or string and LED Control from Smartphone via Bluetooth
to the ARM MBED observed and verified.
Reg No: 17BEC1090 Mariyam Afshaan Ghani
EXPERIMENT -8
Date: 06/09/19
Tasks:
1. With a help of the timer measure the time taken to write a message
to the screen, and displays the time taken as a message.
2. Create a square wave(400ms) output using scheduled programming
and verify the timing accuracy with an oscilloscope.
3. When the interrupt is activated, by this rising edge, the ISR executes,
and LED1 is toggled. This can occur at any time in program execution
execution. The program program has effectively effectively one time
triggered task, the switching of LED4, and one event-triggered task,
the switching of LED1.
4. Use the mbed InterruptIn library to toggle an LED whenever a digital
input goes high, implementing a debounce counter to avoid multiple
interrupts.
APPARATUS REQUIRED:
Bread board
Task 1
Code:
#include "mbed.h"
Serial pc(USBTX,USBRX);
Timer t;
int main() {
while(1){
t.start();
pc.printf("Hello World!\n");
t.stop();
wait(5);
}}
Task 2:
Code:
#include "mbed.h"
Timer T1;
PwmOut out(p5);
int main()
{ T1.start();
while(1)
{ if(T1.read_ms()>=200)
{ out=!out;
T1.reset(); } } }
3. #include "mbed.h"
Timer T1;
DigitalOut out1(LED1);
DigitalOut out2(LED4);
InterruptIn in(p18);
void toggle()
{ out1=!out1; }
int main()
{ in.rise(&toggle);
T1.start();
while(1)
{ if(T1.read_ms()>=200)
{ out2=!out2;
T1.reset(); } } }
4.
#include "mbed.h"
InterruptIn button(p18);
DigitalOut led1(p5);
Timer debounce;
void toggle()
{ if(debounce.read_ms()>200)
{ led1=!led1; debounce.reset();
} } int main()
{ debounce.start();
while(1)
{ button.rise(&toggle); } }
Result:
Reg No: 17BEC1090 Mariyam Afshaan Ghani
EXPERIMENT -9
Date: 17/09/19
Task-1
Set up the Mbed board as Master, and exchange data with a slave,
sending its own switch positions, and displaying those of the slave using
LEDs
Code:
MASTER:
#include "mbed.h"
SPI ser_port(p11,p12,p13);
DigitalOut led1(LED1);
DigitalOut led2(LED2);
DigitalOut cs(p14);
DigitalIn switch_ip1(p7);
DigitalIn switch_ip2(p8);
char switch_word;
char recd_val;
int main() {
while(1) {
switch_word=0xa0;
if(switch_ip1==1)
switch_word=switch_word|0x01;
if(switch_ip2==1)
switch_word=switch_word|0x02;
cs=0;
recd_val=ser_port.write(switch_word);
cs=1;
wait(0.01);
led1=0;
led2=0;
recd_val=recd_val&0x03;
if(recd_val==1)
led1=1;
if(recd_val==2)
led2=1;
if(recd_val==3)
{
led1=1;
led2=1;
SLAVE:
#include "mbed.h"
SPISlave ser_port(p11, p12, p13, p14); // mosi, miso, sclk, ssel
DigitalOut led1(LED1);
DigitalOut led2(LED2);
DigitalIn switch_ip1(p5);
DigitalIn switch_ip2(p6);
char switch_word;
char recd_val;
int main() {
while(1) {
switch_word=0xa0;
if(switch_ip1==1)
switch_word=switch_word|0x01;
if(switch_ip2==1)
switch_word=switch_word|0x02;
if(ser_port.receive())
{
recd_val=ser_port.read();
ser_port.reply(switch_word);
led1=0;
led2=0;
recd_val=recd_val&0x03;
if(recd_val==1)
led1=1;
if(recd_val==2)
led2=1;
if(recd_val==3){
led1=1;
led2=1;
OUTPUT:
Task-2
Code:
MASTER:
#include "mbed.h"
SPI ser_port(p11,p12,p13);
DigitalOut cs (p14);
Serial pc(USBTX,USBRX);
char recv;
char y;
int main() {
while(1) {
y=pc.getc();
cs=0;
pc.putc(y);
recv=ser_port.write(y);
cs=1;
wait(0.001);
}
SLAVE:
#include "mbed.h"
Serial pc(USBTX,USBRX);
char switch_word;
char recd_val;
int main() {
while(1) {
if(ser_port.receive())
recd_val=ser_port.read();
pc.printf("%c",recd_val);
}
OUTPUT:
VERIFICATION:
Reg No: 17BEC1090 Mariyam Afshaan Ghani
13/9/19
Task-1
Interface two Mbed boards to have communication on I2C with one as master
and another as slave. Receive data from serial monitor and transmit thru master
device and receive the same and display on serial monitor of slave I2C.
Code:
MASTER:
#include "mbed.h"
Serial pc(USBTX,USBRX);
I2C i2c(p28,p27);
DigitalOut myled(LED1);
int main() {
char data[20];
while(1){
pc.scanf("%s",&data);
pc.printf("%s\t",data);
int len = strlen(data);
i2c.write(address,data,len);
wait(10);
SLAVE:
#include <mbed.h>
int main()
char buf[20];
slave.address(0xA0);
while (1)
int i= slave.receive();
switch (i)
char break;
case I2CSlave::WriteGeneral:slave.read(buf,
case I2CSlave::WriteAddressed:
slave.read(buf, 20);
break;}
buf[i] = 0;
OUTPUT:
Task-2
MASTER:
#include "mbed.h"
#include<string.h>
Serial pc(USBTX,USBRX);
I2C i2c_port(p28,p27);
DigitalOut myled(LED1);
DigitalIn switch_ip1(p7);
DigitalIn switch_ip2(p6);
char switch_word;
int main(){
while(1){
switch_word=0xa0;
if(switch_ip1==1){
switch_word=switch_word|0x01;
if(switch_ip2==1){
switch_word=switch_word|0x02;
SLAVE:
green_led(LED2);
//red led
//green led
DigitalIn switch_ip1(LED3);
DigitalIn switch_ip2(LED4);
char recd_val;
int main()
{slave.address(0x52);
if (switch_ip1==1)
switch_word=switch_word|0x01;
if (switch_ip2==1)
switch_word=switch_word|0x02;
int i = slave.receive();
green_led=0;
if (recd_val==1)
red_led=1;
if (recd_val==2)
green_led=1;
if (recd_val==3)
{red_led=1;green_led=1;
OUTPUT:
Verifictaion:
6
9
VIRTUAL LAB
TIMERS
Date:11-10-2019
Exp.No. 12
Page No. : 1
Aim:
• Give the introduction about Mbed Online Compiler and installation steps
• Write an mbed c code for the following task using DigitalOut,timer functions.
• Task1: Apply the Timer to run one function at one rate and another function at
another rate. Create four Timers at different rates. When the time value is
exceeded, a function is called,whichflipsthe associatedmbed LED.
• Task2: Find the maximum value that the Timer can reach. Tests Timer
duration and display the current time values to terminal.
General information:
The mbed NXP LPC11U24 Microcontroller 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, stripboard and
breadboard, and includes a built-in USB FLASH programmer as shown in Fig. 1.
Specificationsof LPC11U24:
• NXP LPC11U24 MCU o Low power ARM® Cortex™-M0 Core o 48MHz, 8KB RAM,
32KB FLASH
API Used:
timername.reset();
timername.read();
Code for timing task and LED Blinking :
#include "mbed.h"
Timer timer1;
7
1
Timer timer2;
Timer timer3;
Timer timer4;
DigitalOut ledA(LED1);
DigitalOut ledB(LED2);
DigitalOut ledC(LED3);
DigitalOut ledD(LED4);
void task1(void);
task3(void);
void task4(void);
7
2
int main() {
timer1.start();
timer2.start();
timer3.start();
timer4.start(); while
(1){ if
(timer1.read()>0.2){
task1();
timer1.reset();
if (timer2.read()>0.5){
task2();
timer2.reset();
if (timer3.read()>1){
task3();
timer3.reset();
if (timer4.read()>2){
7
3
task4();
timer4.reset();
void task1(void){
ledA = !ledA;
void task2(void){
ledB = !ledB;
void task3(void){
7
4
ledC = !ledC;
void task4(void){
ledD = !ledD;
Output:
API Used:
7
5
Syntax used for digital output:
Serial pc(USBTX,USBRX)
timername.reset();
timername.read();
4
7
6
Code for displaying timer value on serial window
t;
float s=0;
float m=0;
main()
\n\n\r");
t.reset();
t.start();
while(1){ if
(t.read()>=(s+1))
{ diag =
1;
wait (0.05);
diag = 0;
7
7
s++ ;
pc.printf("%1.0f seconds\r\n",(s-60*(m-1)));
if (t.read()>=60*m)
m++ ;
if (t.read()<s)
7
8
{
for(;;){}
Output:
79