Tải bản đầy đủ (.pdf) (11 trang)

Parallel Data Input-Output

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (382.8 KB, 11 trang )


h t t p : / / r e s o u r c e . r e n e s a s . c o m Page 103
Chapter 8
Parallel Data Input/Output



Although the programs described in Chapter 6 use the memory and
CPU registers only, this chapter explains how to input and output parallel data.
Among various data input and output, those of parallel data are the simplest
and have a wide variety of uses. They are used for general purposes such as
inputting signals from various sensors and turning lamps or heaters on/off.





8.1 Parallel Data Input/Output


In a microcomputer-applied system, you may want to know the on/off
statuses of some switches or display the current statuses using LEDs or others.
Such simultaneous input/output of several-bit data is referred to as parallel data
input/output and the peripheral functions for parallel data input/output are
called "I/O ports", which have registers and pins as shown in Figure 8.1.

Figure 8.1: Parallel Data Input/Output

Parallel data input/output using I/O ports are performed through
registers as shown in Figure 8.2.


h t t p : / / r e s o u r c e . r e n e s a s . c o m Page 104

Figure 8.2: Parallel Data Input/Output Method

Input function
"1" can be read from I/O port registers when the "High" voltage is
applied to I/O port pins or "0" when "Low". Based on the values read from I/O
port registers, the on/off statuses of the switches connected to pins or the
high/low status of the comparator output can be determined.
Output function
The "Low" voltage is output from I/O port pins when the values written
in I/O port registers are "0" or "High" when "1". Based on the values written in
I/O port registers, the LEDs connected to pins or relays can be turned on and
off.

8.2 Port Configuration

The H8/3048 has ports 1 to B as I/O ports available for parallel data
input/output. Port 7 is for input only.
These ports have data direction registers (DDRs) and data registers
(DRs) as shown in Table 8.1.
The H8/3048 employs the memory-mapped I/O method for data
input/output. This method has no dedicated data input/output instructions such
as "data input instructions" or "data output instructions" and instructions for
writing/reading to/from the memory are also used for data input/output. For
data input/output functions (various registers), addresses are allocated as with
the memory. In the case of the H8/3048, the H'FFFF10 to H'FFFFFF addresses
are used for data input/output functions (various registers).
Accordingly, the MOV and bit handling instructions can be used as
they are and reading/writing from/to addresses between H'FFFF10 and

H'FFFFFF are regarded as being data input/output. In I/O ports, data are output
from pins by writing them in the DR of each port and the statuses of pins can
be input by reading data from the DR.





h t t p : / / r e s o u r c e . r e n e s a s . c o m Page 105
Table 8.1: I/O Port Register Map

Figure 8.3 shows the I/O port block diagram.

Figure 8.3: I/O Port Block Diagram

Depending on the DDR setting, the I/O port pins can be used for either
input or output. Write "1" in the DDR of the target bit to use the corresponding
pin for output or "0" for input.
Since the DDR is a write-only register, the setting cannot be read even
if the MOV instruction is used. If an instruction for reading is executed by
mistake, "1" is always read irrespective of the setting.

h t t p : / / r e s o u r c e . r e n e s a s . c o m Page 106
In the DR, a flip-flop function is provided for the output only. Output data once
written is kept (output) until the next data is written. During data input, on the
contrary, the voltage signal being input to a pin is read as it is, not the data
written in the DR output flip-flop.

Precautions on connecting external equipment to I/O ports
The DDR of each port is set to "0" (input) without modification after

resetting and the pin is in "High-Z" (high impedance) state. Since the DR is
also set to "0" by default, setting the DDR to "1" without modifying the DR
changes the pin to "Low". For circuits like the TTL, the "High-Z" state of the
input is the same as the "High" input.
If a TTL is connected to a port and equipment operating when output
from the port is "High" is externally connected, some operation will be
performed between the time immediately after resetting and until the port is
changed to output.
To prevent this abnormal operation, develop a circuit so as to operate
when output from a port is "Low" and set the DR to "1" before setting the DDR
to output. Since this setting changes the pin from "High-Z" to "High", no
abnormal operation occurs after resetting, keeping external equipment stopped.

8.3 How to Use Ports
8.3.1 Sample Port Output

Figure 8.4 shows an example to set port A to output to control LEDs on/off.

Figure 8.4: Control of LEDs On/Off

In a pin set to output by the DDR, the voltage varies with the contents
of the DR. When LEDs are turned on using port A as shown in Figure 8.4,
write "1" in the corresponding bit of the PADDR to set the corresponding pin
of port A to output. To turn the LEDs on, write "0" in the corresponding bit of

h t t p : / / r e s o u r c e . r e n e s a s . c o m Page 107
the PADR, or "1" to turn them off. To turn only LED1 on, write B'00000010
(H'02) in the PADR.
For the bits set to input (bits to which no LED is connected), writing
data in the DR will not output voltage to the pin. If you attempt to read data

from the DR, the pin voltage, not the written value, is read. As a result, writing
is invalid, not affecting the pin.
LEDs are turned on when a current (IF) of about 10mA is circulated
forward of the diodes. At this time, a forward voltage (VF) of about 2V is
required. Since the port A pin of the H8/3048 will not supply enough current to
drive the LEDs directly, the HD74AC series' CMOS circuit is connected to
drive them. The HD74AC family is capable of supplying a 24mA current with
either "High" or "Low" output. In addition, 4V can be reserved from the
"High" voltage (VOH) at this time to drive the LEDs. Resistance is inserted to
prevent a current of over 10mA from flowing into the LEDs. The resistance to
be inserted is obtained as follows:

Resistance [Ohm] ³ (4V - 2V)/10mA

Port A for turning LEDs on and off using this circuit is initialized as follows:
PADDR: .EQU H'FFFFD1
; Defines the PADDR address

PADR: .EQU H'FFFFD3
; Defines the PADR address
MOV.B #B'00000011,R0L
; Prepares a setting in R0L

MOV.B R0L,@PADR
; Sets the PA1 and PA0 default output values (off)
in PADR

MOV.B R0L,@PADDR
; Writes "1" in lower 2 bits of PADDR and sets
PA1 and PA0 to output pins



Write "1" in the lower 2 bits of the PADR and then set the lower 2 pins
of port A to output. This turns both LED1 and LED2 off by default.
To turn only LED1 on/off, use the following instructions:

BCLR #0,@PADR ; Turns only LED1 on
BSET #0,@PADR ; Turns only LED1 off
BNOT #0,@PADR ; Inverts the on/off status of LED1 only

To control a specific LED only, use the bit handling instruction as
shown above. To control several LEDs simultaneously, on the other hand, it is
better to use the MOV instruction for bulk change than using the bit handling
instruction to change the on/off status for each LED. This is because the bit
handling instruction changes the statuses one by one, taking a long time to
change all the LEDs.

MOV.B #B'00000000,R0L
; Sets LED1 and LED2 On data in R0L

MOV.B R0L,@PADR
; Turns LED1 and LED2 on simultaneously

MOV.B #B'00000011,R0L
; Sets LED1 and LED2 Off data in R0L

MOV.B R0L,@PADR
; Turns LED1 and LED2 off simultaneously


Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×