0% found this document useful (0 votes)
120 views9 pages

L4 - Simple I - O Control

Uploaded by

Dilip Ken
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
120 views9 pages

L4 - Simple I - O Control

Uploaded by

Dilip Ken
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

EEE3410 Microcontroller Applications

│LABORATORY – Experiment 4│

Simple Input & Output Controls in 8051

Name Date Marks

Class Class No.

Input & Output Controls

Objectives

 To understand the connection of LEDs and switches to 8051


 To know how to write 8051 assembly program to perform ON/OFF control on external devices
 To become familiar with the basic procedures of developing a microcontroller system

Equipment/Components Required

 PC compatible computer with Windows XP


 MedWin 8051 simulation software.
 Switch & LED training board with power supply and connection cable
 HT1000 89C51 Writer
 floppy disk/USB flash disk

Ver Author(s) Date Remark


1.0 KK SIN 9/2006

Laboratory Experiment 4 1
© Vocational Training Council, Hong Kong
Part A: Background Information
8051 has four ports P0, P1, P2 and P3. Each port has 8 pins, making them as a 8-bit ports. All the
ports can be programmed to use as input or output ports. Upon connection of external devices to the
ports, data can be transferred in/out the 8051.

Figure A.1 shows how 8 LEDs are connected to Port 0 of 8051. Due to the open drain nature of Port
0, connection of pull-up resistors with 5V supply is needed. The LEDs will be ON when port bit is at
logic 0, and the LEDs will be OFF when port bit is at logic 1.

Figure A.2 shows how 8 LEDs are connected to Port 1, Port 2 or Port 3 of 8051. The LEDs can
directly be turned ON/OFF without pull-up resistors linking to 5V supply. The LEDs will be ON
when port bit is at logic 1, and the LEDs will be OFF when port bit is at logic 0.

Figure A.3 and Figure A.4 gives the flowchart and corresponding 8051 program to control the
ON/OFF of the 8 LEDs.

+5V +5V

EA EA
P0.7 V
Reset
P1.7
Reset
P0.6 P1.6

P0.5 P1.5
8051 8051
P0.4 P1.4

P0.3 P1.3
XTAL1 XTAL1
P0.2 P1.2
XTAL2 P0.1 XTAL2 P1.1

P0.0 P1.0
VSS VSS

Figure A.1 Figure A.2

Start
ORG 0000H
CLR A
Set A = 00 LOOP: MOV P0, A
CPL A
ACALL DELAY
Move the content of A
to P1
AJMP LOOP
DELAY: MOV R5, #10
DL1: MOV R6, #250
Delay for 0.1s DL2: MOV R7, #200
DL3: DJNZ R7, DL3
Invert the DJNZ R6, DL2
content of A DJNZ R5, DL1
RET
END
Figure A.3 Figure A.4

2 Experiment 4 Laboratory
© Vocational Training Council, Hong Kong
EEE3410 Microcontroller Applications

Part B: Procedures

B1. Familiarization for developing 8051 program for Input/Output control

Figure B1.1 shows the circuit diagram of the Switch & LED training board. Two sets of 8-LED
bank are connected to Port 0 and Port 1. 4 push buttons (S1 to S4) and 4 Dip switches (S4 to
S8) are connected to lower nibble and higher nibble of Port 3 respectively.

Figure B1.1

Laboratory Experiment 4 3
© Vocational Training Council, Hong Kong
In this part, you are given a source program in table B1.3 to control the 8 LEDs at Port 1 to light
up as “Rotating glowing pattern” in the manner as shown in figure B1.2 below.

Port Bit - 7 6 5 4 3 2 1 0

repeating
Figure B1.2

Table B1.3
Line Label Mnemonics Operands Remarks
1 ORG 0000H
2 START: MOV R1, #07H
3 MOV A, #11111110B
4 LEFT: MOV P1, A
5 ACALL DELAY ;hold ~0.5s
6 RL A
7 DJNZ R1, LEFT
8 MOV R1, #07H
9 MOV A, #01111111B
10 RIGHT: MOV P1, A
11 ACALL DELAY
12 RR A
13 DJNZ R1, RIGHT
14 AJMP START
15 DELAY: MOV R5, #5 ;sets the delay time
16 LOOP1: MOV R6, #250
17 LOOP2: MOV R7, #200
18 LOOP3: DJNZ R7, LOOP3 ;inner loop
19 DJNZ R6, LOOP2 ;middle loop
20 DJNZ R5, LOOP1 ;outer loop
21 RET ;return to main program
22 END

4 Experiment 4 Laboratory
© Vocational Training Council, Hong Kong
EEE3410 Microcontroller Applications

B2. Familiarization for writing the developed 8051 program to 89C51 chip

B2.1 Open the 8051 simulation software. Create a new file with filename “LED.asm”
B2.2 Type in the assembly source program in table B1.3 and assemble the source program.
B2.3 Use command “Peripherals – Ports” to display Port Windows.
B2.4 Execute the program step-by-step and observe the changes at Port 1. It should match the
glowing pattern in figure B1.2.
B2.5 Use command “Project – Output Intel Hex File” to save the HEX code of the assembly
program in a floppy disk/USB flash disk. The default filename is “LED.hex”
B2.6 Use the HT1000 89C51 writer to write the HEX file “LED.hex” into a blank 89C51 chip.
B2.7 Then insert the 89C51 chip to the Switch & LED training board.
B2.8 Switch on the power supply and observe the glowing pattern of LEDs at Port 1.
B2.9 Does it match to the design pattern?

