You are on page 1of 26

CODE COURSE: ECE 521

LABOTORY 4: Intel 8051 CPU PROGRAMMING INPUT/OUTPUT PROGRAMMING


GROUP MEMBERS: MOHAMAD FARIDZAL BIN MOHAMAD BAKRI (2015135411)
SALLEH AMRI BIN BADDAROLAZAM (2015141319)
GROUP: EE2423B
SUBMISSION FOR: MADAM KAMA AZURA
SUBMISSION DATE: 16TH May 2016

RESULT
1. Write and execute a program that turns on LED one by one as Running Light.
ORG 0000H
MULA:

MOV A, #0FEH

; TURN ON LED0

MOV P1, A
LCALL DELAY
MOV A, #0FDH

; TURN ON LED1

MOV P1, A
LCALL DELAY
MOV A, #0BFH

; TURN ON LED6

MOV P1, A
LCALL DELAY
MOV A, #0FFH

; TURN OFF ALL

MOV P1, A
LCALL DELAY
; START PROGRAM HERE
MOV A, #80H
MOV DPTR, #8003H
MOVX @DPTR, A
; INITIALIZE PPI1
START:

MOV R1, #07H


MOV A, #11111110B
MOV DPTR, #8002H

LOOP:

MOVX @DPTR, A
LCALL DELAY
RL A
DJNZ R1, LOOP
AJMP START

DELAY:

MOV R2, #50

LOOP3:

MOV R1, #200

LOOP2:

MOV R0, #200

LOOP0:

DJNZ R0, LOOP0

DJNZ R1, LOOP2


DJNZ R2, LOOP3
RET
END

Figure 1: Shows the visual result for running light in the hardware

2. Write and execute a program that reads the condition of 8 switches and send the logic
signal to the LED.
ORG 0000H
MULA:

MOV A, #0FEH
MOV P1, A
LCALL DELAY

MOV A, #0FDH
MOV P1, A
LCALL DELAY
MOV A, #0BFH
MOV P1, A
LCALL DELAY
MOV A, #0FFH
MOV P1, A
LCALL DELAY
; START PROGRAM
MOV A, #80H
MOV DPTR, #8003H
MOVX @DPTR, A
; PPI1 INITIALIZATION
SW0:

MOV DPTR, #0E001H


MOVX A, @DPTR
ANL A, #000000001B
CJNE A, #00000000B, SW1
LJMP LED0

SW1:

MOV DPTR, #0E001H


MOVX A, @DPTR
ANL A, #00000010B
CJNE A, #00000000B, SW2
LJMP LED1

SW2:

MOV DPTR, #0E001H


MOVX A, @DPTR
ANL A, #00000100B
CJNE A, #00000000B, SW3
LJMP LED2

SW3:

MOV DPTR, #0E001H


MOVX A, @DPTR
ANL A, #00001000B
CJNE A, #00000000B, SW4
LJMP LED3

SW4:

MOV DPTR, #0E001H


MOVX A, @DPTR
ANL A, #00010000B
CJNE A, #00000000B, SW5
LJMP LED4

SW5:

MOV DPTR, #0E001H


MOVX A, @DPTR
ANL A, #00100000B
CJNE A, #00000000B, SW6
LJMP LED5

SW6:

MOV DPTR, #0E001H


MOVX A, @DPTR
ANL A, #01000000B
CJNE A, #00000000B, SW7
LJMP LED6

SW7:

MOV DPTR, #0E001H


MOVX A, @DPTR
ANL A, #10000000B
CJNE A, #00000000B, OFF
LJMP LED7
; LOOP BACK TO SW0

LED0:

MOV A, #00000001B
MOV DPTR, #8002H
MOVX @DPTR, A
ACALL DELAY
LJMP SW1

LED1:

MOV A, #00000010B
MOV DPTR, #8002H
MOVX @DPTR, A
ACALL DELAY
LJMP SW1

LED2:

MOV A, #00000100B
MOV DPTR, #8002H

MOVX @DPTR, A
ACALL DELAY
LJMP SW2
LED3:

MOV A, #00001000B
MOV DPTR, #8002H
MOVX @DPTR, A
ACALL DELAY
LJMP SW3

LED4:

MOV A, #00010000B
MOV DPTR, #8002H
MOVX @DPTR, A
ACALL DELAY
LJMP SW4

LED5:

MOV A, #00100000B
MOV DPTR, #8002H
MOVX @DPTR, A
ACALL DELAY
LJMP SW5

LED6:

