Lab1 - Seven Segment Display
Lab1 - 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.
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
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.
3.
4.
5.
6.
7.
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
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.
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