Embedded System Design

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

School of Electronics Engineering (SENSE)

B. Tech – Electronics & Computer Engineering

BECE403E – EMBEDDED SYSTEM DESIGN


LAB RECORD
(L15+L16)

Submitted By
21BLC1603 – DARSHNI B

Submitted To
Dr. SOFANA REKA
DATE: 21/02/2024

[21BLC1603] BECE403E- Embedded Systems Design Lab Page No: 1


Slot: L15+L16

Date: 21/02/2024

LAB – 05: Working with LCD


AIM:
To understand how the LCD works with STM32 Nucleo-64 using a breadboard
Lab Task-1: Write a program for 16x2 LCD to display your register number (ex: “21BLC1603”) at row-0
3rd position and your name (ex:“DARSHNI”) at beginning of the row-1. Assume LCD operates in 4-
bit with EN and RS active state. Design and verify this logic on Nucleo 152RE board using online Keil
Studio platform.
Lab Task-2: Write a program to display a continuous count variable value on the LCD display on row-1
5th position. Assume LCD operates in 4-bit with EN and RS active state. Design and verify this logic on
Nucleo 152RE board using online Keil Studio platform.
Lab Task- 3: Write a program to display the potentiometer value with 4 decimal places on the LCD
display on row-1 5th position. Assume LCD operates in 4 bit with EN and RS active state. Design and
verify this logic on Nucleo 152RE board using online Keil Studio Platform
Challanging Task:
Automatic room temperature control system
Write a program to design a automatic room temperature control system to monitor the room temperature
using LM35 sensor and display its value on LCD display. Whenever the room temperature crosses 32°C
the
system must switch ON the Fan (DC motor) to control the room temperature. Once the temperature goes
below 32°C Fan must be switch OFF automatically. Assume LCD operates in 4-bit with EN and RS active
state. Design and verify this logic on Nucleo-152RE board using online Keil Studio platform.

Software Required: ARM Keil Studio (Mbed Online Compiler), Tera Term