MOV A, #01000000B
MOV DPTR, #8002H
MOVX @DPTR, A
LCALL DELAY
AJMP SW6

LED7:

MOV A, #10000000B
MOV DPTR, #8002H
MOVX @DPTR, A
LCALL DELAY
AJMP SW0

OFF:

MOV A, #11111111B
MOV DPTR, #8002H
MOVX @DPTR, A
ACALL DELAY
LJMP SW0

DELAY:

MOV R2, #50

LOOP3:

MOV R1, #200

LOOP2:

MOV R0, #200

LOOP:

DJNZ R0, LOOP


DJNZ R1, LOOP2
DJNZ R2, LOOP3
RET
END

1.1 Visual result for hardware for switches and LEDs.

3. Write and execute a program that displays number on both 7-segment counting up from 00
to 99.
ORG 0000H
MULA:

MOV A, #0FEH
MOV P1, A
LCALL DELAY
MOV A, #0FDH
MOV P1, A
LCALL DELAY
MOV A, #0BFH
MOV P1, A
LCALL DELAY
MOV A, #0FFH
MOV P1, A
LCALL DELAY
; START PROGRAM HERE
MOV A, #10000000B
MOV DPTR, #6003H
MOVX @DPTR, A

ZERO:

MOV A, #00001111B
MOVX @DPTR, A
AJMP DELAY
LCALL COUNT
MOV A, #00011111B
MOVX @DPTR, A
AJMP DELAY
LCALL COUNT

MOV A, #00101111B

MOVX @DPTR, A
AJMP DELAY
LCALL COUNT
MOV A, #00111111B
MOVX @DPTR, A
AJMP DELAY
LCALL COUNT
MOV A, #01001111B
MOVX @DPTR, A
AJMP DELAY
LCALL COUNT
MOV A, #01011111B
MOVX @DPTR, A
AJMP DELAY
LCALL COUNT
MOV A, #01101111B
MOVX @DPTR, A
AJMP DELAY
LCALL COUNT
MOV A, #01111111B
MOVX @DPTR, A
AJMP DELAY
LCALL COUNT
MOV A, #10001111B
MOVX @DPTR, A
AJMP DELAY
LCALL COUNT
MOV A, #10011111B

MOVX @DPTR, A
AJMP DELAY
LCALL COUNT
COUNT:

MOV A, #11110000B
MOVX @DPTR, A
LCALL DELAY
MOV A, #11110001B
MOVX @DPTR, A
LCALL DELAY
MOV A, #11110010B
MOVX @DPTR, A
LCALL DELAY
MOV A, #11110011B
MOVX @DPTR, A
LCALL DELAY
MOV A, #11110100B
MOVX @DPTR, A
LCALL DELAY
MOV A, #11110101B
MOVX @DPTR, A
LCALL DELAY
MOV A, #11110110B
MOVX @DPTR, A
LCALL DELAY
MOV A, #11110111B
MOVX @DPTR, A

LCALL DELAY
MOV A, #11111000B
MOVX @DPTR, A
LCALL DELAY
MOV A, #11111001B
MOVX @DPTR, A
LCALL DELAY
RET
DELAY:

MOV R2, #30

LOOP3:

MOV R1, #255

LOOP2:

MOV R0, #255

LOOP:

DJNZ R0, LOOP


DJNZ R1, LOOP2
DJNZ R2, LOOP3
RET
END

Figure 3: Show the result visual for 7-segment that shows 00, 50 and 99 (from 00 to 99)

4. Write and execute a program that can run the DC motor clock-wise for 5 second and then
stop. After 3 second rest, the motor repeat the same step again and the loop repeated all over
again.
ORG 0000H
MULA:

MOV A, #0FEH
MOV P1, A
LCALL DELAY
MOV A, #0FDH
MOV P1, A
LCALL DELAY
MOV A, #0BFH
MOV P1, A
LCALL DELAY
MOV A, #0FFH
MOV P1, A

LCALL DELAY
; START PROGRAM
MOV A, #80H
MOV DPTR, #8003H
MOVX @DPTR, A
; PPI1 INITIALIZATION
DCM:

MOV A, #00000111B
MOV DPTR, #8001H
MOVX @DPTR, A
LCALL DELAY1
MOV A, #00000000B
MOV DPTR, #8001H
MOVX @DPTR, A
LCALL DELAY2
SJMP DCM

DELAY1:

MOV R2, #33

LOOP3:

MOV R1, #255

LOOP2:

MOV R0, #255

LOOP:

