please dont rip this site

TI MSP430 I/O Ports

Also:

Basics:

In C or any High Level Language you read or write a port the same as you write to any variable. In ASM, you read or write to the port just as you would a register; each port, in fact, has a register. There are several registers that control each ports settings and value.

Each pin of a port corresponds to each bit of that ports register. Bits 0 to 7 of that register are pins 0 to 7 of that port.

P1DIR controls the direction of EACH bit of the port independently. An '1' means the pin works as output, an '0' means the pin works as input. If you write 0x0F (or binary 00001111 or decimal 15) to P1DIR, that means pins P1.0 through P1.3 will be outputs, while P1.4 through P1.7 will be inputs.

P1OUT writes a value on the output pins.

P1SEL selects for each pin if it will be used as a digital I/O or for its secondary funcion (like analog input, PWM output, etc).

P1IN reads the value present at the ports inputs.

The MSP430 does have weak pull-ups for most ports. Set the port as an input and write a 1 to PxOUT, to activate the weak pull-up.

Because there are seperate input and output registers for each IO port, the MSP430's avoid Read-Modify-Write problems that plague other uC's

Sample C code

P1DIR = 0x01; // specified as output port. 0x00 would make it input
* This selects P1.0 as output, all other P1 pins as input.

PIOUT = 0x00; //initialize output port to ground
* here you are writing a '0' to each output pin , that is P1.0 to P1.7;

PISEL = 0x00; // use all pins as digital IO?
* Here you are selecting all P1 pins to be used as digital I/O.

If you just use = then you set all the bits on the port in one command.You can use &= (AND EQUAL) and |= (OR EQUAL) to set or clear some bits while preserving the other bits.

Setting a bit should be accomplished by using the |= so that any bit you want to set gets a 1 in the mask

P1OUT |= 0x01; // turn bit zero of port 1 on. P1.0 is now high

To clear a bit, you use &= with a mask but the original mask has to be inverted using the ~ operator. The following are functionally equivalent

P1OUT &= ~0x01; //turn bit zero of port 1 off. P1.0 is now low
P1OUT &= 0xFE; //turn bit zero of port 1 off. P1.0 is now low

Animated diagram:




modx out

Questions:

See also:


file: /Techref/ti/msp430/ports.htm, 4KB, , updated: 2009/9/14 15:35, local time: 2018/6/18 14:05,
TOP NEW HELP FIND: 
54.81.112.7:LOG IN

 ©2018 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE! / 

<A HREF="http://www.sxlist.com/techref/ti/msp430/ports.htm"> MSP430, I/O Ports</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

 

Welcome to sxlist.com!


Site supported by
sales, advertizing,
& kind contributors
just like you!

Please don't rip/copy
(here's why

Copies of the site on CD
are available at minimal cost.
 

Welcome to www.sxlist.com!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .