You are on page 1of 9

THE HONG KONG POLYTECHNIC UNIVERSITY

Department of Electrical Engineering


EE3231 Computer System Principles
Experiment one : Output port for driving seven segment display

Facilities: DC supply
ADuC832 microprocessor module (as shown in Figure 1)
Computer with MedWin software
LED module and 7-segment display

Objectives
1.
2.
3.

To have a basic understanding on how to write simple assembly language programs


To learn basic feature of a microcontroller
To learn sending data via the parallel I/O ports to control simple digital devices

Introduction
The major objective of these experiments is to provide students assembly language
programming experiences as well as learning the input/output features of a microprocessor.
The microprocessor utilized is the ADuC832 which includes features very similar to the 8051
series but enhanced. The language syntax of ADuC832 is similar to the 8086 except that
names of some instructions are not the same. So you must refer to the instruction set for
the ADuC832 when writing your programs.
In these experiments, you will make use of the Input and Output ports to implement simple
devices, such as a timer, calculator, and a motor control.
The microprocessor being used in the experiment is the ADuC832 from Analog Devices. Key
features of the ADuC832 includes:
1. 8-Channel, 12-bit ADC
2. 2 12-bit voltage output DACs
3. Dual output PWM
4. 62Kbytes on-chip program memory
5. 4Kbytes on-chip data memory
6. 2304 bytes on-chip data RAM
7. 8051-based core and 8051 compatible instruction set
From the software point of view, the ADuC832 is compatible to the 8052/8051 so programs
written for the 8052 can be applied to ADuC832 directly or with only minimum
modifications.
Similar to an 8052, the ADuC832 also comes with 8-bit parallel Input/Output ports or I/O
1

ports. The I/O ports are the microprocessors interface to the outside world! Using the I/O
ports, the processor can send out digital signals and therefore can control other digital
devices. For example, the digital signals can turn-on LEDs. Similarly, digital signals
generated by other devices can be inputted to the processor which will then perform different
operations based on the input signals. Proper programs must be devised and stored in the
internal memory of the device in order to achieve the tasks.

8-bit data

I/O Port

Digital
device

