Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8466509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:21:48+00:00 2026-06-10T15:21:48+00:00

I have an MSP430 G2452 wired up with several toggle switches (read: NOT buttons).

  • 0

I have an MSP430 G2452 wired up with several toggle switches (read: NOT buttons). I know how to set up interrupts and debounce a button, but I am having a hard time setting up my port so I can just sample which switches are closed/on.

I want to be able to read P1IN (with masking) to figure out which switches are closed/on and which are open/off. The switches are connected to GND, and I have the pins they’re connected to pulled up, so when a switch is closed/on, the pin it’s connected to should be pulled down. But P1IN doesn’t seem to change.

I am able to set up an interrupt that triggers when a pin is grounded, but I just want to sample the pins, not use an interrupt. How do I set up my port pins so that I can read their states with PxIN?

// Port 1 setup
    P1SEL = 0;                  // set P1 as digital I/O for all pins
    P1DIR = ~sw1to6;            // set switches 1-6 for input
    P1OUT = sw1to6;             // enable pull-ups on switches 1-6
    P1REN |= sw1to6;            // enable pull-up resistors on switches 1-6

(header file definitions:)

// P1.0-1.5
#define sw1 0x01
#define sw2 0x02
#define sw3 0x04
#define sw4 0x08
#define sw5 0x10
#define sw6 0x20
#define sw1to6 sw1 | sw2 | sw3 | sw4 | sw5 | sw6
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T15:21:50+00:00Added an answer on June 10, 2026 at 3:21 pm

    Since your “sw1to6” macro is not in parenthesis the negation will not do what you expect. You probably want:

    #define sw1to6 (sw1 | sw2 | sw3 | sw4 | sw5 | sw6)
    

    In general it is best to always put your macros in parenthesis.

    After that you should be able to read the pins on P1IN.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an MSP430 Assignment which I'm doing in assembly, and the final part
Have any one tried to activate fancybox thumbnail gallery using a button or an
Have a recurring situation, petty I know, but I'd like to consolidate the following:
Have an app that can use tts to read text messages. It can also
have written this little class, which generates a UUID every time an object of
Have a procedure which looks like Procedure TestProc(TVar1, TVar2 : variant); Begin TVar1 :=
Have done quite a bit of searching for a guide (of any substance) for
Have deployed numerous report parts which reference the same view however one of them
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:
Have a painfully simple blog Post creator, and I'm trying to check if the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.