Beruflich Dokumente
Kultur Dokumente
TUTORIAL 3
1. Using the MCS-51 opcode map, find out the machine codes of the following
assembly language program and their addresses in the program memory.
ORG 0000H
MOV R0, #30H
LOOP: MOV P1, @R0 ; P1 register at address 90H
INC R0
CJNE R0, #40H, LOOP
END
3. Find the contents of the accumulator and the PSW register of an 8051 microcontroller
after it executes each instruction below. (Assume that initially PSW contains 00H)
MOV A, #98H
ADD A, #87H
MOV B, #12H
SUBB A, B ; B register is at address F0H
4. Write a program to implement the logic operation as shown in the figure below.
Label Bit address
V
V 90H
W
Z W 91H
X
X 92H
Y
Y 93H
Z 94H
5. For an 8-bit number, bits 0 & 1 to be cleared, bits 3 & 4 are to be set and bits 5 & 7
are to be inverted. Assuming the number is in accumulator, write assembly language
instructions for 8051 to carry out the task using logical operators with appropriate
masks. If the initial value in accumulator is 0E7H, find the final value in the
accumulator at the end of execution of the above instructions.
6. Internal RAM locations 3FH and 40H contain 91H and 05H respectively. Assuming
that the contents of PSW is initially 0, find the values of the following registers for
execution of the following program:
i. Accumulator, B and PSW registers after the ‘MUL’ instruction
When the solution reaches level LE, valve VE is closed and the whole process is
repeated.
The tank has three level sensors that send signals to input lines P2.0 to P2.2. A logical
low from the sensor indicates that the level has been reached. The output lines P1.1 to
P1.3 provide signals to the solenoid valves. A logical high from the lines will open
the corresponding valve. The output lines P1.0 and P1.4 provide signals to the motor
and the heater respectively. Both the motor and the heater are activated by a logical
high. Write a program for the 8051 microcontroller to carry out the process.
Motor
VB VA
M
8051
P1.0
P1.1 LB
P1.2
P1.3
P1.4
LA
P2.0
P2.1 LE
P2.2
Heater VE
Notes: The microcontroller is connected to the sensors and actuators through some drivers and
signal conditioning circuits, which are not shown here for simplicity.
10. Two dual carriage roads meet at an intersection, as shown in Figure Q10 below. Four
traffic lights (E, S, W and N) placed at this junction are to be controlled by an 8051
microcontroller. Each traffic light is controlled via different I/O pins on the
microcontroller, as shown in Table Q10.1. The operations of the traffic lights are
summarized in Table Q10.2. The operation cycle repeats indefinitely until the
microcontroller is powered down. Assume that the traffic lights are properly
connected to the microcontroller via an interfacing circuit, write a program for the
8051 microcontroller to control these traffic lights. (Note: 12MHz crystal is used).
Table Q10.1
Port 0 Port 1
Pin 0 1 2 3 4 5 0 1 2 3 4 5
Light E-R E-Y E-G W-R W-Y W-G N-R N-Y N-G S-R S-Y S-G
*R: Red, Y: Yellow, G: Green
Table Q10.2
Duration E W N S
30s Green Red Red Red
3s Yellow Red Red Red
30s Red Green Red Red
3s Red Yellow Red Red
60s Red Red Green Red
3s Red Red Yellow Red
60s Red Red Red Green
3s Red Red Red Yellow
N
W E
S
Figure Q10