Hardware Required: Micro USB cable, NUCLEO64-STM32L152 Board, LEDs, Jumper Wires (F-F, M-F
and M-M), Breadboard, Potentiometer(s), LCD
Procedure:
1. Go to ARM Keil Studio (https://studio.keil.arm.com) and log in
2. Select File → New → Mbed Project
3. Click the Example project drop-down list and select “mbed2-example-blinky”

[21BLC1603] BECE403E- Embedded Systems Design Lab Page No: 2


4. In Project name field, provide the name of the new project and click Add project
5. Double click on the “main.cpp” file from the newly created project folder
6. Modify the code in the editor window as per the logic of your application
7. Check for any errors in the program under the “Problems” tab of the panels window
8. If no errors, connect the Nucleo Board to the computer using Micro USB Cable
9. Connect the LCD’s pins to the breadboard.
10. Connect the wires and switches as per the pin diagram and the port numbers used in the
program.
11. Open Tera Term and select the port (COM6, in general) where STM32 is connected.
12. Ensure the connectivity of LEDs, ground, and potentiometer(s) in the breadboard.
13. Click Play icon (Run project) to upload and start the code execution on the board.

PROGRAM:
Lab Task 1

#include "mbed.h"
#include "TextLCD.h"
TextLCD lcd(PC_0,PC_1,PB_0,PA_4, PA_1, PA_0); // rs, e, d4-d7
int main()
{
lcd.locate(3,0);
lcd.printf("21BLC1603\n");
lcd.locate(0,1);
lcd.printf("DARSHNI\n");
}

Output:

[21BLC1603] BECE403E- Embedded Systems Design Lab Page No: 3


Fig.1: Displaying Name and Reg. No in LCD

INFERENCE:
From the program, we understood how to send data to each row of LCD.

PROGRAM:
Lab Task 2

1
#include "mbed.h"
#include "TextLCD.h"
TextLCD lcd(PC_0,PC_1,PB_0,PA_4, PA_1, PA_0); // rs, e, d4-d7
int main()
{
int a=0;
lcd.cls();
while (1) {
lcd.locate(5, 1);
lcd.printf("%d", a);
wait(1);
a++;
}
}

Output:

[21BLC1603] BECE403E- Embedded Systems Design Lab Page No: 4


Fig.2: “29” is displayed in LCD

Fig.3: “30” is displayed in LCD

INFERENCE:
From the program, we understood how to repeatedly update a value and continuously display it in
LCD.

PROGRAM:
Lab Task 2
#include "mbed.h"
#include "TextLCD.h"
TextLCD lcd(PC_0,PC_1,PB_0,PA_4,PA_1,PA_0);
Serial pc(USBTX,USBRX);

[21BLC1603] BECE403E- Embedded Systems Design Lab Page No: 5


int main()
{
lcd.cls();
while(1) {
char in = pc.getc();
lcd.printf("%c",in);
}
}

Output:

Fig.4: Typing “hello


world” in Tera Term
and displaying it in
LCD.

INFERENCE:
From the program, we implemented input from Tera Term and to display the output on the LCD.

Lab Task 3:

PROGRAM:
Task 3
#include "mbed.h"
#include "TextLCD.h"
AnalogIn ain(PC_5);
TextLCD lcd(PC_0,PC_1,PB_0,PA_4,PA_1,PA_0); // rs,e,d4-d7
int main()

[21BLC1603] BECE403E- Embedded Systems Design Lab Page No: 6


{
lcd.cls();
while(1) {
float value = ain*5;
lcd.locate(5,0);
lcd.printf("v = %0.3f",value);
wait(2);
lcd.cls();
wait(1);
}
}

Output:

Fig.5: Changing
potentiometer to less value

[21BLC1603] BECE403E- Embedded Systems Design Lab Page No: 7


Fig.6: Changing
potentiometer to higher
value

INFERENCE:
From the program, we successfully learnt to read the output of a potentiometer and display the voltage
on LCD.
CHALLENGING TASK :
Write a program to design a automatic room temperature control system to monitor the room temperature
using LM35 sensor and display its value on LCD display. Whenever the room temperature crosses 32°C
the system must switch ON the Fan (DC motor) to control the room temperature. Once the temperature
goes below 32°C Fan must be switch OFF automatically. Assume LCD operates in 4-bit with EN and RS
active state. Design and verify this logic on Nucleo-152RE board using online Keil Studio platform.
CODE:
#include "mbed.h"
#include "TextLCD.h"
AnalogIn ain(PC_3);
TextLCD lcd(PC_0,PC_1,PB_0,PA_4,PA_1,PA_0); // rs,e,d4-d7
DigitalOut FAN(PC_8);
int main()
{

while(1) {
float sensorvalue = ain;
float vout = sensorvalue*50;
float tempc=vout*100;
lcd.cls();
lcd.locate(3,0);
lcd.printf("Temp = %0.2f",tempc);
if(tempc > 32.00){

[21BLC1603] BECE403E- Embedded Systems Design Lab Page No: 8


FAN=1;
lcd.locate(5,1);
lcd.printf("FAN On");
}
else{
FAN=0;
lcd.locate(5,1);
lcd.printf("FAN OFF");
}
wait(1);
}
}

}
Output Verification:

INFERENCE :
Thus automatic room temperature control system,
RESULT:
TASK 1:
Displayed name and registration number on the LCD display.
TASK 2:
Repeatedly updated the value on LCD display
TASK 3:

read the output of a potentiometer and displayed the voltage on LCD.

TASK 4:

[21BLC1603] BECE403E- Embedded Systems Design Lab Page No: 9


displaying the precise temperature reading on an LCD display with two decimal places. The system
intelligently activates a fan whenever the temperature surpasses the 32°C threshold within the room. This
is indicated on the LCD screen with the message "FAN On". Conversely, when the temperature falls
below 32°C, the fan is automatically deactivated, and the LCD displays "FAN OFF", signifying the
cessation of fan operation. Thus, the code was successfully executed and verified.

[21BLC1603] BECE403E- Embedded Systems Design Lab Page No: 10

You might also like