In this experiment, you will learn how to program the microprocessor so that data can be sent
out from the I/O port in order to control simple devices, such as a LED. For sending data, we
can use Port 0 (P0), Port 2 (P2), and Port 3 (P3) of the device. The instruction MOV
(move) is used to send data to the port, eg, MOV P0, #0FFH ; will send the binary pattern
11111111 (#0FFH) to port 0 (P0).
Port1
Port0

Port2

The ADuC832
microprocessor

RS232

Port 3

Figure 1 The ADuC832 experiment module

The notation P0.X refers to a particular bit of the port. Example P0.1 refers to Port 0 bit 1.
2

In addition to the I/O ports, you should also make use of the registers (R0 to R7), which are
always used as temporary storage.
Note:
There are 4 I/O ports but Port1 (P1) is only used for input so it is not suitable to
applications related to experiments discussed in this document.
1. Soft copy of this document is available in the ftp.ee.polyu.edu/yffung/ee3121/lab_doc
2. For programming the ADuC832, you do not need to define a segment. However, you
must write END as the last line in your program.

Experiment 1 Sending output signals to control simple digital devices


Part 1 Controlling LEDs
There are 2 LEDs to be controlled. The LEDs are forward biasd so to turn-on a LED, we
need to send a logic 1 (5V) to the LED. The LEDs are located in Pin1 and Pin6 of the
connector. The binary pattern sending out from a port could be used to control the LED. For
example, if Port 2 of ADUC832 is connected to the LED board and #42H is sent to port 2,
using MOV P2, #42H; #42H = #01000010B. Both LEDs will be ON.
If you want to change the on-off patterns of the LEDs, it can be done by using different
values. However, you must call the delay function so that the output can be maintained at
the LED for a visible time. You should try removing all time delay and examine the result
during the experiment.
In the sample program, a delay function using the timer inside the ADuC832 is provided. In
the sample program, the value R5 (Register 5) is used to define the number of times you
want to call the delay function and each time when the delay function is executed, a
delay of 1ms is created. If R5 is 1 then the delay time is equal to 1ms.
In order to write the assembly language program, the software system MedWin is used, you
must go through the description given in the Appendix to learn the basic steps of program
development using MedWin. After the assembly program is completed then you need to
assemble the program and a .hex file will be created by the MedWin. The .hex file is then
downloaded to the ADuC832 processor for execution.
Steps for software development based on the ADuC832
1. Write the assembly language program using MedWin
2. Assemble the program using MedWin and output a .hex file
3. Download the .hex file to the ADuC832 processor using the WSD system (refer to
the Appendix)
4. Connect the hardware modules to the processor
5. Run the program by pressing the reset button on the ADuC832 processor
Controlling LEDs
Procedure:
1. Invoke the MedWin software and create a new project under the Project tool bar.
2. Create a new file under the file tool bar and then add the file to the newly created
project. Now under the File Manager sub-section, you should see the project
4

3.
4.

5.
6.
7.

components include: source files, header, library and output.


Type in the program LED.asm (page 8) in the file editor window.
Save your file and then assemble the file by using the Build option under the
Project tool bar. A .hex file will be created if the program has no error. The name of
the .hex file is same as the name of your project. If error occurs then the Message
sub-window will highlight the cause of the error.
Download the .hex program to the ADuC832 using WSD.
Connect the LEDs to the port used in your program of the ADuC832 board
Press the Reset button to execute the file and observe the result.

Task:
Try changing the on-off pattern as well as the delay time by modifying the LED.asm
program. Patterns such as (you should try out your own patterns):
LED1 LED2
ON
OFF
OFF
ON
ON
ON
OFF
OFF
ON
ON
Repeat

Part 2 Application of 7-segment display


By using the 7-segment decoder, a binary number between 0 to 9 is converted to the proper
pattern to drive the 7-segment LED (refer to the Appendix on 7-segment display for details).
Therefore, to display different values with the 7-segment display, you only need to send
output the corresponding value from an I/O port.
7-segment
Decoder

7-segment
display

7-segment display
Tasks
1. Based on the procedure given in the LED section, create a new project for the 7segment display and type in the program seven.asm (page 9). Assemble and run the
program. Relate the output of the 7-segment display to the statements in the program
and compare the differences between the program led.asm and seven.asm.
2. Modify the program so that the display will repeat the pattern 0->1->3->5->7->9. This can
be done by implementing a loop in your program or simply displaying the number one after
another.
Hints for writing a loop with assembly language program:
There are many approaches to implement a loop in assembly language programming.
The simplest form is using the DJNZ instruction. DJNZ Decrement Jump Not Zero.
The syntax for DJNZ is similar to a FOR loop in C++.
MOV R1, #10 ; initialize the counter of the loop
JumpPoint:
Looping
Some assembly codes such as sending data to the display
DJNZ R1, JumpPoint
The instruction DJNZ stands for decrement the value of R1, if R1 is not zero then go to
JumpPoint again. So the assembly codes between JumpPoint and DJNZ will be executed
repeatedly until the value of R1 equal to 0.
In order to make use of the DJNZ, you need to initialize the value of R1 as well as defining
the label for the program to jump to when value of R1 is not equal to 0.
So a loop between JumpPoint and the DJNZ is formed and how many times to loop
depends on the initial value of R1. Certainly, you can also use other registers as well.
Part 3 Controlling two 7-segment displays (advance task)
If you have time then you can try this!
The two 7-segment display setup has no decoder therefore, you need to turn-on the
segment one by one. Each segment is one LED. The display used is common anode type
so to turn-on the segment, you need a 0. The displays share the same input and they
are enabled by a signal, as shown in the following diagram.

Figure Two seven segment display

Write an assembly language program so that the characters HU can be shown in the
displays.
The two-display setup requires two I/O ports, one is used to enable the display and the
other port is used to send signal to turn-on the corresponding segments.
More advanced task:
Try to store the pattern for 0 to 9 in internal memory of the device in a form of variable and
then show the value with direct/indirect addressing.
Example: to define a memory storage
Xyz db #123
Loading the address of Xyz to a register can be achieved by mov R0, #Xyz
Indirect addressing: mov P0, @R0

Program LED.asm
ORG 100H
Main:
; timer related
MOV TMOD, #021H
MOV TH1, #073H
MOV PLLCON, #00H
SETB TR1
; LEDs are connected PORT 0
Start:
MOV P0 , #0FFH ; turn ON LEDs connect to Port 0
;R5 control the delay time total delay time = R5*1ms !!!
MOV R5,#0100D
ACALL DELAY ; call the delay function !!!
MOV P0, #00H ; turn off leds
JMP Start ; jump back to label Start
;;;;;;;;;;;;;;;; source codes for delay function ;;;;;;;;;;
DELAY:
MOV TH0, #0FAH
MOV TL0, #089H
SETB TR0
DLY0:
JB TF0, DLY1
JMP DLY0
DLY1:
CLR TF0
DJNZ R5, BackDELAY
RET
BackDELAY:
JMP DELAY
END

; end of program

Program seven.asm
PLLCON DATA 0D7H
ORG 100H
JMP Main
Main:
MOV TMOD, #021H
MOV TH1, #073H
MOV PLLCON, #00H
SETB TR1
Start:
MOV P0 , #01H ; BCD 1 send to display the display must be connected to Port 0
;R5 control the delay time !!!
MOV R5,#0100D
ACALL DELAY ; call the delay function !!!
MOV P0, #04H ; send 4 to display
;R5 control the delay time !!!
MOV R5,#0100D
ACALL DELAY ; call the delay function !!!
MOV P0, #07H ; send 7 to display
MOV R5,#0100D
ACALL DELAY ; call the delay function !!!
JMP Start
;;;;;;;;;;;;;;;; source codes for delay function ;;;;;;;;;;
DELAY:
MOV TH0, #0FAH
MOV TL0, #089H
SETB TR0
DLY0:
JB TF0, DLY1
JMP DLY0
DLY1:
CLR TF0
DJNZ R5, BackDELAY
RET
BackDELAY:
JMP DELAY
END

You might also like