The following document contains information on Cypress products. Colophon The products described in this document are designed, developed and manufactured as contemplated for general use, including without limitation, ordinary industrial use, general office use, personal use, and household use, but are not designed, developed and manufactured as contemplated (1) for any use that includes fatal risks or dangers that, unless extremely high safety is secured, could have a serious effect to the public, and could lead directly to death, personal injury, severe physical damage or other loss (i.e., nuclear reaction control in nuclear facility, aircraft flight control, air traffic control, mass transport control, medical life support system, missile launch control in weapon system), or (2) for any use where chance of failure is intolerable (i.e., submersible repeater and artificial satellite). Please note that Spansion will not be liable to you and/or any third party for any claims or damages arising in connection with above-mentioned uses of the products. Any semiconductor devices have an inherent chance of failure. You must protect against injury, damage or loss from such failures by incorporating safety design measures into your facility and equipment such as redundancy, fire protection, and prevention of over-current levels and other abnormal operating conditions. If any products described in this document represent goods or technologies subject to certain restrictions on export under the Foreign Exchange and Foreign Trade Law of Japan, the US Export Administration Regulations or the applicable laws of any other country, the prior authorization by the respective government entity will be required for export of those products. Trademarks and Notice The contents of this document are subject to change without notice. This document may contain information on a Spansion product under development by Spansion. Spansion reserves the right to change or discontinue work on any product without notice. The information in this document is provided as is without warranty or guarantee of any kind as to its accuracy, completeness, operability, fitness for particular purpose, merchantability, non-infringement of third-party rights, or any other warranty, express, implied, or statutory. Spansion assumes no liability for any damages of any kind arising out of the use of the information in this document. ® ® ® TM Copyright © 2013 Spansion Inc. All rights reserved. Spansion , the Spansion logo, MirrorBit , MirrorBit Eclipse , TM ORNAND and combinations thereof, are trademarks and registered trademarks of Spansion LLC in the United States and other countries. Other names used are for informational purposes only and may be trademarks of their respective owners. Fujitsu Semiconductor (Shanghai) Co., Ltd. Application Note MCU-AN-500003-E-11 F²MC-8FX FAMILY 8-BIT MICROCONTROLLER MB95200H/210H SERIES I/O PORT APPLICATION NOTE I/O PORT V1.1 Revision History Revision History Date 2008-03-20 2008-07-18 Author Levi, Zhang Levi, Zhang Change of Records V1.0, First Draft V1.1, Delete description about I2C and external bus in 2.5 Pullup register; add URL in chapter 6 Additional Information This manual contains 17 pages. 1. The products described in this manual and the specifications thereof may be changed without prior notice. To obtain up-to-date information and/or specifications, contact your Fujitsu sales representative or Fujitsu authorized distributor. 2. Fujitsu will not be liable for infringement of copyright, industrial property right, or other rights of a third party caused by the use of information or drawings described in this manual. 3. The contents of this manual may not be transferred or copied without the express permission of Fujitsu. 4. The products contained in this manual are not intended for use with equipments which require extremely high reliability such as aerospace equipment, undersea repeaters, nuclear control systems or medical equipments for life support. 5. Some of the products described in this manual may be strategic materials (or special technology) as defined by the Foreign Exchange and Foreign Trade Control Law. In such cases, the products or portions thereof must not be exported without permission as defined under the law. © 2008 Fujitsu Semiconductor (Shanghai) Co., Ltd. MCU-AN-500003-E-11 – Page 2 I/O PORT V1.1 CONTENTS CONTENTS REVISION HISTORY .............................................................................................................. 2 CONTENTS ............................................................................................................................ 3 1 INTRODUCTION ................................................................................................................ 4 2 I/O PORT............................................................................................................................ 5 2.1 Key Features ............................................................................................................. 5 2.2 Block Diagram ........................................................................................................... 5 2.3 Registers ................................................................................................................... 6 2.3.1 Port Data Register (PDR) ............................................................................ 6 2.3.2 Data Direction Register (DDR) .................................................................... 6 2.3.3 Pull-up Control Register (PUL) .................................................................... 6 2.3.4 Input level Selection Register (ILSR) .......................................................... 6 2.4 Input Mode ................................................................................................................ 7 2.4.1 Digital Port Input or Peripheral Function Input (except ADC) ...................... 7 2.4.2 ADC Input.................................................................................................... 7 2.5 Pull-up Register......................................................................................................... 7 2.6 Output Mode ............................................................................................................. 8 2.6.1 Digital Port Output ....................................................................................... 8 2.6.2 Resource Output ......................................................................................... 8 3 PORT INPUT / UNUSED PINS .......................................................................................... 9 3.1 Port Input / Unused Pins ........................................................................................... 9 4 TECHNICAL INFORMATION .......................................................................................... 11 4.1 Hysteresis Input ...................................................................................................... 11 5 TIPS AND TRICKS .......................................................................................................... 12 5.1 Initial Value ............................................................................................................. 12 5.2 Byte Instructions...................................................................................................... 12 5.3 RMW Instructions .................................................................................................... 12 6 ADDITIONAL INFORMATION ......................................................................................... 13 7 APPENDIX ....................................................................................................................... 14 7.1 Index of Figures ...................................................................................................... 14 7.2 Sample Code .......................................................................................................... 15 7.2.1 Project Name: Digital_IO ........................................................................... 15 7.2.2 Project Name: ADC_Input ......................................................................... 16 7.2.3 Project Name: Peripheral_Output ............................................................. 17 MCU-AN-500003-E-11 – Page 3 I/O PORT V1.1 Chapter 1 Introduction 1 Introduction This application note describes how to use IO Port. The application note describes the function and usage. Please note that in this manual each port number is given with a 1-digit placeholder. “x. yz” always means the bit position 0 - 7. For example, “PDR0_P03” means Port 0 Bit 3. MCU-AN-500003-E-11 – Page 4 I/O PORT V1.1 Chapter 2 I/O Port 2 I/O Port This chapter describes the basic functions of I/O port 2.1 2.2 Key Features Operation as an output or an input port Operation as a peripheral function output or input Operation of pull-up control register Operation of input level selection register Block Diagram Figure 2-1 shows the internal block diagram of an external I/O Port (Port G). Up to 8 I/O-pins can be controlled within one register. The registers are described as follows. Figure 2-1: Block Diagram of Port G Please note that the block diagram only contains the basic functions of a general I/O Port, such as input, output and pull-up resister. MCU-AN-500003-E-11 – Page 5 I/O PORT V1.1 Chapter 2 I/O Port 2.3 Registers Please refer to Chapter 9 in Hardware Manual of MB95200H Series for detailed register setting. 2.3.1 Port Data Register (PDR) This register contains the data bits, if the corresponding port acts as a simple digital output. The values are output values, if the Port Direction Register is set to output mode. Please note that a resource output control bit overwrites the bit of PDR register bit. PDRx_Pyz Pin Function 0 Pin state low (VSS) 1 Pin state high (VDD) 2.3.2 Data Direction Register (DDR) This register contains the bit information of the corresponding pins if they act as input or output. DDRx_Pyz Peripheral Function Output Pin Function 0 Disable Port Input 1 Disable Port Output invalid Enable Peripheral Function Output 2.3.3 Pull-up Control Register (PUL) This register connects an internal pull-up resistor to a port pin. PULx_Pyz Pull-up Resistor 0 Disable 1 Enable Please see Data Sheet for the resistor value. 2.3.4 Input level Selection Register (ILSR) With this register, one of the following input levels can be chosen. ILSR Input Level VIL VIH 0x04 CMOS 0.3 VCC 0.7 VCC 0x00 Hysteresis 0.3 VCC 0.7 VCC Please note that only PDR0_P04 has this function. MCU-AN-500003-E-11 – Page 6 I/O PORT V1.1 Chapter 2 I/O Port 2.4 Input Mode In general, if a pin acts as an input, the corresponding bit in the Data Direction Register (2.3.2) should be set to “0”. If the connected external source may change to high-Z state, please use an external pull-up or pull-down resistor or set the corresponding bit in the Pull-up Register (2.3.3). There are three kinds of input modes as follows: Digital Input means the port is used as a general I/O. ADC Input means the port is only used for analog input function. Peripheral function Input means the port is used as a peripheral input such as external interrupt input. 2.4.1 Digital Port Input or Peripheral Function Input (except ADC) The following register settings shall be done, if a pin acts as a digital port or peripheral function input. DDRx_Pyz = 0; AIDRL_Pyz = 1; // Only if pin shares ADC input 2.4.2 ADC Input The following register settings shall be done, if a pin acts as ADC input. DDRx_Pyz = 0; AIDRL_Pyz = 0; 2.5 // Only if pin shares ADC input Pull-up Register The P0 and PG ports in input mode may enable an internal pull-up resistor (about 50 KΩ, please see Data Sheet for the exact value) by programming the pull-up register (2.3.3). The initial value of “0” disconnects the internal pull-up resistor, writing “1” to the corresponding bit in the PULx enables the resistor. If the port-pin is used as an output, the value of the register bit has no meaning and the pullup resistor is disabled. (Exceptions: For UART output SOT, the internal pull-up resistor can be used if not provided by line driver). Enabled pull-up resistors will be disabled while the microcontroller is in stop mode or timer mode. The resistor is also disabled if the pin is used as ADC input. For a pin shared with other peripheral functions, disable the output of such peripheral functions. In addition, set the corresponding bit in the PUL register to “0”. . MCU-AN-500003-E-11 – Page 7 I/O PORT V1.1 Chapter 2 I/O Port 2.6 Output Mode There are two kinds of output modes as follows: Digital output means the port is used as a general I/O. Peripheral function output means the port is used as peripheral resource output such as 8/16-bit composite timer's output. 2.6.1 Digital Port Output The following register settings shall be done, if a pin acts as a digital port output. DDRx_Pyz = 1; PDRx_Pyx = [pin output state]; [Resource-Output enable] = 0; // disable resource output Note that the resource output enable bit, which may share a port pin, shall be disabled for digital port output function. 2.6.2 Resource Output The following register settings shall be done, if a pin acts as a peripheral output. [Resource-Output enable] = 1; // enable resource output MCU-AN-500003-E-11 – Page 8 I/O PORT V1.1 Chapter 3 Port Input / Unused Pins 3 Port Input / Unused Pins This chapter describes how to connect input port pins and how to proceed with unused pins 3.1 Port Input / Unused Pins It is strongly recommended not to leave the pins unconnected, while they are switched to input and are enabled. Otherwise, these pins may enter a so-called floating state. This may cause a high ICC current, which is adverse to low power consumption modes, and may cause a damage of the MCU. In this case, use the internal pull-up resistors or use external pull-up or pull-down resistors to define the input-level. It is recommended to set the port input enable bit to “0”, if a port pin is unconnected. Never connect a potential divider with almost the same resistor values. Figure 3-1: Recommended Operation of Unconnected Pin Take care of the connection of input pins with other devices, which may enter into High-Z state. Always use internal pull-up or external pull-up or pull-down resistors in this case. Outputs from external circuits should always be connected via a serial resistor to a MCU input pin, in order to prevent latch-up caused by undershoots or overshoots. Debouncing and decoupling capacitors should be chosen as small as possible. MCU-AN-500003-E-11 – Page 9 I/O PORT V1.1 Chapter 3 Port Input / Unused Pins All pins are set to input enabled (i.e. corresponding DDR bits are set to “0”), after power-on reset. Do not connect any input port directly to VCC or VSS (GND)! Always use pull-up or pull-down resistors. MCU-AN-500003-E-11 – Page 10 I/O PORT V1.1 Chapter 4 Technical information 4 Technical information This chapter describes electrical characteristics related to hysteresis input 4.1 Hysteresis Input A hysteresis indicates that the behaviours of input levels, at which ‘1’ is detected and the level at which”0” is detected, are different. Please refer to the section “ELECTRICAL CHARACTERISTICS” in Data Sheet of MB95200H/210H series for detailed description. Kindly note that the power supply current (i.e. the power consumption) of the device may increase, while the input voltage is within the hysteresis area. However, the input current of I/O pin remains constant. Figure 4-1: Power Consumption Level on Hysteresis Input VIL Port hysteresis input level (low-level) specified in Data Sheet VIH Port hysteresis input level (high-level) specified in Data Sheet Hysteresis area MCU-AN-500003-E-11 – Page 11 I/O PORT V1.1 Chapter 5 Tips and Tricks 5 Tips and Tricks This chapter gives some hints on using I/O port. 5.1 Initial Value Take care that the port data is defined before the pin direction is changed to output. Otherwise, the undefined data might be output to I/O pin, until PDRx is written. PDRx = initial_value; DDRx = 0xff; 5.2 // define initial value before port is set to output // set port x to output, after initial value is defined Byte Instructions Instead of bit instructions, use byte-instructions which will be executed faster. 5.3 RMW Instructions Accessing to the Port Data Register (2.3.1) via a read-modify-write instruction always returns register value during a read cycle (of the same read-modify-write instruction), no matter whether the resource output of the corresponding pin is enabled or not. MCU-AN-500003-E-11 – Page 12 I/O PORT V1.1 Chapter 6 Additional Information 6 Additional Information For more information on FUJITSU SEMICONDUCTOR products, please visit the following websites: English version: http://www.fujitsu.com/cn/fsp/services/mcu/mb95/application_notes.html Simplified Chinese Version: http://www.fujitsu.com/cn/fss/services/mcu/mb95/application_notes.html MCU-AN-500003-E-11 – Page 13 I/O PORT V1.1 Chapter 7 Appendix 7 Appendix 7.1 Index of Figures Figure 2-1: Block Diagram of Port G ........................................................................................ 5 Figure 3-1: Recommended Operation of Unconnected Pin ..................................................... 9 Figure 4-1: Power Consumption Level on Hysteresis Input ................................................... 11 MCU-AN-500003-E-11 – Page 14 I/O PORT V1.1 Chapter 7 Appendix 7.2 Sample Code 7.2.1 Project Name: Digital_IO I/O Port is used as a digital input and output main.c #include “mb95200.h” /*--------------------------------------------------------------------------name: Init(); function: initial I/O Port as digital input or output -----------------------------------------------------------------------------*/ void Init (void) { PDR0_P00 = 1; DDR0_P00 = 1; // set P0_P00 output PDR0_P01 = 0; AIDRL_P01 = 1; // disable AN1 input DDR0_P01 = 0; // set P0_P01 input PDR6_P62 = 1; DDR6_P62 = 1; // set P6_P62 output PDR6_P63 = 0; DDR6_P63 = 0; // set P6_P63 input } /*--------------------------------------------------------------------------name: main (); function: main loop -----------------------------------------------------------------------------*/ void main (void) { Init (); while(1); } MCU-AN-500003-E-11 – Page 15 I/O PORT V1.1 Chapter 7 Appendix 7.2.2 Project Name: ADC_Input I/O Port is used as analog input main.c /*--------------------------------------------------------------------------name: Init(); function: initial I/O Port as analog input -----------------------------------------------------------------------------*/ void Init (void) { DDR0_P01 = 0; // P0_P01 inputs AIDRL_P01 = 0; // enable AN1 input } /*--------------------------------------------------------------------------name: main (); function: main loop -----------------------------------------------------------------------------*/ void main (void) { Init (); while(1); } MCU-AN-500003-E-11 – Page 16 I/O PORT V1.1 Chapter 7 Appendix 7.2.3 Project Name: Peripheral_Output IO Port is used as Peripheral Output (e.g. 8/16-bit composite timer) main.c #include "mb95200.h" /*--------------------------------------------------------------------------name: InitCompTimer(); function: initial timer for interval timer (One-shot) function -----------------------------------------------------------------------------*/ void InitCompTimer (void) { T00DR = 0xFF; // set count value TMCR0 = 0x00; // 8-bit, no filtering T00CR0 = 0x00; // interval timer with one-shot mode T00CR1 = 0x00; // disable interrupt T00CR1_OE = 1; // enable output } /*--------------------------------------------------------------------------name: main(); function: main loop, P0_P05 will be output while counter value matches with pre-set value -----------------------------------------------------------------------------*/ void main(void) { InitCompTimer(); T00CR1_STA = 1; // start timer while(1) { while (T00CR1_STA == 0) { T00CR1_STA = 1; } } } MCU-AN-500003-E-11 – Page 17