DJNZ R0, LOOP


DJNZ R1, LOOP2
DJNZ R2, LOOP3
RET

DELAY2:

MOV R2, #27

LOOP3:

MOV R1, #255

LOOP2:

MOV R0, #255

LOOP:

DJNZ R0, LOOP


DJNZ R1, LOOP2
DJNZ R2, LOOP3
RET
END

Figure 4: Shows the DC motor is turn ON then turn OFF

5. Write and execute a program that read the keypad button and display the number on 7segment.

ORG 0000H
MULA:

MOV A,#0FEH
MOV P1,A
LCALL DELAY
MOV A,#0FDH
MOV P1,A
LCALL DELAY
MOV A,#0BFH
MOV P1,A

LCALL DELAY
MOV A,#0FFH
MOV P1,A
LCALL DELAY

;START YOUR PROGRAMS HERE


MAIN:

MOV A,#83H
MOV DPTR,#0E003H
MOVX @DPTR,A
MOV A,#80H
MOV DPTR,#6003H
MOVX @DPTR,A

START:

MOV A,#10000000B
MOV DPTR,#0E002H
MOVX @DPTR,A
MOVX A,@DPTR
MOV R1,A
ANL A,#00000001B
JNZ NUMB1
MOV A,R1
ANL A,#00000010B
LCALL APA4
MOV A,R1
ANL A,#00000100B
LCALL APA7
MOV A,R1
ANL A,#00001000B
LCALL APAS
MOV A,#01000000B

MOV DPTR,#0E002H
MOVX @DPTR,A
MOVX A,@DPTR
MOV R1,A
ANL A,#00000001B
JNZ NUMB2
MOV A,R1
ANL A,#00000010B
LCALL APA5
MOV A,R1
ANL A,#00000100B
LCALL APA8
MOV A,R1
ANL A,#00001000B
JNZ NUMB0
MOV A,#00100000B
MOV DPTR,#0E002H
MOVX @DPTR,A
MOVX A,@DPTR
MOV R1,A
ANL A,#00000001B
JNZ NUMB3
MOV A,R1
ANL A,#00000010B
LCALL APA6
MOV A,R1
ANL A,#00000100B
LCALL APA9
MOV A,R1
ANL A,#00001000B
LCALL APAH
MOV A,#00010000B

MOV DPTR,#0E002H
MOVX @DPTR,A
MOVX A,@DPTR
MOV R1,A
ANL A,#00000001B
LCALL APAA
MOV A,R1
ANL A,#00000010B
LCALL APAB
MOV A,R1
ANL A,#00000100B
LCALL APAC
MOV A,R1
ANL A,#00001000B
LCALL APAD
LJMP START
NUMB0:

MOV A,#00H
MOV DPTR,#6000H
MOVX @DPTR,A
LCALL DELAY
LJMP START
RET

NUMB1:

MOV A,#01H
MOV DPTR,#6000H
MOVX @DPTR,A
LCALL DELAY
LJMP START
RET

NUMB2:

MOV DPTR,#6000H
MOV A,#02H

MOVX @DPTR,A
LCALL DELAY
LJMP START
RET
NUMB3:

MOV A,#03H
MOV DPTR,#6000H
MOVX @DPTR,A
LCALL DELAY
LJMP START
RET

APA4:

JNZ NUMB4
RET

NUMB4:

MOV A,#04H
MOV DPTR,#6000H
MOVX @DPTR,A
LCALL DELAY
LJMP START
RET

APA5:

JNZ NUMB5
RET

NUMB5:

MOV A,#05H
MOV DPTR,#6000H
MOVX @DPTR,A
LCALL DELAY
LJMP START
RET

APA6:

JNZ NUMB6
RET

NUMB6:

MOV A,#06H
MOV DPTR,#6000H
MOVX @DPTR,A
LCALL DELAY
LJMP START
RET

APA7:

JNZ NUMB7
RET

NUMB7:

MOV A,#07H
MOV DPTR,#6000H
MOVX @DPTR,A
LCALL DELAY
LJMP START
RET

APA9:

JNZ NUMB9
RET

NUMB9:

MOV A,#09H
MOV DPTR,#6000H
MOVX @DPTR,A
LCALL DELAY
LJMP START
RET

APA8:

JNZ NUMB8
RET

NUMB8:

MOV A,#08H
MOV DPTR,#6000H
MOVX @DPTR,A
LCALL DELAY

LJMP START
RET
APAA:

JNZ NUMBA
RET

NUMBA:

