Sei sulla pagina 1di 56

FINAL LAB REPORT

Embedded System Design (ECE4003)

NOVEMBER 6, 2019
HARSH KULSHRESTHA
17BEC1043
Contents
S. No. Experiment Date
1 LED blinking using DigitalOut API 16/07/2019
2 LED blinking using BusOut function 23/07/2019
3 Serial communication 30/07/2019
4 PwmOut API(I) 06/08/2019
5 PwmOut API(II) 13/08/2019
6 Bluetooth Module 27/08/2019
7 LCD Interfacing 03/09/2019
8 SPI Interfacing 10/09/2019
9 Car Parking Sensor 17/09/2019
10 Pedometer using Accelerometer 08/10/2019
11 RTOS 15/10/2019
Experiment 1
LED BLINKING USING DIGITALOUT FUNCTION
Date: 16.07.19
Exp. No.: 1

17BEC1043

Aim: To Blink LEDs using Digital-Out Function.

• Task-1: On-board LED Blinking


• Task-2: LED blinking pattern one at a time
• Task-3: blinking alternate LEDs

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.

Fig. 1 : LPC11U24 Pin details


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: On-board LED Blinking

API Used:

Syntax used for digital output:


DigitalOut (PinName pin)

For LED blinking we’ve used:


DigitalOut variable(LEDn); where n= 1,2,3,4

For delay:
wait(t) ; where ‘t’ is in seconds

Code for LED Blinking:


#include "mbed.h"
DigitalOut myled(LED1);
DigitalOut myled1(LED2);
DigitalOut myled2(LED3);
DigitalOut myled3(LED4);
int main() {
while(1) {
myled = 1;
wait(0.2);
myled2 = 1;
wait(0.2);
myled1=1;
wait(0.2);
myled3 = 1;
wait(0.2);
myled = 0;
wait(0.2);
myled2=0;
wait(0.2);
myled1=0;
wait(0.2);
myled3 = 0;
wait(0.2);
}
}

Task - 2
#include "mbed.h"

DigitalOut myled1(LED1);
DigitalOut myled2(LED2);
DigitalOut myled3(LED3);
DigitalOut myled4(LED4);

int main() {
while(1) {
myled1 = 1;
wait(0.5);
myled1 = 0;
wait(0.5);

myled2 = 1;
wait(0.5);
myled2 = 0;
wait(0.5);

myled3 = 1;
wait(0.5);
myled3 = 0;
wait(0.5);

myled4 = 1;
wait(0.5);
myled4 = 0;
wait(0.5);
}
}

Task – 3
CODE
#include "mbed.h"

DigitalOut myled1(LED1);
DigitalOut myled2(LED2);
DigitalOut myled3(LED3);
DigitalOut myled4(LED4);
int main() {
while(1) {
myled1 = 1;
wait(0.5);

myled2 = 1;
wait(0.5);

myled3 = 1;
wait(0.5);

myled4 = 1;
wait(0.5);
myled4 = 0;
wait(0.5);

myled3= 0;
wait(0.5);

myled2= 0;
wait(0.5);

myled1= 0;
wait(0.5);

}
}

Output:
Fig. 1 LED Blinking

Fig. 2 LED Blinking


Fig. 3 LED Blinking

Fig. 4 LED Blinking

Result: LED Blinking using mbed software was successfully executed and verified.
Experiment 2
LED GLOWING USING BUSOUT FUNCTION
Date: 23.07.19
Exp. No.: 2

17BEC1043
AIM: To use BUSOUT function and glow on board LEDs.

Task 1: Glow 2 onboard LEDs at the same time


Task 2: Display Hexadecimal Counting pattern from 0-15.
Task 3: Read the Switch values and display the status of the switches in multiple LEDs.
Task 4: Design a 7-segment display.

API Used: BUSOUT

Task 1:
code:
#include "mbed.h"

BusOut myled1(LED1,LED2);
BusOut myled2(LED3,LED4);
int main(){
while(1)
{ myled1=3;
myled2=0;
wait(1);
myled1=0;
myled2=3;
wait(1);
}
}
2.

Code:
#include "mbed.h"

BusOut myled1(LED1,LED2,LED3,LED4);
int i;
int main(){
while(1)
{ for(i=0;i<16;i++)
{ myled1=i;
wait(1);}

}
}

3.
Code:
#include "mbed.h"

BusIn pins(p15,p16,p17,p18);
BusOut myled2(LED1,LED2,LED3,LED4,p21,p22,p23,p24);
int main()
{
while(1)
{
if(pins==12)
{
myled2=0xAA;
}
else if(pins==3)
{
myled2=0x55;
}
}
}

Task 4.
#include "mbed.h"

BusOut leds(p21,p22,p23,p24,p25,p26,p27,p28);
int main()
{
while(1)
{
wait(0.5);
leds=0x3f;
wait(0.5);
leds=0x06;
wait(0.5);
leds=0x5b;
wait(0.5);
leds=0x4f;
wait(0.5);
leds=0x66;
wait(0.5);
leds=0x6d;
wait(0.5);

OUTPUTS:
Fig. 1 Hexadecimal counting pattern

Fig. 2 Displaying OX55 and OXAA


Fig. 3 Seven Segment Display.

RESULT: The API BUSOUT was used to light onboard and external LEDs and hexadecimal
pattern was displayed.
Experiment 3
Serial Communication
Date: 30.07.19
Exp. No.: 3

17BEC1043

Verification-

Task 1-
Write a c++ code with mbed APIS to print the current voltage value of a potentiometer on PC serial monitor using
ADC and serial power.

Code-
#include "mbed.h"
serial pc(USBTX,USBRX);
AnalogIn ain(p20)
int main()
{
while(1)
{
float value=ain*3.3;
printf("the voltage is %f",value)
wait(1)
}
}
Output-

Task 2-
Write a C++ code to interface an LM35 with mbed board and display the temperature values of
PC serial monitor.
Code-
#include "mbed.h"
Serial pc(USBTX,USBRX);
AnalogIn ain(p20);
int main()
{
while(1)
{
float value=ain*3.3*100;
printf("the temprature is %f",value);
wait(1);
}
}
Circuit-

Output-
Task 3-
Write the C++ code using mbed API to implement the table as shown in the lab.
Code-
#include "mbed.h"

Serial pc(USBTX,USBRX);
AnalogIn Ain(p20);
BusOut myled(LED1,LED2,LED3,LED4);
float ADCdata;
int main(){
pc.printf("ADC Data values...\n\r");
while(1)
{
ADCdata=Ain;
pc.printf("%f\n\r",ADCdata);
wait(0.5);
if(0.00000<ADCdata<=0.20000)
myled=0x00;
else if(0.20000<ADCdata<=0.400000)
myled=0x01;

else if(0.40000<ADCdata<=0.60000)
myled=0x03;

else if(0.60000<ADCdata<=0.800000)
myled=0x07;

else if(0.80000<=ADCdata<=1.00000)
myled=0xf;
}

Outputs-
}
EXPERIMENT 4
PwmOut API
Verification-

Task 1-
Write a C++ code with mbed API to generate a PWM signal with duty cycle 50%. Verify the
ouput using
(a). LED
(b). Digital CRO
Code
#include "mbed.h"

PwmOut PWM1(p21);

int main()

{
PWM1.period(0.010); // set PWM period to 10 ms

PWM1=0.5; // set duty cycle to 50%

Task 2-
Repeat the task 1 with 70% duty cycle.
Code-
#include "mbed.h"

PwmOut PWM1(p21);

int main()

PWM1.period(0.010); // set PWM period to 10 ms

PWM1=0.7; // set duty cycle to 70%

}
Experiment 5
PwmOut Function
Date:13 Aug, 2019
Week No. : 5 Reg No-17BEC1043

Verification-

Aim:

• Give the introduction about Mbed Online Compiler and installation steps
• Write an mbed c code for the following task using PwmOut function
1. Write the c++ code to vary the intensity of the LED using the values of
potentiometer.
2. Generate a PWM signal to increase or decrease the brightness. If ‘i’ is
pressed then increase the brightness, do the opposite if ‘d’ is pressed.
APIs used:

PwmOut,DigitalOut,AnalogIn

Code 1:

#include "mbed.h"

DigitalOut dout(p22);

AnalogIn ain(p20);

int main() {

while(1) {

dout=ain;

wait(1);

Bright LED-
Dim LED-
Code 2:

#include "mbed.h"

Serial pc(USBTX, USBRX); // tx, rx

PwmOut led(p20);

float brightness=0.0;

int main() {

pc.printf("Control of LED dimmer by host terminal\n\r");

pc.printf("Press 'u' = brighter, 'd' = dimmer\n\r");

while(1) {

char c = pc.getc();

wait(0.001);

if((c == 'i') && (brightness < 0.1)) {


brightness += 0.001;

led = brightness;

if((c == 'd') && (brightness > 0.0)) {

brightness -= 0.001;

led = brightness;

pc.printf("%c %1.3f \n \r",c,brightness);

}
Experiment 6
BLUETOOTH MODULE
Date: 27.08.19

17BEC1043
Verification-

AIM: To transmit data to android device with Bluetooth module


Write a C Code to
TASK 1: To transmit data to Android device Eg Print “Hello World”.
TASK 2: To glow respective LEDs when 0 and 1 are the inputs from android device.
TASK 3: To read the temperature and display on the mobile.

API Used: SERIAL BT

Bluetooth modem used: Hc05.


CODE:

TASK 1:
Bluetooth modem used:Hc05
#include "mbed.h"
Serial pc(USBTX,USBRX);
Serial bt(p9,p10);
int main()
{

pc.baud(9600);
bt.baud(9600);
pc.printf("Hello World\n\r");
wait(100);
}

TASK 2:
#include "mbed.h"
Serial pc(USBTX,USBRX);
Serial bt(p9,p10);
int main()
{
char ch;
pc.baud(9600);
bt.baud(9600);
while(1)
{
if(bt.readable())
{
ch=bt.getc();
pc.printf("%c",ch);
}
else if(pc.readable())
{
ch=pc.getc();
bt.printf("%c",ch);}

}}

TASk3:
#include "mbed.h"
Serial pc(USBTX,USBRX);
Serial bt(p9,p10);
BusOut myled(LED1,LED2);
int main()
{
char ch;
pc.baud(9600);
bt.baud(9600);
pc.printf("Hello World!\n\r");
while(1)
{
if(bt.readable())
{
ch=bt.getc();
if(ch=='1')
{
myled=01;
wait(0.2);

}
if(ch=='0'){
myled=10;
wait(0.2);
}
}
else if(pc.readable())
{
ch=pc.getc();
if(ch=='1')
{
myled=01;
wait(0.2);
}
if(ch=='0'){
myled=10;
wait(0.2);

}
}
}
}
––

TASK 4:
#include "mbed.h"
Serial pc(USBTX,USBRX);
AnalogIn a(p20);
Serial bt(p9, p10);

int main() {
char ch;
pc.baud(9600);
bt.baud(9600);
pc.printf("Hello World!\n\r");
bt.printf("Hello World!\r\n");

while(1) {
float value=a*(3.3)*100;
pc.printf("the temperature value is %f\n",value);
bt.printf("the temperature value is %f\n",value);
wait(1);

}
}

OUTPUTS:

Fig 1: Print “HI”


Fig 2: To display the input from Bluetooth terminal on TERATERM.

Fig 3: Display Temperature.

RESULT:

The data was transmitted and received using Bluetooth module.


Experriment 7
LCD interfacing
Date: 3 Sept,2019
Exp. No. : 7 Reg. No. : 17BEC1043
Verification-

Aim:

Task1- To print “Hello world” in the interfaced LCD.

Task2 - To print the average temperate values using LM35 and print it on an LCD.

General Information-

LCD 16x2 Interfacing With ARM MBED

LCD 16x2
• LCDs (Liquid Crystal Displays) are used in embedded system applications for
displaying various parameters and status of the system.
• LCD 16x2 is a 16-pin device that has 2 rows that can accommodate 16 characters each.
• LCD 16x2 can be used in 4-bit mode or 8-bit mode.
• It is also possible to create custom characters.
• It has 8 data lines and 3 control lines that can be used for control purposes.

• Task-1: Printing “Hello world”

• API Used:

TextLCD(),

• Code for LCD:

#include "mbed.h"

#include "TextLCD.h"

TextLCD lcd(p5, p6, p7, p8, p9, p10);//RS, RW, D4, D5, D6, D7

int main() {

lcd.printf(“Hello World”);

• Task-2: Printing temperature on LCD

• API Used:

TextLCD(), AnalogIn
wait(t) ; where ‘t’ is in seconds

Code :
#include "mbed.h"

#include "TextLCD.h"

TextLCD lcd(p5, p6, p7, p8, p9, p10);//RS, RW, D4, D5, D6, D7

AnalogIn ain(p11);

int i;

float temp,mean;

int main() {

while(1)

int count=0;

float sum=0;

for(i=0;i<100;i++)

temp=ain;

sum+=temp;

count=count+1;

wait(0.1);

mean=sum/count;

lcd.printf("%f",mean);

}
LCD showing temperature

Result- Hence we have interface the LCD as required.


Date: 10/09/2019

EXPERIMENT 8
SPI Interfacing
Verification-

Aim: To establish a SPI between a master peripheral and a slave peripheral


API USED: SPI

TASK 1:

Set the mbed up as Master, and exchanges data with a slave, sending its own switch positions,
and displaying those of the slave using LEDs.
Interfacing between MASTER and SLAVE:
Master code:
#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_wrd |= 0x01;
if(switch_ip2 == 1)
switch_word = switch_wrd |= 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 code:
#include "mbed.h"
SPISlave ser_port(p11,p12,p13,p14);
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:

Master and Slave communication with switches and LEDS

TASK 2:

Display text typed into the MASTER terminal application on to the slave serial terminal.
Code:
Master Mbed Code:

#include "mbed.h"
SPI ser_port(p11,p12,p13);
Serial pc(USBTX,USBRX);
DigitalOut cs(p14);
char recd_val;
char ch;
int main()
{
ch = 0xa0;
while(1)
{
if(pc.readable())
pc.printf(“%c”,ch);
cs = 0;
recd_val = ser_port.write(ch);
cs = 1;
wait(0.01);
recd_val = recd_val & 0x03;
}
}
#include "mbed.h"
SPISlave ser_port(p11,p12,p13,p14);
Serial pc(USBTX,USBRX);
char recd_val;
char ch;

int main()
{
ch = 0xa0;
while(1)
{
if(ser_port.receive())
{
recd_val = ser_port.read();
ser_port.reply(ch);
}
pc.printf(“%
c”,ch);
recd_val =
recd_val &
0x03;
}
}
Output:

Characters typed
in the Master
and Slave Serials
appears on each
others
Terminals.

Inference:
All the tasks have
been executed
and verified.
WEEK-9
CAR PARKING SENSOR
Verification-

AIM: Design a car parking sensor module using ultrasonic sensor.

Interfacing Ultrasonic sensor with mbed board:


The buzzer makes sound whenever the sensor is near to an object. The buzzer is connected to
pin p20 of the mbed board which acts as the output.

Code:
#include "mbed.h"
DigitalOut trigger(p6);
DigitalOut myled(LED1); //monitor trigger
DigitalOut myled2(LED2); //monitor echo
DigitalIn echo(p7);
DigitalOut buzzer(p20);
Serial pc(USBTX,USBRX);
int distance = 0;
int correction = 0;
Timer sonar;

int main()
{
sonar.reset();
// measure actual software polling timer delays
// delay used later in time correction
// start timer
sonar.start();
// min software polling delay to read echo pin
while (echo==2) {};
myled2 = 0;
// stop timer
sonar.stop();
// read timer
correction = sonar.read_us();
printf("Approximate software overhead timer delay is %d uS\n\r",correction);

//Loop to read Sonar distance values, scale, and print


while(1) {
// trigger sonar to send a ping
trigger = 1;
myled = 1;
myled2 = 0;
sonar.reset();
wait_us(10.0);
trigger = 0;
myled = 0;
//wait for echo high
while (echo==0) {};
myled2=echo;
//echo high, so start timer
sonar.start();
//wait for echo low
while (echo==1) {};
//stop timer and read value
sonar.stop();
//subtract software overhead timer delay and scale to cm
distance = (sonar.read_us()-correction)/58.0;
myled2 = 0;
printf(" %d cm \n\r",distance);

//wait so that any echo(s) return before sending another ping


if(distance <5){
buzzer=1;
}else{
buzzer=0;
}
wait(0.2);
}
}

Output:
Output:

Figure shows distance measured by Ultrasonic sensor in TeraTerm Serial monitor


Inference:

We have constructed a Car parking sensor module.


Date: 08/10/2019

WEEK-10
Pedometer

Verification:

AIM: Design a pedometer using accelerometer (ADXL335)

Code:
SPI acc(p11,p12,p13);
DigitalOut cs(p14);
Serial pc(USBTX,USBRX);
char buffer[6];
int16_t data[3];
float x,y,z,temp,temp1;
int Vref=5;
int a=0,b;
int main(){
cs=1;
acc.format(8,3);
acc.frequency(2000000);
cs=0;
acc.write(0x31);
acc.write(0x0B);
cs=1;
cs=0;
acc.write(0x2D);
acc.write(0x08);
cs=1;
while(1)
{
y=0;
wait(0.2);
cs=0;
acc.write(0x80|0x40|0x32);
for(int i=0;i<6;i++){
buffer[i]=acc.write(0x00);
}
cs=1;
temp=y;
temp1=x;
int Vref=5;
data[0]=buffer[1]<<8|buffer[0];
data[1]=buffer[3]<<8|buffer[2];
data[2]=buffer[5]<<8|buffer[4];
x=0.004*data[0];
y=0.004*data[1];
z=0.04*data[2];
if((y-temp)!=0 && (x-temp1)!=0)
{
a+=1;

pc.printf("number of steps: %d\n\r",a);


}
pc.printf("x=%+1.4fm\t y=%+1.4fm\t z=%+1.4fm\n\r",x,y,z);
}
}
Output:

Inference:
We have designed a pedometer.
Date: 18/10/2019

Experiment 11
RTOS
Verification:

Aim:
1. To toggle 2 LEDs using an RTOS thread.
2. To toggle 4 LEDs using an RTOD thread.
Code:
Task 1:
#include "mbed.h"
#include "rtos.h"
DigitalOut led1(LED1);
DigitalOut led2(LED2);

void led2_thread(void const *args)


{
while(1)
{
led2=!led2;
Thread::wait(1000);
}
}
int main() {
Thread thread(led2_thread);
while(1)
{
led1=!led1;
Thread::wait(500);
}
}

Task 2:

#include "mbed.h"
#include "rtos.h"
DigitalOut led1(LED1);
DigitalOut led2(LED2);
DigitalOut led3(LED3);
DigitalOut led4(LED4);

void led2_thread(void const *args)


{
while(1)
{
led2=!led2;
Thread::wait(1000);
}

}
void led3_thread(void const *args)
{
while(1)
{
led3=!led3;
Thread::wait(1500);
}

}
void led4_thread(void const *args)
{
while(1)
{
led4=!led4;
Thread::wait(2000);
}

int main() {
Thread thread2(led2_thread);
Thread thread3(led3_thread);
Thread thread4(led4_thread);

while(1)
{
led1=!led1;
Thread::wait(500);
}
}

Result:
Hence, we have performed the required
experiment.

Potrebbero piacerti anche