Professional Documents
Culture Documents
IOT Da3
IOT Da3
ASSESSMENT 3-
Code:
#include <regx51.h>
// Function prototypes
void init_timer();
void main() {
P1 = 0x00;
// Initialize Timer/Counter 1
init_timer();
while (1) {
// Red light
P1_0 = 1; // Turn on the red light
delay_ms(RED_TIME);
// Yellow light
delay_ms(YELLOW_TIME);
// Green light
delay_ms(GREEN_TIME);
unsigned int i, j;
// Adjust this loop based on your clock frequency and compiler optimization settings
void init_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.
#define SHIFT_REGISTER_CONTROL P3
};
TR0 = 0;
void main() {
LED_MATRIX = 0x00;
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.
1. Hardware Components:
• Microcontroller: Select a microcontroller with analog input, digital output, and LCD
interfacing capabilities (e.g., Arduino, Raspberry Pi, PIC, etc.).
• LCD Display: An LCD screen to show the current temperature and the status of the
heating/cooling device.
2. Hardware Connections:
• Connect the temperature sensor's output pin to the microcontroller's analog input
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.
• Read the temperature value from the analog input pin using the temperature sensor.
• 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.