MSP430 - Header Files

At this point you should have the IAR EW integrated development environment (IDE) up and running. You are now able to setup, edit, download and verify a program written in C running on the target MSP430 chip.

Let us take a break from the coding and look at some of the program elements.

P1OUT represents the address of the 8-bit port PORT1 which is essentially a hardware register.

When we pass a value to the register, we are setting 8 bits simultaneously.

For example,

P1OUT = 0;

sets all 8 bits to zero, while

P1OUT = 255;

sets all 8 bits to one.

Note that the two statements

P1OUT = 255;
P1OUT = 0xFF;

are compiled to identical statements.


P1OUT = 15;
P1OUT = 0x0F;

are identical.

Suppose we wish to alter a single bit while preserving the other seven bits. There are many ways of accomplishing this. The C language provides one such solution in the form of a mechanism using structures and unions.

P1OUT_bit is a structure.

P0, P1, P2, P3, P4, P5, P6 and P7 are members of the P1OUT_bit structure.

We can access any member, for example, the statement

P1OUT_bit.P3 = 1;

will set bit-3 of PORT1, while

P2OUT_bit.P6 = 0;

will reset bit-6 of PORT2.

(On the MSP430 experimental board, bit-3 of PORT1 is labelled P1.3, for example.)

Input/output pins, in general, are by default (on power on reset) configured as input ports. To configure the port as output we need to set a 1 in the appropriate port direction register.

For example, we can configure all of PORT1 pins to be outputs using the instruction

P1DIR = 0xFF;

Similarly, we can configure a pin, for example,

P1DIR_bit.P0 = 1;

will configure P1.0 (pin-2) as output without disturbing the other pins.

How do we know what names have been assigned to the various hardware components and features?

The designers of the microcontroller have established a list of names to use when accessing the hardware. These names are defined in a special text file which in our case is named io430g2553.h

You can locate this file under the Workspace hierarchy by expanding the Files tree.
Double click on the io430g553.h and the file will be opened in a new tab for editing. Note that you are able to freely edit this file but it would be best to leave in unmodified (except for adding your own comments).

Blog entry information

Last update

More entries in General

More entries from MrChips

Share this entry