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

FALL SEMESTER 2023-2024

ASSESSMENT 3-

PROGRAMME NAME: BTECH COURSE TITLE: EMBEDDED SYSTEMS LAB

CLASS ID- VL2023240100166 FACULTY NAME: PROF. ATHIRA P SHAJI

COURSE CODE: BITE403L CLASS GROUP: UGS04

ISHAN MISHRA 21BIT0138


1.Write an embedded C program to control a traffic light system with three lights: red, yellow, and
green. The lights should switch in the following sequence: red for 10 seconds, yellow for 2 seconds,
and green for 15 seconds. Use Timer/Counter 1 in 16-bit counter mode to keep track of the time
intervals. Assume the lights are connected to P1.0 (red), P1.1 (yellow), and P1.2 (green) pins of the
microcontroller. At the beginning, make all three lights off. Also, compute the initial value of TH1,TL1,
and the status of the Timer/Counter 1 mode register.

Code:

#include <regx51.h>

// Define the time intervals for each light in milliseconds

#define RED_TIME 10000

#define YELLOW_TIME 2000

#define GREEN_TIME 15000

// Function prototypes

void delay_ms(unsigned int milliseconds);

void init_timer();

void main() {

// Set the initial states of the lights to off

P1 = 0x00;

// Initialize Timer/Counter 1

init_timer();

while (1) {

// Red light
P1_0 = 1; // Turn on the red light

delay_ms(RED_TIME);

P1_0 = 0; // Turn off the red light

// Yellow light

P1_1 = 1; // Turn on the yellow light

delay_ms(YELLOW_TIME);

P1_1 = 0; // Turn off the yellow light

// Green light

P1_2 = 1; // Turn on the green light

delay_ms(GREEN_TIME);

P1_2 = 0; // Turn off the green light

// Function to introduce a delay in milliseconds

void delay_ms(unsigned int milliseconds) {

unsigned int i, j;

for (i = 0; i < milliseconds; i++) {

for (j = 0; j < 125; j++) {

// Adjust this loop based on your clock frequency and compiler optimization settings

// Function to initialize Timer/Counter 1 in 16-bit counter mode

void init_timer() {

TMOD &= 0xF0; // Clear the lower 4 bits of TMOD

TMOD |= 0x01; // Set Timer/Counter 1 to 16-bit counter mode


// Compute the initial value of TH1 and TL1 for the desired time intervals

TH1 = (65536 - RED_TIME) >> 8;

TL1 = (65536 - RED_TIME) & 0xFF;

// Set Timer/Counter 1 mode register (TR1) to start the timer

TR1 = 1;

2. Write an embedded C program to control an LED matrix display using a shift register. The LED
matrix consists of 8 rows and 8 columns, and it is connected to a shift register that is controlled by
the microcontroller. The program should continuously display a rotating pattern on the LED matrix.
Each row of the matrix should be lit up one by one, shifting from left to right in a circular motion. Use
Timer/Counter 2 in 8-bit counter mode to control the timing of the display. The LED matrix is
connected to Port 1 of the microcontroller, and the shift register control pins are connected to Port 2.
Also, compute the initial value of TH2, TL2, and the status of the Timer/Counter 2 mode register.

#include <reg51.h> #define LED_MATRIX P0

#define SHIFT_REGISTER_CONTROL P3

unsigned char patterns[8] = {

0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80

};

void delay(unsigned int milliseconds) { unsigned int i;

for (i = 0; i < milliseconds; i++) { TMOD = 0x01;

TH0 = 0xFC; TL0 = 0x67; TR0 = 1;

while (TF0 == 0); TF0 = 0;

TR0 = 0;

void main() {
LED_MATRIX = 0x00;

while (1) { unsigned char i;

for (i = 0; i < 8; i++) { LED_MATRIX = patterns[i]; delay(2000);

3. Design an embedded system for a temperature control system in a greenhouse. The system should
monitor the temperature inside the greenhouse and automatically control a heating or cooling
device to maintain a desired temperature range. The temperature sensor is connected to an analog
input pin of the microcontroller, and the heating/cooling device is controlled using a digital output
pin. The desired temperature range can be set using buttons connected to the microcontroller.
Additionally, the current temperature and the status of the heating/cooling device should be
displayed on an LCD screen. Provide a logical and functional description of the system, including the
required hardware components, their connections, and the software flow. Also, compute the initial
values of any necessary registers or variables.

Logical and Functional Description of Greenhouse Temperature Control System:

1. Hardware Components:

• Microcontroller: Select a microcontroller with analog input, digital output, and LCD
interfacing capabilities (e.g., Arduino, Raspberry Pi, PIC, etc.).

• Temperature Sensor: A temperature sensor (e.g., LM35) to measure the temperature


inside the greenhouse.

• Heating/Cooling Device: A heating or cooling device (e.g., heater, fan, air


conditioner) to control the greenhouse temperature.

• Buttons: Buttons to set the desired temperature range.

• LCD Display: An LCD screen to show the current temperature and the status of the
heating/cooling device.

• Connecting Wires: To connect all the components together.

2. Hardware Connections:

• Connect the temperature sensor's output pin to the microcontroller's analog input
pin.

• Connect the heating/cooling device to the microcontroller's digital output pin.

• Connect the buttons to the microcontroller's digital input pins for setting the desired
temperature range.

• Connect the LCD screen to the microcontroller for displaying the temperature and
device status.

3. Software Flow:

• Initialize the microcontroller and required peripherals (analog input, digital output,
LCD).

• Set the initial desired temperature range using the buttons and store it in a variable.

• Enter the main loop of the program.

• Read the temperature value from the analog input pin using the temperature sensor.

• Compare the current temperature with the desired temperature range.

• If the temperature is below the desired range, activate the heating device (turn it
on).

• If the temperature is above the desired range, activate the cooling device (turn it
on).
• Display the current temperature and the status of the heating/cooling device on the
LCD screen.

• Repeat the above steps continuously to monitor and control the temperature in the
greenhouse.

4. Initial Values:

• Desired Temperature Range: Set the initial desired temperature range using the
buttons and store it in a variable.

• Heating/Cooling Device Status: Set the initial status of the heating/cooling device
(off).

• Temperature Sensor Calibration: Calibrate the temperature sensor and configure the
microcontroller's analog input accordingly.

• Register and Variable Initialization: Initialize any necessary registers or variables for
temperature comparison, button inputs, LCD interfacing, etc.

You might also like