MOV A,#0AH
MOV DPTR,#6000H
MOVX @DPTR,A
LCALL DELAY
LJMP START
RET

APAS:

JNZ NUMBS
RET

NUMBS:

MOV A,#0AH
MOV DPTR,#6000H
MOVX @DPTR,A
LCALL DELAY
LJMP START
RET

APAH:

JNZ NUMBH
RET

NUMBH:

MOV A,#0BH
MOV DPTR,#6000H
MOVX @DPTR,A
LCALL DELAY
LJMP START
RET

APAB:

JNZ NUMBB

RET
NUMBB:

MOV A,#0BH
MOV DPTR,#6000H
MOVX @DPTR,A
LCALL DELAY
LJMP START
RET

APAC:

JNZ NUMBC
RET

NUMBC:

MOV A,#0CH
MOV DPTR,#6000H
MOVX @DPTR,A
LCALL DELAY
LJMP START
RET

APAD:JNZ NUMBD
RET
NUMBD:

MOV A,#0DH
MOV DPTR,#6000H
MOVX @DPTR,A
LCALL DELAY
LJMP START
RET

DELAY:

MOV R2,#3

LOOP3:

MOV R1,#250

LOOP2:

MOV R0,#250

LOOP:

DJNZ R0,LOOP

DJNZ R1,LOOP2
DJNZ R2,LOOP3
RET
END

DISCUSSION
1.

For this exercise 1, firstly we need to test in the trainer board to test the functional of

the program and the board. By using LED0, LED1 and LED6 to switch ON like running light
by using delay then it will OFF then move to the hardware in to the application board. This
exercise is only use LEDs. When the running light test is running, this indicated that the
board and the programme are functionally well and can proceed for the lab exercise. Next,
the LEDs it is connect in PPI1 and declare it as #80H because use port C as an output. Then
#8003H is load to control register to the port address. Then to transfer the program inside the
ROM we used MOVX @DPTR, A to control word. The data #11111110B that will be store in
A indicated that only 1 LED will turn ON which is LED0. The LED in application board is
active low so 0 is ON and 1 is OFF. The LED0 to LED7 will ON like running light and
continue looping. The delay will take 600s before the next LED is ON. Then, RL A is to do
return left from LED0 turn OFF, then LED1 is ON and so on. Next, DJNZ R1, LOOP is when
data not equal to zero for the data in R1 it will decrement after it go back to the loop. The
LEDs will stop running after all the loop is finish.

For this exercise 2, firstly we need to test in the trainer board to test the functional of

the program and the board. By using LED0, LED1 and LED6 to switch ON like running light
by using delay then it will OFF then move to the hardware in to the application board. This
exercise is only use switches and LEDs. When the running light test is running, this indicated
that the board and the programme are functionally well and can proceed for the lab exercise.
For eight switches it is connect in PPI 3 and declare it as #E001H because use port B as an
input. The LEDs are connect in PPI1 and declare it as #80H because use port C as an output.
Then #8003H is load to control register to the port address. Then to transfer the program
inside the ROM we used MOVX @DPTR, A to control word.

For switch as an input, SW0 to SW7 is move to external to read inside the program
then used ANL A for the logical AND. Then, if the carry is not equal to 1, so it will jump to
loop SW0 SW7 if carry equal to 1 LJMP loop to switch ON the specific LEDs. For example,
for SW0 will LJMP to loop LED0 and so on.
For LEDs as an output, LED0 to LED7 it will ON when the specific switch is
press. If SW0 is pressed LED0 will ON then if SW1 is pressed LED1 will ON. Next,
if SW2 is pressed LED2 will ON then if SW3 is pressed LED3 will ON. For SW4 is
pressed LED4 will ON then if SW5 is pressed LED5 will ON. If SW6 is pressed
LED6 will ON then if SW7 is pressed LED7 will ON.
3

For this exercise 3, as usual we need to test in the trainer board to test the functional

of the program. By using LED0, LED1 and LED6 to switch ON like running light by using
delay then it will OFF then move to the hardware in to the application board. When the
running light test is running, this indicated that the board and the programme are functionally
well and can proceed for the lab exercise. For LEDs it is connect in PPI1 and declare it as
#80H because use port C as an output. Then #8003H is load to control register to the port
address. Then used MOVX @DPTR to transfer the program inside the ROM we used to
control word. This exercise is only use 7-segment to display the number on both 7-segment
counting up from 00 to 99 and connect to PPI 0. For 7-segment is connecting in PPI 0 and
declare it as MOV DPTR, #6003H because use port A as an output and initialize. The 7segment divided in rows and columns.

