MSP-EXP430G2 Launchpad Setting Gpio

Source: Internet
Author: User

I. Background knowledge: Use of logical operators

When the program initializes, it is recommended to use direct assignment for registers with uncertainties in the reset state (such as Pxout), and it is best to modify the registers using logical operators in other cases.

Direct Assignment

REGISTER =0xF0;

"Turn on" a bit (1), keep the other bits unchanged

// turn bit x on // both on

"Close" a bit (0), keep the other bits unchanged

// turn bit x off // both off

"Flip" a bit (reverse), keep the other bits unchanged

// Toggle bit x // Toggle Both
Two. Register for Gpio

As shown in the following table.

  Register                       short Form         Register Type         Initial State     &nb Sp      
  Input   pxin   Read only  -
  Output   pxout   read/write   unchanged
  Direction   pxdir   read/write   Reset with puc

  pullup/pulldown

  resistor Enable

  Pxren   Read/write   Reset with PUC

pxdir: Setting the direction of the IO Pin

-Bit = 0: input (default)

-Bit = 1: Output

pxren: Enable pin internal pull-up/pull-down, typical pull-up/pull-down resistor resistance 35KOHM

-bit=0: Disable the upper/lower pull resistor function (default)

-Bit=1: Enable up/down resistor function

pxin: reflects the level on the PIN

-Bit=0: input is low level

-Bit=1: input is high level

pxout:

-When the up/down resistor is disabled, the function is to set the output level high and low

--bit=0: Output High Level

--bit=1: Output Low Level

-When the Enable up/down resistor, the function is to select the pull up or pull down

--bit=0: Drop down

--Bit=1: Pull-up

Three. Initialization program example

Example 1: Setting P1.0 to Output

1#include"io430.h"2 3 voidMainvoid)4 {5   //Stop watchdog timer to prevent time out reset6Wdtctl = Wdtpw +Wdthold;7 8P1out =0;//Initialize the output state before changing the pin to an output9P1dir |= BIT0;//P1.0 Output 0Ten  One      while(1) A     { -         //code ... -     } the  -}

Example 2: Setting P1.3 as a pull-up input

1#include"io430.h"2 3 #definePUSH2 BIT34 5 voidMainvoid )6 {7     //Stop watchdog timer to prevent time out reset8Wdtctl = Wdtpw +Wdthold;9 TenP1out =0; OneP1out |= PUSH2;//Initialize the Pullup state AP1ren |= PUSH2;//Enable internal Pullup -P1dir &= ~push2;//set P1.3 to input mode (default) -     //State on P1.3: (p1in & PUSH2) = = PUSH2 the  -      while(1) -     { -         //code ... +     } -    +}
Resources

Msp430x2xx Family User ' s Guide
msp430g2553 Datasheet

MSP-EXP430G2 Launchpad Setting Gpio

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.