Tutorials On 8051
Tutorials On 8051
confined livestock production to maintain the optimal indoor temperature of 18° to 20°C. As a founder of a start
–up company, you are given an opportunity to design and develop a microcontroller based system to meet the
customer specifications as given below.
Customer Specifications
Turn on Blue LED, if temperature is lower than the optimal range
Turn ON RED LED, if Temperature is higher than the optimal range and display the message “HIGH” to
alert the stock handlers to take appropriate control action.
Turn ON GREEN LED, if temperature is within the optimal range.
The ambient temperature can be sensed by LM 35 sensor whose specifications are given as below. The signal
conditioning circuit / amplifier to be introduced to enable the operation of ADC 0808 to its full scale voltage
range. It is sufficient to mention the gain requirements without getting into the details of designing an
amplifier circuit.
LM 35 Specifications:
Keep LCD ready to receive data for display by Initialising LCD for 2 lines, 5X7 matrix char. display,
turning on LCD & cursor, clear display, and so on... through a calling program labelled “ ACALL
COMMAND”.
Sense the temperature and initiate the required action to be taken as per the above
specifications. (Note: Make a provision to include a calling program labelled “Display” for
sending the message to be displayed as per the specification.)
As part of an industrial automation system two wheels are driven by two separate motors, motor A
and motor B. The rotation sensors give a logic low level as the wheel magnet passes the sensor. Each
motor can be turned on or off by providing a logic signal as indicated in Figure 3B. An 8051 is to be
used to control these motors, where a motor can be turned ON and allowed run for N rotations and
then turned OFF. The sensor signals will cause timer/counter interrupts. Write an 8051-assembly
language program which will turn on the two motors at the same time. Motor A will do 20 rotations
and will then be stopped. Motor B will do 200 rotations and will then be stopped
ORG 0000H
Both timer 1 (Motor B - 200 rotation-P1.7) and timer 0 MOV TMOD, #66H
(Motor A -20 rotation-P1.6) as counters in mode 2
SETB P3.4
ORG 0000H
LJMP MAIN SETB P3.5
0RG 000BH
MOV TH1, #00H
LJMP ISRT0
ORG 001BH MOV TH0, #00H
LJMP ISRT1 SETB P1.6
SETB P1.7
MAIN: MOV TMOD, #66H
SETB P3.4 SETB TR1
SETB P3.5
SETB TR0
MOV TH1, #38H //for 200 rotation
MOV TH0, #0ECH // 20 rotation AGAIN: MOV R0, TL0
MOV IE, #10001010B CJNE R0, #20, AGAIN
SETB TR0
CLR P1.6
SETB TR1
SETB P1.6 CLR TR0
SETB P1.7 AGAIN1: MOV R0, TL1
LOOP: SJMP LOOP
CJNE R0, #200, AGAIN1
ISRT0: CLR TR0 CLR P1.7
CLR P1.6
CLR TR1
RETI
END
ISRT1: CLR TR1
CLR P1.7
RETI
The Figure 4B shows a D/A (digital to analog) converter which drives a dc motor. Assume the power
stage is included in the D/A converter so that the motor can be driven directly by Vout. An 8051
microcontroller has this D/A converter connected to an I/O port P1. The 8051 is connected to a
Computer via the serial port. When 8-bit data character is received from the Computer, it interrupts
the 8051 through the 8051’s serial port interrupt and the received 8-bit data value is passed to the
D/A converter so that the Computer is effectively controlling the motor speed. Write an 8051-
assembly language program to implement this system. Assume a serial data baud rate of 9,600 baud.
Baud rate calculation for value to load 9600 – FDH
ORG 0000H
LJMP MAIN
ORG 0023H
LJMP ISRSERIAL
ORG 0030H
MAIN: MOV TMOD, #20H
MOV TH1, #0FDH
MOV SCON, #50H
MOV IE, #10010000B
SETB TR1
ORG 0100H
ISRSERIAL: JNB R1, NEXT
MOV A, SBUF
MOV P1, A
NEXT: RETI
END
An 8051 based system constantly outputs a square wave at some frequency through an I/O port
bit. The frequency is timed based on an 8-bit timer of 8051. The 8051 is connected to a PC via
the serial port. When an 8-bit data character is received from the PC, it interrupts the 8051
through the 8051’s serial port interrupt and the received 8-bit data value is passed to the timer
so as to re-specify the frequency. Thus a PC programmable frequency generator is achieved.
Write an 8051 assembly language program to implement this system. Assume a serial data
baud rate of 9,600 baud. Show all configuration of the UART, timer. 8051 is crystalled at
11.0596 MHz.
A thermal power plant requires constant temperature monitor of heating core to avoid any
catastrophic failure causing harm to workers in the power plant. A thermo-couple based
temperature sensing unit is setup at the plant. As a student on internship there, you are
required to develop an emergency evacuation setup using 8051 microcontroller with the
following specifications.
The setup up contains input from temperature sensor in voltage, ADC and an LCD display to
show the status, two LEDs RED and GREEN, A buzzer alarm warning for evacuation.
Draw the interfacing circuit and write an assembly language program to execute the required
conditions.
Solution:
800C = 4V = CCH
ORG 0000H
MOV 30H, A
SUBB A, #0FFH ;1000C check
JNC BUZZ
MOV A, 30H
SUBB A,#0CCH ;800C check
JNC RED
SETB P2.4 ; green do
CLR P2.3
SJMP START
BUZZ: SETB P2.3 ; buzzer, red led do
SETB P2.5
MOV DPTR, # TABLE1 ; display evacuate
AGAIN: CLR A
MOVC A,@A+DPTR
JZ SKIP
MOV P3, A
ACALL DATA1
INC DPTR
SJMP AGAIN
SKIP: NOP
WAIT: SJMP WAIT