For rows it used port A from 0 to 3 and for column it used port A from 4-7. This is 7segment BCD that used 4-8 decoders to simplify the binary code. This 7-segment BCD has
two 7-segments that display 00 to 99 by counting. By using MOV A, #00001111B will show
0 on the first bit of 7-segment BCD and LCALL COUNT to perform a counting sequence
from 0-9. Then using MOV A, #11110000B on the second 7-segment to display 0 and using
LCALL DELAY for loop to delay to wait until the first 7-segment BCD is counting to 9 and
increase from 0-9. The delay for 7-segment BCD is to count up. For example, the left 7segment will first counting from 0-9 with delay of 600us and the right 7-segment will have a
long delay of 600us x 10 for the counting sequence.
4

For this exercise 4, as usual we need to test in the trainer board to test the functional

of the program. By using LED0, LED1 and LED6 to switch ON like running light by using
delay then it will OFF then move to the hardware in to the application board. For LEDs it is
connect in PPI1 and declare it as #80H because use port C as an output. Then #8003H is load
to control register to the port address. Then used MOVX @DPTR to transfer the program
inside the ROM we used to control word. This exercise is only use DC motor and connects to
PPI 1 and #8001H to initialize the port B is output for DC motor.
This DC motor is because it is active low. The MOV A, #00000111B is to switch ON
motor, EN1, IN1 and IN2 is ON that is 0. Then, DC motor will rotate clockwise. Next,
MOV DPTR, #8001H is to control EN1, IN1 and IN2 in port B for that is from B.0-B.1.
Next, MOVX @DPTR, A is to excess external hardware. The delay will be rotates three
seconds and stops that is delay for five second and then stop rotates. The delay is 565.285s.
Then, MOV A, #00000111B is to change the port B into input 1 so that the EN1, IN1 and
IN2 are OFF.

For this exercise 5, as usual we need to test in the trainer board to test the functional

of the program. By using LED0, LED1 and LED6 to switch ON like running light by using
delay then it will OFF then move to the hardware in to the application board. When the
running light test is running, this indicated that the board and the programme are functionally
well and can proceed for the lab exercise. For keypad switches it is connect in PPI1 and
declare it as #E001H because use port B as an input. The 7-segment are connect in PPI0 and

declare it as #80H because use port C as an output. Then #6003H is load to control register to
the port address. Then to transfer the program inside the ROM we used MOVX @DPTR, A
to control word. This exercise is only use 7-segment to display the number on both 7-segment
display the number based on the switch which been push on and connect to PPI0. For 7segment is connecting in PPI 0 and declare it as MOV DPTR, #6003H because use port A as
an output and initialize. The 7-segment divided in rows and column.
Firstly, make a program for keypad switch. For each keypad switch will point to one
number that will display to 7-segment. For example, when push on keypad switch 4, the
program will send the input from keypad to output which 7-segment and before that we need
to program a display 7-segment for each switch. So for keypad switch 4, the 7-segment will
display 04 on it.
For rows it used port A from 0 to 3 and for column it used port A from 4-7. This is 7segment BCD that used 4-8 decoders to simplify the binary code. This 7-segment BCD has
two 7-segments that display 0-9 which determined by keypad switch. LCALL DELAY is
used for loop to delay. Each keypad switch has it own 7 segment display program which will
display when turned on.
CONCLUSION
As a conclusion, we are able to write the Intel 8051 input or output assembly
languages programs for 82C55 Programmable Peripheral Interface (PPI device) from
exercises. From this exercise lab, students are able to write and execute program on LED,
switches, 7-segment DC motor.
The 8255 has 24 input/output pins in all. These are divided into three 8-bit ports (Port A,
Port B, Port C). Port A and port B can be used as 8-bit input/output ports. Port C can be used as
an 8-bit input/output port or as two 4-bit input/output ports or to produce handshake signals for
ports A and B.
The three ports are further grouped as follows:
1. Group A consisting of port A and upper part of port C.
2. Group B consisting of port B and lower part of port C.
Eight data lines (D0 - D7) are available (with an 8-bit data buffer) to read/write data into the ports
or control register under the status of the RD (pin 5) and WR (pin 36), which are active low

signals for read and write operations respectively. The address lines A1 and A0 allow to
successively access any one of the ports or the control register as listed below:

A1

A0

Port selected

port A

port B

port C

control register

The objective of the experiment are achieve.

You might also like