B3. Input and Output Control

B3.1 The pattern of glowing up of the LEDs at Port 1 is controlled by the 4 push buttons S1 to
S4 t Port 3 as shown in figure B3.1.
B3.2 Table B3.2 and figure B3.3 give the flowchart and the assembly source program.
B3.3 Use the 8051 simulation software to test the correctness of the assembly program.
B3.4 Create the HEX code file of the assembly program and write it into an 89C51 chip.
B3.5 Put the 89C51 chip in the Switch & LED training board to test the control process.

When S1 Closed When S2 Closed

When S3 Closed When S4 Closed

Priority: S1 S2 S3 S4 Figure B3.1

Laboratory Experiment 4 5
© Vocational Training Council, Hong Kong
Table B3.2
Line Label Mnemonics Operands Remarks
1 ORG 0000H
2 MOV R1, #00000000B
3 MOV R2, #01010101B
4 LEFT: MOV R3, #00001111B
5 MOV R4, #11110000B
6 ;
7 TEST: ORL P3, #0FFH
8 JNB P3.0, CASE1
9 JNB P3.1, CASE2
10 JNB P3.2, CASE3
11 JNB P3.3, CASE4
12 AJMP TEST
13 ;
14 CASE1: MOV A, R1
15 MOV P1, A
16 ACALL DELAY
17 XRL A, #11111111B
18 MOV P1, A
19 AJMP TEST
20 CASE2: MOV A, R2
21 MOV P1, A
22 ACALL DELAY
23 XRL A, #10101010B
24 MOV P1, A
25 AJMP TEST
26 CASE3: MOV A, R3
27 MOV P1, A
28 ACALL DELAY
29 XRL A, #11110000B
30 MOV P1, A
31 AJMP TEST
32 CASE4: MOV A, R4
33 MOV P1, A
34 ACALL DELAY
35 XRL A, #00001111B
36 MOV P1, A
37 AJMP TEST
38
39 DELAY: MOV R5, #5 ;sets the delay time
40 LOOP1: MOV R6, #250
41 LOOP2: MOV R7, #200
42 LOOP3: DJNZ R7, LOOP3 ;inner loop
43 DJNZ R6, LOOP2 ;middle loop
44 DJNZ R5, LOOP1 ;outer loop
45 RET ;return to main
46 END program

6 Experiment 4 Laboratory
© Vocational Training Council, Hong Kong
EEE3410 Microcontroller Applications

Start
Y
SW1 closed? SW1 Handler
Initializatio
N
1 2 Y
SW2 closed? SW2 Handler

Set P3 as input port N


Y
SW3closed? SW3 Handler

Read S1∼S4 status


N
Y
SW4 closed? SW4 Handler

Figure B3.3
1

Part C: Exercise
C1. What value should be assigned to a Port when it is used as input port?

C2. Write 8051 instructions to output a 4-bit value to the upper nibble of Port 1 without changing the
values of the bits at lower nibble.

C3. Write 8051 instructions to mask a 4-bit value input from the upper nibble of Port 1 and store it in
accumulator A.

Laboratory Experiment 4 7
© Vocational Training Council, Hong Kong
C4. The assembly language program shown in table C4.2 control the glowing pattern of LEDs,
figure C4.1, at Port 0 using the method of lookup table.

Port Bit - 7 6 5 4 3 2 1 0

Figure C4.1

Table C4.2
Line Label Mnemonics Operands Remarks
1 ORG 0000H
2 START: MOV R0, #OK-MYDATA+1
3 MOV DPTR, #MYDATA
4 MOV R1, #00H
5 LOOP: MOV A, R1
6 MOVC A, @A+DPTR
7 MOV P0, A
8 ACALL DELAY
9 INC R1
10 DJNZ R0, LOOP
11 AJMP START
12 ;
13 DELAY: MOV R5, #5 ;sets the delay time
14 LOOP1: MOV R6, #250
15 LOOP2: MOV R7, #200
16 LOOP3: DJNZ R7, LOOP3 ;inner loop
17 DJNZ R6, LOOP2 ;middle loop
18 DJNZ R5, LOOP1 ;outer loop
19 RET ;return to main
program
20 ;
21 MYDATA: DB 01111110B
22 DB 00111100B
23 DB 00011000B
24 DB 11100111B
25 DB 10100101B
26 OK: DB 01011010B
27 END

8 Experiment 4 Laboratory
© Vocational Training Council, Hong Kong
EEE3410 Microcontroller Applications

C4(a) Modify the program to have the LED glowing pattern shown in figure C4.3.

Figure C4.3

C4(b) Modify the program to have the LED glowing pattern shown in figure C4.4.

Figure C4.4

C5. Write an assembly language program which can read Dip switch S7 at P3.7 and control the
LEDs at Port 0 to light up as the glowing pattern either in figure C4.3 or in figure C4.4.
depending on the value read from the Dip switch. If ‘0’ is read, glowing pattern in figure C4.3
is used. Otherwise, glowing pattern in figure C4.4 is used.

- End -

Laboratory Experiment 4 9
© Vocational Training Council, Hong Kong

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy