Skip to content Skip to navigation

Connexions

You are here: Home » Content » Introduction to Programming the MSP430

Navigation

Lenses

What is a lens?

Definition of a lens

Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

Who can create a lens?

Any individual member, a community, or a respected organization.

What are tags? tag icon

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

This content is ...

Affiliated with (What does "Affiliated with" mean?)

This content is either by members of the organizations listed or about topics related to the organizations listed. Click each link to see a list of all content affiliated with the organization.

Recently Viewed

This feature requires Javascript to be enabled.

Tags

(What is a tag?)

These tags come from the endorsement, affiliation, and other lenses that include this content.
Download
x

Download module as:

  • PDF
  • EPUB (what's this?)

    What is an EPUB file?

    EPUB is an electronic book format that can be read on a variety of mobile devices.

    Downloading to a reading device

    For detailed instructions on how to download this content's EPUB to your specific device, click the "(what's this?)" link.

  • More downloads ...
Reuse / Edit
x

Module:

Add to a lens
x

Add module to:

Add to Favorites
x

Add module to:

 

Introduction to Programming the MSP430

Module by: adrian valenzuela. E-mail the author

Summary: This is a basic tutorial on how to program the basic digital peripherals on the MSP430 on the MSP430F16x Lite Development Board.

Configuring Digital I/O

Digital I/O such as the LEDs and pushbuttons are configured by modifying a several registers pertaining to the port that they are attached to. Check the datasheet to find the respective port number of the peripheral you which to control. For more detailed information about Digital I/O on the MSP430 check Chapter 9: Digital I/O of the User’s Guide.

First, we must assign the direction of the corresponding I/O pins. This is done by setting the direction register, PxDIR, with the appropriate bit. By default, all I/O pins are assigned to be inputs.

  • Bit = 0: The port pin is switched to input direction.
  • Bit = 1: The port pin is switched to output direction.

On the MSP430F16x Lite Development Board the three LEDs are located on Ports 1 and 2. The port number will correspond the to x value in registers such as PxIN, PxOUT, or PxDIR. Therefore, if we wanted to define the direction of a pin on port 2 we would write to P2DIR.

Exercise 1

How do we switch the three pins (P1.7, P2.2, and P2.3) corresponding to the LEDs to be outputs?

Output pins may be toggled using the PxOUT register. LEDs are turned on by setting their corresponding register bits low.

Exercise 2

How would be turn on the three LEDs without modifying any other bits in the register?

Since all I/O registers are set as inputs by default we do not have to set the direction of the push buttons. Each time an input is toggled a bit in PxIN will be modified.

Exercise 3

Write a couple different polling schemes for detecting if BUTTON_1 was pushed.

Note:

PxIN bits corresponding to the push buttons are high by default (i.e. the button is not depressed.)

Exercise 4

Now we will write a program that lights up one of the LEDs and will light up a different LED once BUTTON_2 is pressed. The LED sequence should go as follows: red, green, yellow, repeat.

Create a new project in CrossStudio and make sure you select the correct processor, the MSP430F169.

Include the correct header file by adding the following line at the top of the main.c file.

#include <msp430x16x.h> 

It may be helpful to define some macros for commonly used register values. For example, if we add #define red_on ~0x04 to the top of the file (after the #include) we may call red_on every time we wanted the value ~0x04. Similarly, you may write a function to turn a light on or off.

Complete the program.

Content actions

Download module as:

PDF | EPUB (?)

What is an EPUB file?

EPUB is an electronic book format that can be read on a variety of mobile devices.

Downloading to a reading device

For detailed instructions on how to download this content's EPUB to your specific device, click the "(?)" link.

| More downloads ...

Add module to:

My Favorites (?)

'My Favorites' is a special kind of lens which you can use to bookmark modules and collections. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need an account to use 'My Favorites'.

| A lens I own (?)

Definition of a lens

Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

Who can create a lens?

Any individual member, a community, or a respected organization.

What are tags? tag icon

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

| External bookmarks

Reuse / Edit:

Reuse or edit module (?)

Check out and edit

If you have permission to edit this content, using the "Reuse / Edit" action will allow you to check the content out into your Personal Workspace or a shared Workgroup and then make your edits.

Derive a copy

If you don't have permission to edit the content, you can still use "Reuse / Edit" to adapt the content by creating a derived copy of it and then editing and publishing the copy.