CHAPTER 4 I/O PORTS
4.7
Program Example for I/O Ports
This section gives an example program using the I/O ports.
Program Example for I/O Ports
Processing description
•
Ports 0 and 1 are used to illuminate all elements of a seven segment LED (eight segments if
the decimal point is included).
•
The P00 pin is used for the anode common pin of the LED and the P10 to P17 pins operate
as the corresponding segment pins.
Figure 4.7-1 shows the connection example for an eight-segment LED.
Coding example
PDR0
EQU
DDR0
EQU
PDR1
EQU
DDR1
EQU
;--------- Main program -----------------------------------------------------------------------------------------------------------------
CSEG
:
CLRB
MOV
128
Figure 4.7-1 Connection Example for an Eight-Segment LED
MB89120/120A
P00
P17
P16
.
.
.
.
P10
0000H
0001H
0002H
0003H
PDR0:0
PDR1,#11111111B
.
.
.
.
; Address of the Port 0 data register
; Address of the Port 0 data direction register
; Address of the Port 1 data register
; Address of the Port 1 data direction register
; [CODE SEGMENT]
; Set P00 to the "L" level.
; Set all port 1 pins to the "H" level.