打印

MSP430F22x4端口操作(转)

[复制链接]
1691|6
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
foreverly|  楼主 | 2010-12-13 14:37 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
1.Digital I/O Introduction
                    MSP430 devices have up to 6 digital I/O ports implemented, P1 - P6. Each port
         has eight I/O pins. Every I/O pin is individually configurable for input or output direction,
         and each I/O line can be individually read or written to.Ports P1 and P2 have interrupt
         capability. Each interrupt for the P1 and P2 I/O lines can be individually enabled and
         configured to provide an interrupt on a rising edge or falling edge of an input signal.
        All P1 I/O lines source a single interrupt vector, and all P2 I/O lines source a different,
        single interrupt vector.
       The digital I/O features include:
      
Independently programmable individual I/Os

      
Any combination of input or output

      
Individually configurable P1 and P2 interrupts

      
Independent input and output data registers

      
Individually configurable pull-up or pull-down resistors


2 Digital I/O Operation
                    The digital I/O is configured with user software. The setup and operation of the
         digital I/O is discussed in the following sections.

   2.1 Input Register PxIN
               Each bit in each PxIN register reflects the value of the input signal at the corresponding
         I/O pin when the pin is configured as I/O function.
         Bit = 0: The input is low
         Bit = 1: The input is high
         Note: Writing to Read-Only Registers PxIN Writing to these read-only registers results in
                   increased current consumption while the write attempt is active.

2.2 Output Registers PxOUT
              Each bit in each PxOUT register is the value to be output on the corresponding I/O pin
         when the pin is configured as I/O function, output direction, and the pull-up/down resistor
         is disabled.
         Bit = 0: The output is low
         Bit = 1: The output is high
         If the pin’s pull?up/down resistor is enabled, the corresponding bit in the PxOUT register
         selects pull-up or pull-down.
         Bit = 0: The pin is pulled down
         Bit = 1: The pin is pulled up

2.3 Direction Registers PxDIR
               Each bit in each PxDIR register selects the direction of the corresponding I/O pin,
         regardless of the selected function for the pin. PxDIR bits for I/O pins that are selected for
         other functions must be set as required by the other function.
         Bit = 0: The port pin is switched to input direction
         Bit = 1: The port pin is switched to output direction

2.4 Pull Up/Down Resistor Enable Registers PxREN
                 Each bit in each PxREN register enables or disables the pull-up/down resistor of the
         corresponding I/O pin. The corresponding bit in the PxOUT register selects if the pin is
         pulled up or pulled down.
         Bit = 0: Pull-up/down resistor disabled
         Bit = 1: Pull-up/down resistor enabled


2.5 Function Select Registers PxSEL

                 Port pins are often multiplexed with other peripheral module functions. See the
         device-specific data sheet to determine pin functions. Each PxSEL bit is used to select
         the pin function ? I/O port or peripheral module function.
         Bit = 0: I/O Function is selected for the pin
         Bit = 1: Peripheral module function is selected for the pin
                Setting PxSELx = 1 does not automatically set the pin direction. Other peripheral
         module functions may require the PxDIRx bits to be configured according to the direction
         needed for the module function. See the pin schematics in the device-specific datasheet.
         [NOST]:
                When any P1SELx or P2SELx bit is set, the corresponding pin’s interrupt
         function is disabled. Therefore, signals on these pins will not generate P1 or P2 interrupts,
         regardless of the state of the corresponding P1IE or P2IE bit.
                When a port pin is selected as an input to a peripheral, the input signal to the  
         peripheral is a latched representation of the signal at the device pin. While PxSELx=1,
         the internal input signal follows the signal at the pin. However, if the PxSELx=0, the input
         to the peripheral maintains the value of the input signal at the device pin before the
         PxSELx bit was reset.


2.6 P1 and P2 Interrupts
                 Each pin in ports P1 and P2 have interrupt capability, configured with the PxIFG,
         PxIE, and PxIES registers.    All P1 pins source a single interrupt vector,and all P2 pins
         source a different single interrupt vector. The PxIFG register can be tested to determine
         the source of a P1 or P2 interrupt.
         Interrupt Flag Registers P1IFG, P2IFG .     Each PxIFGx bit is the interrupt flag for its
         corresponding I/O pin and is set when the selected input signal edge occurs at the pin.
         All PxIFGx interrupt  flags request an interrupt when their corresponding PxIE bit and the
         GIE bit are set. Each PxIFG flag must be reset with software. Software can also set  each
         PxIFG flag, providing a way to generate a software initiated interrupt.
         Bit = 0: No interrupt is pending
         Bit = 1: An interrupt is pending
                    Only transitions, not static levels, cause interrupts. If any PxIFGx flag becomes set
         during a Px interrupt service routine, or is set after the RETI instruction of a Px interrupt
         service routine is executed, the set PxIFGx flag generates another interrupt. This ensures
         that each transition is acknowledged.
        [Note]:
                  PxIFG Flags When Changing PxOUT or PxDIR Writing to P1OUT, P1DIR, P2OUT,
             or P2DIR can result in setting the corresponding P1IFG or P2IFG flags.


2.7 Interrupt Edge Select Registers P1IES, P2IES

         Each PxIES bit selects the interrupt edge for the corresponding I/O pin.
         Bit = 0: The PxIFGx flag is set with a low-to-high transition
         Bit = 1: The PxIFGx flag is set with a high-to-low transition
         [Note]:
                   Writing to PxIESx Writing to P1IES, or P2IES can result in setting the corresponding
              interrupt flags.
              PxIESx           PxINx          PxIFGx
                  0        →       1                 0           : May be set
                  0        →       1                 1           : Unchanged
                  1        →       0                 0           : Unchanged
                  1        →       0                 1           : May be set
              Interrupt Enable P1IE, P2IE Each PxIE bit enables the associated PxIFG interrupt flag.
              Bit = 0: The interrupt is disabled
              Bit = 1: The interrupt is enabled

2.7 Configuring Unused Port Pins
                         Unused I/O pins should be configured as I/O function, output direction, and left
              unconnected on the PC board, to prevent a floating input and reduce power
              consumption. The value of the PxOUT bit is don’t care, since the pin is unconnected.
              Alternatively, the integrated pull-up/down resistor can be enabled by setting the PxREN
             bit of the unused pin to prevent the floating input. See chapter System Resets, Interrupts,
             and Operating Modes for  termination unused pins.

相关帖子

沙发
bairan168| | 2010-12-14 14:26 | 只看该作者
看得我眼都累了,顶。

使用特权

评论回复
板凳
ty新气象| | 2010-12-22 22:41 | 只看该作者
够累人的。

使用特权

评论回复
地板
3B1105| | 2010-12-25 14:01 | 只看该作者
怎么好像是从用户手册上拷贝过来的吧

使用特权

评论回复
5
米其林r| | 2010-12-28 21:01 | 只看该作者
UG上的

使用特权

评论回复
6
maoyanketi| | 2010-12-30 23:53 | 只看该作者
看着确实挺累的

使用特权

评论回复
7
hfutcq| | 2010-12-31 14:10 | 只看该作者
看得还好!

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

0

主题

486

帖子

1

粉丝