Ajay Marampally
/
allfiles
all files
Revision 0:d44967a3251e, committed 2018-10-28
- Comitter:
- Ajay_Marampally
- Date:
- Sun Oct 28 18:20:46 2018 +0000
- Commit message:
- all files
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r d44967a3251e main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sun Oct 28 18:20:46 2018 +0000 @@ -0,0 +1,1869 @@ +lab 1 + +EMBEDDED SYSTEM DESIGN LAB 1-12 +EXPERIMENT 1 + + + +AIM: + To perform the Following Using mbed LPC11U24 +• To Glow an Internal LED +• To Glow an External LED connected to an IO pin +• To Glow the Internal LED’s in a sequential Order +• Using Switch to Change the Order of Sequential Glowing Of Internal LED’s +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. + +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 + + +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: +1.BLINK AN LED + #include "mbed.h" +DigitalOut myled(LED1); +int main() { + while(1) { + myled = 1; + wait(0.2); + myled = 0; + wait(0.2); + } +} + + + +Output: + + + +2.BLINK 4 LEDS +#include "mbed.h" +DigitalOut myled1(LED1); +DigitalOut myled2(LED2); +DigitalOut myled3(LED3); +DigitalOut myled4(LED4); + +int main() { + while(1) { + myled1= 1; + wait(0.2); + myled1 = 0; + myled2 = 1; + wait(0.2); + myled2= 0; + myled3 = 1; + wait(0.2); + myled3= 0; + myled4 = 1; + wait(0.2); + myled4= 0; + wait(0.2); + } +} + + + + +3.EXTERNAL LEDS BLINKING +#include "mbed.h" +DigitalOut myled(p23); +int main() { + while(1) { + myled = 1; + wait(0.2); + myled = 0; + wait(0.2); +} +} + + + + +4.SWITCHING +#include "mbed.h" + DigitalOut myled(LED1); +DigitalIn Switch(p23); +int main() { + while(1) { + if(Switch==1) + myled = 1; + else + myled=0; + } +} + + +Experiment-2 + + + +AIM: + To write C++ Source Code to understand the digital port access +1. Program mbed Board to light two-two LED’s at a time using BusOut function. +2. Display hexadecimal Coding pattern from 0 to 15 by blinking the on-board LED’s using BusOut function. +3. Read the Multiple Switches values and display the status of switches in Multiple LED’s .If the first two switches are on display 0x55 and if second two switches are on then display 0xAA. Use 4 switches, 8 LED’s. +4. Connect a 7 Segment Display to the mbed Board and write a code to display count from 0 to 9. + +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. + + +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 + + +API Used: + +Syntax used for digital output: +BusOut (PinName pin) + +BusOut variable(LEDn); where n= 1,2,3,4 + +For delay: +wait(t) ; where ‘t’ is in seconds + +1.Program mbed Board to light two-two LED’s at a time using BusOut function +CODE: +#include "mbed.h" +BusOut leds1(LED1,LED2); +BusOut leds2(LED3,LED4); +int main() { + while(1) { + leds1 = 0xFF; + wait(0.2); + leds1 = 0; + wait(0.2); + leds2 = 0xFF; + wait(0.2); + leds2 = 0; + wait(0.2) + } +} + + +2.Display hexadecimal Coding pattern from 0 to 15 by blinking the on-board LED’s using BusOut function. +#include "mbed.h" + BusOut leds(LED1,LED2,LED3,LED4); +int main() { + while(1) { + int i; + for (i=0;i<15;i++) + { + leds=i; + wait(0.5); + } + } +} + + +3.Read the Multiple Switches values and display the status of switches in Multiple LED’s .If the first two switches are on display 0x55 and if second two switches are on then display 0xAA. Use 4 switches, 8 LED’s. + #include "mbed.h" + BusIn switches1(p22,p23); +BusIn switches2(p24,p25); +BusOut leds(LED1,LED2,LED3,LED4); + int main() { + while(1) { + if(switches1==0x03) + leds=0x55; + else if(switches2==0x03) + leds=0xAA; + } +} + + + +4.Connect a 7 Segment Display to the mbed Board and write a code to display count from 0 to 9. +#include "mbed.h" + BusOut leds(LED1,LED2,LED3,LED4,p23,p24,p25); + int main() { + while(1) { + leds=0x7E; + wait(0.5); + leds=0x06; + wait(0.5); + leds=0x4d; + wait(0.5); + leds=0x79; + wait(0.5); + leds=0x33; + wait(0.5); + leds=0x5B; + wait(0.5); + leds=0x5F; + wait(0.5); + leds=0x70; + wait(0.5); + leds=0x7F; + wait(0.5); + leds=0x7B; + wait(0.5); + } + } + + + + +Verification: + + + + + + +EXPERIMENT-3 + + + + +AIM: + To perform the Following Using mbed LPC11U24 +1.Write a serial program to dispay a message to pc. +2. Write a program to dispay the corresponding character you type in serial window. +3.Monitor the status of a switch connected to pin5, if high write “hello” to the pc and blink led1 otherwise write “sorry” to the pc and led1 is off. +4. Write a serial program to use the ‘Y’ and ‘N’ keys from pc to make leds on the mbed board to display ‘A’ and ‘5’. + +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. + +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 + + + + +API Used: + +Syntax used for serial communication: + +serial variable(USBTX,USBRX); + +For printing: +pc.printf("sale please"); + + + +1.write a serial program to dispay a message to pc. +Code: +#include "mbed.h" +Serial pc(USBTX,USBRX); + +int main() +{ + pc.printf("sale please"); + while(1) + { + pc.putc(pc.getc()); + // pc.printf("sale please"); + } + + } + + + + +2. write a program to dispay the corresponding character you type in serial window. +Code: +#include "mbed.h" +Serial pc(USBTX,USBRX); + +int main() +{ + pc.printf("sale please"); + while(1) + { + pc.putc(pc.getc()); + // pc.printf("sale please"); + } + + } + + + +3.Monitor the status of a switch connected to pin5, if high write “hello” to the pc and blink led1 otherwise write “sorry” to the pc and led1 is off. +Code: + +#include "mbed.h" +Serial pc(USBTX,USBRX); +DigitalOut led(LED1); +DigitalIn sw(p5); +int main() +{ + while(1) + { + if(sw==1) + { + led=1; + wait(0.5); + led=0; + + pc.printf("Hello"); + } + else{ + led=0; + + pc.printf("sorry"); + } + + } + + } + + + + + + + +4. Write a serial program to use the ‘Y’ and ‘N’ keys from pc to make leds on the mbed board to display ‘A’ and ‘5’. + +Code : + #include "mbed.h" + +Serial pc(USBTX, USBRX); +BusOut myled(LED1, LED2, LED3, LED4); + +int main() { + while(1){ + if(pc.getc()=='Y') + { + + myled = 0x0A; + + } + else if(pc.getc()=='N') + { + + myled = 0x05; + + } + else + { + myled=0; + } + } +} + + +When ‘N’ is pressed: + +When ‘Y’ is pressed: + +Verification: + + + + + + + + + + + + + + + + + + + + EXPERIMENT-4 + + + + +Aim: +To perform the Following Using mbed LPC11U24 +1.attach a potentiometer to mbedpin 20. + Start a new mbed project and enter the code below.this code will continuously display the analog input value when used with a host pc terminal application. +2.using the 4 onboard mbed leds,write a program that will use potentiometer input on pin20 to continuously control how many leds are on.use the following chart to define the led +Control: + LED1 LED2 LED3 LED4 +X<=0.2 0 0 0 0 +0.2<X<=0.4 1 0 0 0 +0.4<X<=0.6 1 1 0 0 +0.6<X<=0.8 1 1 1 0 +0.8<X<=1 1 1 1 1 + +3. . Design, build and program a simple embedded system using an LM35 sensor, which displays temperature on the computer screen. This device has an output of 10 mV/C, with operating temperature from 55C to 150C + + + + + + + +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. + +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 + +API Used: + +Syntax used for analog input: + +AnalogIn variable(pin); + + + +Code: +1. +#include "mbed.h" +Serial pc(USBTX ,USBRX); +AnalogIn A(p20); + float Ain=A; +int main() +{ + while(1) +{ + pc.printf("%f the value is ",Ain*3.3); + wait(0.5); + } + } + + + +2. +#include "mbed.h" +AnalogIn A(p20); +BusOut leds (LED1,LED2,LED3,LED4); +int main() +{ + while(1) +{ + float Ain=A; + wait(0.5); + if(Ain<=0.2) + leds=0; + else if(Ain>0.2 & Ain<=0.4) + leds=0x08; + else if(Ain>0.4 & Ain<=0.6) + leds=0x0C; + else if(Ain>0.6 & Ain<=0.8) + leds=0x0E; + else if(Ain>0.8 & Ain<=1.0) + leds=0x0F; + } + } + + + + + +3. +#include "mbed.h" +Serial pc(USBTX ,USBRX); +AnalogIn A(p20); +int main() +{ + while(1) +{ + float Ain=A; + pc.printf("%f the value is ",(Ain*3.3)*100); + wait(0.2); + } + } + + + + + +Verification: + + + + EXPERIMENT 5 + PULSE WIDTH MODULATION +AIM: +To perform the Following Using mbed LPC11U24 +•Create a PWM signal which will generate a 100 Hz pulse with 50% duty cycle. +•Change the duty cycle to some different values, say 0.2 (20%) and 0.8 (80%) and check the correct display. +•Controlling LED brightness with PWM +•This exercise uses a pulse width modulation signal to increase and decrease the brightness of the onboard LED The program requires the use of a host terminal application to communicate the brightness value to the mbed, in this example by using the ‘u’ and ‘d’ keys. +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. + +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 +• + +API Used: +For serial communication port access: +Serial pc(USBTX, USBRX); where the arguments are the transmitting or receiving pins +Serial device( pin tx, pin rx, int baud) +For printing : +pc.printf(“”); to print a string +pc.putc(); to print a character +Syntax used for PWM signal generation +PwmOut (PinName pin) +For delay: +wait(t) ; where ‘t’ is in seconds +For LED: +Led.write(); Led.read(); Led.period(); +For getting analog input: +Analogin a(pin) +For delay: +wait(t) ; where ‘t’ is in seconds + +1. 1. Create a PWM signal which will generate a 100 Hz pulse with 50% duty cycle. +CODE: +#include "mbed.h" + +PwmOut led(p5); + +int main() { + //specify time period first, then everything else + led.period(0.5); + led.write(0.5); + while(1); +} + } + +Output: + + + +2. Change the duty cycle to some different values, say 0.2 (20%) and 0.8 (80%) and check the correct display. + +CODE: +80 % duty cycle +#include "mbed.h" + +PwmOut led(p5); + +int main() { + + led.period(0.1); + led.pulsewidth(0.8); + while(1); +} + + + + +20 % duty cycle +#include "mbed.h" + +PwmOut led(p5); + +int main() { + + led.period(0.1); + led.pulsewidth(0.2); + while(1); +} + + + + +Output: + + + + + + + +3. Controlling LED brightness with PWM. +CODE: + +#include "mbed.h" + +PwmOut led(p5); +float brightness=0.0; + +int main() { + while(1) + { + while(brightness<1) + { + brightness+=0.1; + led=brightness; + wait(0.2); + } + while (brightness>0) + { + brightness-=0.1; + led=brightness; + wait(0.2); + } + } +} + + +Output: + +4. This exercise uses a pulse width modulation signal to increase and decrease the brightness of the onboard LED The program requires the use of a host terminal application to communicate the brightness value to the mbed, in this example by using the ‘u’ and ‘d’ keys. + +Code: + + +#include "mbed.h" +Serial pc(USBTX, USBRX); +PwmOut led(p5); +float brightness=0.0; + +int main() { + while(1) + { + if(pc.getc()=='u') + { + brightness+=0.2; + led=brightness; + } + else if(pc.getc()=='d') + { + brightness-=0.2; + led=brightness; + } + } +} + + +Output: + + + + + + + + + + + + + + +Verification + + +Result: +PWM is implemented and verified in LPC11U24. + +EMBEDDED SYSTEM DESIGN LAB + EXPERIMENT 6 + CONTROLLING SERVO WITH PWM +AIM: + To perform the Following Using mbed LPC11U24 +• To control a server motor using PWM. +• Light tracking devices are very important for the capture of solar energy. Often, they operate in 3 dimensions, and tilt a solar panel so that it is facing the sun as accurately as possible. To start rather more simply, create a 2D light tracker by fitting 2 LDRs, angled array from each other by 90 to 180 by a servo motor connected to the LDRs using the circuit in the figure to two ADC inputs. Write a program that reads the light value sensed by the 2 LDRs and rotates the servo motor such that each is receiving equal light. The servo can only rotate 180o. This is not, however, unrenewable, as a sun tracking system will be located to track the sun from sunrise to sunset, i.e, not more than 180o. Display the position of the servomotor in the serial of the 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. + +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 + +API Used: + +Syntax used for PWM signal generation +PwmOut (PinName pin) + +For delay: +wait(t) ; where ‘t’ is in seconds + +For LED: +Led.write(); Led.read(); Led.period(); + + +For getting analog input: +Analogin a(pin) +For delay: +wait(t) ; where ‘t’ is in seconds + + + + + + + + + + + + + + + + +5. To control a server motor using PWM. +CODE: + #include "mbed.h" +PwmOut ser(p6); +AnalogIn pot(p5); +int main() +{ +float i; +ser.period(20); +while(1) +{ +if(pot==0) +{ +for(i=0;i<1;i=i+0.25) +ser.pulsewidth_ms(1.25*i); +} +else +{ +for(i=1;i>0;i=i-0.25) +ser.pulsewidth_ms(1.25*i); +} + +} + + +Output: + + +6. Light tracking devices are very important for the capture of solar energy. Often, they operate in 3 dimensions, and tilt a solar panel so that it is facing the sun as accurately as possible. To start rather more simply, create a 2D light tracker by fitting 2 LDRs, angled array from each other by 90 to 180 by a servo motor connected to the LDRs using the circuit in the figure to two ADC inputs. Write a program that reads the light value sensed by the 2 LDRs and rotates the servo motor such that each is receiving equal light. The servo can only rotate 180o. This is not, however, unrenewable, as a sun tracking system will be located to track the sun from sunrise to sunset, i.e, not more than 180o +CODE: +#include "mbed.h" +AnalogIn ldr1(p7); +AnalogIn ldr2(p6); +PwmOut servo(p20); + +int main() { + + servo.period_ms(20); + float i = 1.25; + while(1) { + //servo.pulsewidth(1.25); + while(ldr1!=ldr2) { + if(ldr1<ldr2) + servo.pulsewidth(i+0.25); + else + servo.pulsewidth(i-0.25); + + } + } +} + +Output: + + + +Verification + + +Result: +The servo is controlled with PWM. + + + + + + + + + +EMBEDDED SYSTEM DESIGN LAB + EXPERIMENT 7 + TIMERS AND COUNTERS +AIM: + To perform the Following Using mbed LPC11U24 +• Write a code with a help if the timer to measure the time taken to write a message on the screen, and display the time taken as the message. +• Create a square ware (400ms) output using scheduled programming and verify the timing accuracy with an oscilloscope. +• When the interrupt is activated, by this rising edge, the ISR executes and LED1 is toggled. This can occur at any time in the program execution. The program has effectively one time triggered task, the switching of the LED4 and one event triggered task, the switching of LEDs. +• Use the mbed interrupt In library to toggle an LED whenever a digital input goes high, implementing a debounce counter to avoid multiple interrupts. + +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. + +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 + +API Used: + +Syntax used for trimer: +Timer (PinName pin) + +Syntax used for interrupt: +InterruptIn (PinName pin) + +For delay: +wait(t) ; where ‘t’ is in seconds + +For LED: +Led.write(); Led.read(); Led.period(); + + + + + + + + + + + + + + + + + + + +1. Write a code with a help if the timer to measure the time taken to write a message on the screen, and display the time taken as the message. +CODE: +#include "mbed.h" + +Timer t; +Serial pc(USBTX,USBRX); + +int main() { + t.start(); + pc.printf("Hey"); + t.stop(); + pc.printf("The time taken was %f seconds\n", t.read()); +} + + + +Output: + + + +2. Create a square ware (400ms) output using scheduled programming and verify the timing accuracy with an oscilloscope. +CODE: +#include "mbed.h" + +Timer t; +DigitalOut sqr(p7); + +int main() { + while(1) + { + t.start(); + sqr=1; + if (t.read_ms()==200) + { + t.stop(); + } + t.start(); + sqr=0; + if (t.read_ms()==200) + { + t.stop(); + } + } +} + +Output: + + + + + +3. When the interrupt is activated, by this rising edge, the ISR executes and LED1 is toggled. This can occur at any time in the program execution. The program has effectively one time triggered task, the switching of the LED4 and one event triggered task, the switching of LEDs. +CODE: +InterruptIn button(p5); +DigitalOut led(LED1); +DigitalOut flash(LED4); + +void flip() { + led = !led; +} + +int main() { + button.rise(&flip); + while(1) { + flash = !flash; + wait(0.25); + } +} + + +Output: + + + + + +4. Use the mbed interrupt In library to toggle an LED whenever a digital input goes high, implementing a debounce counter to avoid multiple interrupts. +CODE: +#include "mbed.h" + +Timer debounce; +InterruptIn button(p18); +DigitalOut led1(p5); + +void toggle(void); +int main(){ + debounce.start(); + button.rise(&toggle); + } +void toggle(){ + if(debounce.read_ms()>200) + led1=!led1; + debounce.reset(); + } + + +Output: + + +Verification + + +Result: +The working of timer and counter is verified. + + + + + +EMBEDDED SYSTEM DESIGN LAB + EXPERIMENT 8 + INTERFACING BLUETOOTH MODULE HC-05 +AIM:a + To perform the Following Using mbed LPC11U24 +• Transmit any character or string from smartphone via Bluetooth to the ARM board and toggle LED1 of mbed board. +• Design, Build and program a simple embedded system using LM35 Sensor which displays temperature on the phone using Bluetooth 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. + +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 + +API Used: + + For Bluetooth + Serial blue(p9,p10); + +For delay: +wait(t) ; where ‘t’ is in seconds + +For LED: +Led.write(); Led.read(); Led.period(); + + Serial communication: + Serial pc(USBTX, USBRX); // tx, rx + + + +1. Transmit any character or string from smartphone via Bluetooth to the ARM board and toggle LED1 of mbed board. + CODE: + #include "mbed.h" +Serial pc(USBTX, USBRX); +Serial blue(p9, p10); +DigitalOut myled(LED1); +int main() +{ + blue.baud(115200); + pc.baud(115200); + pc.printf("Bluetooth Start\r\n"); + // echo back characters and toggle the LED + while (1) + { + if (blue.readable()) + { + pc.putc(blue.getc()); + myled = !myled; + } + } +} + + + +Output: + + + + + + + +2. Design, Build and program a simple embedded system using LM35 Sensor which displays temperature on the phone using Bluetooth terminal. + CODE: + #include "mbed.h" +Serial pc(USBTX, USBRX); +Serial blue(p9, p10); +AnalogIn temp(p5); +int main() +{ + blue.baud(9600); + pc.baud(9600); + while (1) + { float t=temp*3.3*100; + if (pc.readable()) + { blue.printf("The temperature is "); + blue.putc(t); + } + } +} + + + + + + +Output: + + + +Verification + + + +Result: +Bluetooth is interfaced and its working is verified. + + + + +EMBEDDED SYSTEM DESIGN LAB + EXPERIMENT 9 + SPI USING LPC11U24 +AIM: + To perform the Following Using mbed LPC11U24 +• Set the mbed board as a master and exchange data with a slave, sending its own switch position and display that of slave. +• Set the mbed board as a slave and exchange data with a master, sending its own switch position and display that of master. +• Display the text typed into the terminal application of the slave terminal. Use # key to clear the screen of the text u have written. + +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. + +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 + +API Used: + +Syntax used for digital input: +DigitalIn switch_ip1(p5); + +Digital output: +DigitalOut led1(LED1); + +SPI master: +SPI ser_port(p11,p12,p13);//mosi,miso,sclk + +SPI slave: +SPISlave ser_port(p11,p12,p13,p14);//mosi,miso,sclk +For delay: +wait(t) ; where ‘t’ is in seconds + + Serial communication: + Serial pc(USBTX, USBRX); // tx, rx + + + +1. Set the mbed board as a master and exchange data with a slave, sending its own switch position and display that of slave. +CODE: +#include "mbed.h" +SPI ser_port(p11,p12,p13);//mosi,miso,sclk +DigitalOut led1(LED1);//led +DigitalOut led2(LED2);//led +DigitalOut cs(p14);//this acts as "slave select" +DigitalIn switch_ip1(p7); +DigitalIn switch_ip2(p8); +char switch_word;//word we will send +char recd_val;//value return from slave +int main() { + while(1) { + //Default settings for SPI Master chosen, no need for further configuration + //Set up word to be sent, by testing switch inputs + switch_word=0xa0;//set up a recognisable output pattern + if (switch_ip1==1) + switch_word=switch_word|0x01;//OR in lsb + if (switch_ip2==1) + switch_word=switch_word|0x02;//OR in next lsb + cs=0;//select slave + recd_val=ser_port.write(switch_word);//send switch_word and receive data + cs=1; + wait(0.01); + //set leds according to incoming word from slave + led1=0;//preset both to 0 + led2=0; + recd_val=recd_val&0x03;//AND out unwanted bits + if(recd_val==1) + led1=1; + if(recd_val==2) + led2=1; + if(recd_val==3) + { + led1=1; + led2=1; + } + } +} + + + + + + + +2. Set the mbed board as a slave and exchange data with a master, sending its own switch position and display that of master. +CODE: +#include "mbed.h" +SPISlave ser_port(p11,p12,p13,p14);//mosi,miso,sclk +DigitalOut led1(LED1);//led +DigitalOut led2(LED2);//led +DigitalIn switch_ip1(p5); +DigitalIn switch_ip2(p6); +char switch_word;//word we will send +char recd_val;//value return from slave +int main() { + //default formatting applied + while(1) { + //set up switch_word from switches that are pressed + switch_word=0xa0;//set up a recognizable outout pattern + if (switch_ip1==1) + switch_word=switch_word|0x01; + if (switch_ip2==1) + switch_word=switch_word|0x02; + if (ser_port.receive()) + {//test if data transfer has occured + recd_val=ser_port.read();//Read byte from master + ser_port.reply(switch_word);//Make this the next reply + } + 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: + + + + +3. Display the text typed into the terminal application of the slave terminal. Use # key to clear the screen of the text u have written. +MASTER CODE: +#include "mbed.h" +SPI spi(p11,p12,p13,p14); // mosi, miso, sclk +DigitalOut cs(p8); +Serial pc(USBTX, USBRX); // tx, rx +char a; +int main() +{ + while(1) + { + //pc.printf("Enter char: "); + a=pc.getc(); + pc.printf("%c",a); + cs=0; + spi.write(a); + cs=1; + } +} + + + + SLAVE CODE: + #include "mbed.h" +SPISlave device(p11, p12, p13, p14); +Serial pc(USBTX, USBRX); +int main() { +while (1) { +if (device.receive()) { +char v = device.read(); +pc.printf("%c",v); +if (v =='#') +pc.printf("/b"); +} +} + + +Output: + + +Master: + +Slave: + + + +Verification + + + +Result: +SPI protocol is implemented and verified. + + + + +ECE 4003 EMBEDDED SYSTEM DESIGN +EXPERIMENT 10 + I2C Interface + +SOFTWARE USED: +Arm Mbed OS developer site +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. + +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 + + +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 + + +Ex. 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. + +MASTER: +//Master +#include <mbed.h> +Serial pc(USBTX, USBRX); +I2CSlave slave(p28, p27); +int main() +{ + char buf[20]; + char msg[] = "Slave!"; + slave.address(0xA0); + while (1) { + int i = slave.receive(); + switch (i) { + case I2CSlave::ReadAddressed: + slave.write(msg, strlen(msg) + 1); // Includes null char + break; + case I2CSlave::WriteGeneral: + slave.read(buf, 20); + pc.printf("Read : %s\n", buf); + break; + case I2CSlave::WriteAddressed: + slave.read(buf, 20); + pc.printf("Read : %s\n", buf); + break; + } + for(int i = 0; i< 20; i++) + buf[i] = 0; + } + + + + + +Slave +//Slave +#include "mbed.h" +Serial pc (USBTX,USBRX); +I2C i2c(p28, p27); + +int main() +{ + int address = 0xA0; + char data[20]; + pc.printf("enter data to be sent"); + pc.scanf("%s",&data); + pc.printf("%s",data); + int l=strlen(data); + i2c.write(address, data, l); + wait(10); +} + + + +Ex.2 +I2C Master, transfers switch state to second mbed acting as slave, and displays state of slave’s switches on its leds. +Master: +#include "mbed.h" +I2C i2c_port(p27,p28); +DigitalOut led1(LED1); +DigitalOut led2(LED2); +DigitalIn switch_ip1(p5); +DigitalIn switch_ip2(p6); +char switch_word; +char recd_val +const int addr=0x52; +int main() +{ + while(1) { + switch_word=0xa0; + if (switch_ip1==1) + switch_word=switch_word|0x01; + if (switch_ip1==2) + switch_word=switch_word|0x02; + i2c_port.start(); //force a start condition + i2c_port.write(addr); //send the address + i2c_port.write(switch_word); //send one byte of data, ie switch_word + i2c_port.stop(); //force a stop condition + wait(0.002); +//receive a single byte of data, in correct I2C package + i2c_port.start(); + i2c_port.write(addr|0x01); //send address, with R/W bit set to Read + recd_val=i2c_port.read(addr); //Read and save the received byte + i2c_port.stop(); //force a stop condition + led1=0; + led2=0; + recd_val=recd_val&0x03; + if(recd_value==1) + led1=1; + if (recd_val==2) + led2=1; + if (recd_val==3) { + led1=1; + led2=1; + } + } +} + + + + + + + + + + +Ex.3 +I2C Slave, when called transfers switch state to mbed acting as Master, and displays state of Master’s switches on its leds. + +#include "mbed.h" +I2CSlave i2c_port(p27,p28); +DigitalOut led1(LED1); +DigitalOut led2(LED2); +DigitalIn switch_ip1(p5); +DigitalIn switch_ip2(p6); +char switch_word; +char recd_val +int main() +{ slave.address(0x52); + while(1) { + switch_word=0xa0; + if (switch_ip1==1) + switch_word=switch_word|0x01; + if (switch_ip1==2) + switch_word=switch_word|0x02; + slave.write(switch_word); + int i=slave.receive(): + if(i==3) + recd_val=slave.read(); + led1=0; + led2=0; + recd_val=recd_val&0x03; + if(recd_value==1) + led1=1; + if (recd_val==2) + led2=1; + if (recd_val==3) { + led1=1; + led2=1; + } + } +} + +Result: +I2C protocol is implemented and verified. + +EMBEDDED SYSTEM DESIGN LAB +EXPERIMENT 11 + INTERFACING LCD WITH LPC11U24 +AIM: + To perform the Following Using mbed LPC11U24 +• Write an Modular c++ program to display the ,essage “HELLO” on LCD display. +• Write a C++ program by using TextLCD library to display a message “Hello World”. +• Display a continuous count variable o the LCD display 2nd row 5th digit. + +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. + +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 + +API Used: + + +Digital output: +DigitalOut led1(LED1); + +LCD defining: +TextLCD lcd(p19, p20, p21, p22, p23, p24); //rs,e,d0,d1,d2,d3 + +Print in LCD: +lcd.printf("Hello World!"); + +For delay: +wait(t) ; where ‘t’ is in seconds + +1. Write an Modular c++ program to display the ,essage “HELLO” on LCD display. +CODE: +// LCD.cpp file +#include "LCD.h" +DigitalOut RS(p19); +DigitalOut E(p20); +BusOut data(p21, p22, p23, p24); +void toggle_enable(void){ +E=1; +wait(0.001); + E=0; +wait(0.001); +}//initialise LCD function +void LCD_init(void) +{ +wait(0.02); +RS=0; +E=0;//function node +data=0x2; +toggle_enable(); //display mode +data=0x0; +toggle_enable(); +data=0xF; +toggle_enable(); //clear display +data=0x0; +toggle_enable() ; +data=0x1; +toggle_enable(); +} +void display_to_LCD(char value) //display function +{ +RS=1; +data=value>>4; +toggle_enable(); +data=value&0x0F; +toggle_enable(); +} + + +//LCD.h FIle +#ifndef LCD_H +#define LCD_H +#include "mbed.h" + + +void display_to_LCD(char value); +void toggle_enable(void); +void LCD_init(void); + +#endif + + +#include "mbed.h" +#include "LCD.h" +//DigitalOut vo(p18); + +int main() +{ +//vo = 0.5; +LCD_init(); +display_to_LCD(0x48); // ‘H’ +display_to_LCD(0x45); // ‘E’ +display_to_LCD(0x4C); // ‘L’ +display_to_LCD(0x4C); // ‘L’ +display_to_LCD(0x4F); // ‘O’ +} + + + +Output: + + + + + + + + + + +2. Write a C++ program by using TextLCD library to display a message “Hello World”. +CODE: +#include "mbed.h" +#include "TextLCD.h" +TextLCD lcd(p19, p20, p21, p22, p23, p24); //rs,e,d0,d1,d2,d3 +int main() +{ +lcd.printf("Hello World!"); +} + +Output: + + + + + + + + + + +3. Display a continuous count variable o the LCD display 2nd row 5th digit. + + CODE: +#include "mbed.h" +#include "TextLCD.h" +TextLCD lcd(p19, p20, p21, p22, p23, p24); +//rs,e,d0,d1,d2,d3 +int t=0; +int main() +{ + while(t<=50) + { lcd.locate(4,2); + + t=t+1; + lcd.printf("%d",t); + wait(0.5); + } +} + + + + + + + + +Output: + + + +Verification + + + +Result: +Interfacing LCD with LPC11U24 is done and verified. + + + + + + +EMBEDDED SYSTEM DESIGN LAB + EXPERIMENT 12 + IMPLEMENTING RTOS FUNCTIONS WITH LPC11U24 +AIM: + To perform the Following Using mbed LPC11U24 +• Creating and Controlling a Simple thread. +• Create two threads (blinking two sets of LEDS) with different priorities and display the priorities on PC. +• Write a program to use MUTEX to protect printf(). + +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. + +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 + +API Used: + + +Initializing a thread: +Thread thread; + +Starting a thread: +thread.start(led2_thread); + +To set priority to a pointer object of thread: +test->set_priority(osPriorityHigh); + +To get priority to a pointer object of thread: +test->get_priority(); + +For delay: +wait(t) ; where ‘t’ is in seconds +Thread::wait(500); + + Defining a Mutex + Mutex stdio_mutex; + + Locking a Mutex + stdio_mutex.lock(); + + Unlocking a Mutex + stdio_mutex.unlock(); + + + + + + + + + + + + +4. Creating and Controlling a Simple thread. +CODE: +#include "mbed.h" +#include "rtos.h" +DigitalOut led1(LED1); +DigitalOut led2(LED2); +Thread thread; +void led2_thread() { + while (true) { + led2 = !led2; + wait(0.5); + } +} +int main() { + + +thread.start(led2_thread); + +while (true) { + led1 = !led1; + wait(0.5); + } +} + + +Output: + + + + +5. Create two threads (blinking two sets of LEDS) with different priorities and display the priorities on PC. +CODE: +#include "mbed.h" +#include "rtos.h" +DigitalOut led1(LED1); +DigitalOut led2(LED2); +DigitalOut led3(LED3); +DigitalOut led4(LED4); +Serial pc(USBTX, USBRX); // tx, rx +Thread *(test); +void led2_thread(void const *args) { + while (true) { + led2 = !led2; + + Thread::wait(1000); + } + } + void led4_thread1(void const *args) { + while (true) { + led4 = !led4; + + Thread::wait(1000); + } +} +int main() { + char ch; + Thread thread(led2_thread); + test = &thread; + test->set_priority(osPriorityHigh); + ch=test->get_priority(); + pc.printf("%i\n\r",ch); + + Thread thread1(led4_thread1); + test = &thread; + test->set_priority(osPriorityLow); + pc.printf("%i\n\r",test->get_priority()); + + while (true) { + led1 = !led1; + led3 = !led3; + Thread::wait(500); + } + + +} + + +Output: + + + + + +6. Write a program to use MUTEX to protect printf(). + + CODE: +#include "mbed.h" +#include "rtos.h" +Mutex stdio_mutex; +Thread t2; +Thread t3; +void notify(const char* name, int state) { + stdio_mutex.lock(); + printf("%s: %d\n\r", name, state); + stdio_mutex.unlock(); +} +void test_thread(void const *args) { + while (true) { + notify((const char*)args, 0); wait(1); + notify((const char*)args, 1); wait(1); + } +} + +int main() { + t2.start(callback(test_thread, (void *)"Th 2")); + t3.start(callback(test_thread, (void *)"Th 3")); + test_thread((void *)"Th 1"); +} + + +Output: + + + + +Verification + + + +Result: +RTOS functions are verified using mbed LPC11U24. +
diff -r 000000000000 -r d44967a3251e mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sun Oct 28 18:20:46 2018 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/e95d10626187 \ No newline at end of file