You are on page 1of 18

HANOI UNIVERSITY OF SCIENCE AND TECHNOLOGY

SCHOOL OF ELECTRICAL AND ELECTRONIC ENGINEERING


------

PROJECT REPORT
Design: A system for measuring and monitoring environment
temperature using Microcontroller 8051, temperature sensor
to display on LCD and control motor with 2 modes

Lecturer: Tran Thi Anh Xuan


Student: Chu Duc Phu
Student ID: 20202763
Class: 141007

Năm học 2022 - 2023


I. Choose components:

- Temperature sensor:
+ Choose LM35 due to:
 Does not require any external calibration;
 The shell can protect it from overheating;
 Low cost and high accuracy.
- Analog-to-Digital Converter:
+ Choose ADC0804 due to:
 Low cost, easy to use, simple interface;
 Good resolution: 8-bit resolution, high precision;
 High stability: automatic compensation of input signal and noise;
 Compatible with a wide range of microcontrollers.
- LCD:
+ Choose LCD16x2 due to:
 Popular size
 Good resolution
 Simple and easy to use interface
 Energy saving
 Reasonable price, stable features
- Motor driver module:
+ Choose L293D due to:
 Simple and easy to use interface
 Over-current and over-temperature protection
 Reasonable price and stable features
- Microcontroller: AT89C51
- Fan: DC motor
II. Working principle:

 LM35:
Pin 1 - VCC:
+ Supply 5V power to the sensor.
Pin 2 - Analog output:
+ Vout = 10mV/°C x T (-55°C - 150°C);
+ Connect to VIN+ Pin of ADC0804 to transm
wait for ADC to process.
 ADC0804:

Pin 20 - VCC:
+ Supply 5V power to the sensor.
Pin 11-18 - DBi (0< i <7):
+ Export digital data to P2 Pins of
MC8051 and wait for MC8051 to
process before exporting to LCD.
Pin 1 – CS (Chip Select):
+ Connect it to mass to work.

Pin 2 – RD (Read Data):


+ Pin enable reading out data at low-active.
+ Only when the RD pin goes from high-to-low, data is output to the DB pins;
+ Create a high-to-low pulse by using commands “SETB” and “CLR” with
pin P3.3 of MC8051.

Pin 3 – WR (Write Data):


+ When this pin is high and pulls low, the new input signal Vin is allowed to be
converted into a digital signal.
+ Create a high-to-low pulse by using commands “SETB” and “CLR” with pin P3.4
of MC8051.
Pin 4 – INTR:
+ Normally this pin is high and goes low when the conversion is finished.
+ Default this pin is 1 by using commands “SETB” with pin P3.5 of MC8051 and
create wait-command until INTR is low – the end of conversion.
+ Afterthat, “CLR RD” to output digital data to the DB pins – P2.

Pin 9 – VREF/2:
+ Input voltage used as reference
voltage.
+ Connect to potentionmeter to
create 1.28mV input voltage.
 AT89C51:

Port P0.0 – P0.3:


+ Connect to motor control buttons that consist of:
 1 auto button ;
 3 mode-manual button.

Port P1:
+ Connect to LCD to export ASCII data to LCD to display.
Port P2:
+ Connect to DB Pins to take digital data of temperature.
+ This digital data is temperature in hexa form. So, I need create a sub-program to
convert HEXA data into ASCII data before exporting to LC

Port P3.3 – P3.5:


+ Connect to pins RD, WR and INTR of ADC0804 to control the conversion.
Port P3.6 – P3.7:
+ Connect to pins RS and E of LCD to choose mode of LCD and display
temperature.
Port P3.1:
+ Create pulse to L293D motor driver module to control mot
 LCD 16x2:

Pin VDD:
+ Supply 5V power to the sensor.

Pin VEE:
+ Connect to the potentionmeter to adjust the contrast of LCD.

Pin RS (Register Select):


+ RS=0: Command mode to adjust mode of LCD;
+ RS=1: Data mode to enable receiving ASCII data to display.
+ Choose mode by using commands “SETB” and “CLR” with pin P3.6 of MC8051.

Pin RW (Read/Write):
+ Connect to GND => RW=0: Write mode.

Pin E (Enable):
+ Create a high-to-low pulse to enable the LCD by using commands “SETB” and
“CLR” with pin P3.7 of MC8051.

Pins D0 – D7:
+ Receive the data to be displayed on LCD or the command instructions.
 L293D:

Pin IN1 – IN2:


+ Set IN1=1 and IN2=0 to cause motor to rotate clockwise.

Pin EN1:
+ Supply PWM pulse from MC8051 to rotate the motor and the rotational speed can
be adjusted by code.

IV. Flow chart:


IV. Code explanation:
- This is the declaration of pins of LCD, ADC and motor control pin.

- Main program:
+ First, I adjust LCD to correctly operate requirements.
+ Next, call LCD_String display “TEMPERATURE IS: ” in LCD.
+ Call ADC_0804 to process analog signal from LM35 before displaying in LCD by
LCD_Display.
+ Afterthat, MC8051 create pulse and output to motor driver to control motor.
+ And jump to Main to continue the loop.

- ADC_0804:
+ First, I adjust the state of pins before starting process analog signal.
+ Next, set bit the pin ADC_WR to start conversion.

- LCD_Display:
+ First, move the digital signal that is just processed by ADC0804 to A-register.
+ Next, perform calculations to convert binary numbers to ASCII and display in
LCD.
+ The spaces are to center align.

- LCD_Write is for writing data mode.


- LCD_Command is for command mode.
- LCD_Init to initialize the LCD.
- LCD_String is for displaying the first sentence:
+ Move data pointer to Line1-program.
+ Send data’s address of each letter to output to LCD by each loop will increase
DPTR by 1 bit until end of sentence to be displayed.
+ Final, move cursor to 2nd line.
- Motor_Choose:
+ Choose suitable mode to run motor by comparing commands.

- Auto_Mode:
+ Perform the comparison the temperature to find the right auto-mode.
- Auto_Mode1,2,3:
+ First, check state of manual-buttons: if is ON, jump back to Motor_Choose; else,
perform the next commands.
+ Next, check if temperature changes, jump to Return to return to Back.
+ If temperature does not change, run the corresponding motor-mode.

- Manual_Mode1,2,3:
+ First, check state of manual-buttons: if is ON, jump back to Motor_Choose; else,
perform the next commands.
+ Next, check if the state of corresponding manual-button: if is ON, run the
corresponding motor-mode; else, jump to RET.
- Mode1,2,3:
+ Set bit EN1-pin to start high pulse.
+ Move the suitable values into TH0 and TL0 to be counted when I start the Timer0
by calling Pulse.
+ Clear bit EN1-pin to start low pulse.
+ Move the suitable values into TH0 and TL0 to be counted when I start the Timer0
by calling Pulse.
- Pulse:
+ First, clear the overflow flag TF0 to start the new counter.
+ Run Timer0 and wait until TF0 = 1, stop Timer0 to create delay as required.

- Delay:
V. Simulation results:
 Auto_Mode:
+ When I press AUTO button, motor will automatically run according to the
temperature displayed on the LCD.
+ When temperature is t<25°C

+ When temperature is 25°C ≤ t < 30°C


+ When temperature is 30°C ≤ t < 35°C

+ When temperature is t ≥ 35°C


 Manual_Mode:
+ When I press button MODE 1, even though AUTO button is ON, motor
runs mode-1 speed.

+ Similarly, when I press button MODE 2, even though AUTO button and
MODE 1 button are ON, motor runs mode-2 speed.
+ When I press button MODE 3, even though AUTO button, MODE 1 and
MODE 2 are ON, motor runs mode-3 speed.

VI. Advantages and disadvantages:


 Advantages:
+ Output temperature to LCD as required;
+ The motor can run in 2 modes as required;
+ The code has been optimized according to my ability.
 Disadvantages:
+ When I change the temperature, the motor don’t run. The motor runs
continuously only when the temperature rise stops.
+ In the simulation, when the temperature rises too quickly, the system fails
LCD and the motor. And when motor is running, if I want to change speed, I need
to wait for motor to be done of running 2-3 rounds.

You might also like