BME698:118 Fundamentals of Embedded Systems Lab1: Flashing LED

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 1

BME698:118 Fundamentals of Embedded Systems

Lab1: Flashing LED

To goal of this assignment is to work with the actual embedded hardware by controlling a
flashing LED on Port 1 Pin 1.

Your final software program must be able to blink the LED at a user-specified duty cycle.
Nominally I defined this at 75%, but don’t make this a hard-coded number...use a variable
so you can change the percentage.

You may use the LED flashing program as a reference, but be very aware that the program
is written very poorly for the many reasons I have mentioned. Don’t catch bad
programming habits from this code.

Some guidelines:
 Use #defines appropriately. Create a #define LED_ON and #define LED_OFF for
example.
 Encapsulate the interface to hardware. This means creating one or more
functions with descriptive names like turn_LED_on(), turn_LED_off(). You
choose the names, you choose what arguments are passed to the functions (if
any), and how many functions you use. Realistically, I can think of an
implementation with two functions, and an implementation with one function.
Your choice.
 Use the template – make sure the header (top of the file comments) contains the
function name, function description, your name, version number, and reason for
change (first version is usually described as “Created.”)
 Currently, the period of flashing is 20,000 counts. You can increase this number
so it is easier to see the duty cycle. But remember the limitations of an integer...

Some other info that may help you.....

Check out the header file, msp430x20x3.h. Wander through and find the definitions for
P1DIR and P1OUT. The existing LED program sets the LOWEST BIT (hint hint) for P1DIR to
1. This means that port pin 1 on Port 1 is an output port (1 = output)...that means we can
write values to that port pin to toggle the LED. The program also toggles the LED by using
the command:

P1OUT ^= 0x01;

This is NOT identical to:

P1OUT = 0x01;

Remember, we are interested in changing only ONE BIT on the port, but the port has 8 bits.

For the more adventurous of you, figure out how to do this with the least amount of ROM
possible, while still fulfilling the guidelines for encapsulation, etc. Use the MAP file to see
how much ROM was used.

You might also like