Sei sulla pagina 1di 3

ENEE 4700

IAR Workbench Tutorial

Fall 2011

(0) Connect the MSP430 to the computer. If this is the first time it has been connected, the computer may install the driver automatically. After it installs the driver, reboot the computer. (1) Run IAR Embedded Workshop. (2) Select Project -> Create New Project. a. Under Project templates select C -> main and then OK. b. Select a filename (first, etc.). (3) Choose Project -> Options and make the selections below: a. Under General Options select the microcontroller on your board, likely an MSP430G2231. b. Under C/C++ compiler -> Optimization, choose None for the level. This will make debugging easier as no variables will get removed. c. Under Debugger select FET Debugger as the Driver, instead of the default Simulator. The simulator runs on your computer. The FET Debugger loads code on an attached MSP430. d. Select OK to close the Options window. (4) Choose Project -> Make to compile your project. a. It will ask you where to save the workspace (a collection of related projects). Give it some useful name (trial, 4700, etc.). b. The code will now be compiled. No warnings or errors should appear.

(5) This blank project does nothing except disable the watchdog timer. To turn on an LED, we need to do two things. a. Tell the MSP430 that we want to use the appropriate pin as an output, instead of the default input. This is done using pre-defined names for the registers. The code below sets the lsb of Port 1s Direction register. Add it after the single line of code in your main function. P1DIR = BIT0; // Set Port 1 Pin 0 as an output b. Tell the MSP430 to write a one to Port 1, Pin0. This is done by writing a one to the appropriate bit in the appropriate register, in this case Port 1s Output register. P1OUT = BIT0; // Write a 1 on pin 0 only c. Remake the project (Project -> Make) and verify there are no errors or warnings. (6) We now want to download our code to the MSP430. Select Project -> Download & Debug.

ENEE 4700

IAR Workbench Tutorial

Fall 2011

a. You may see additional panes open within the IAR Workbench. The program is now stalled on the MSP430 at the beginning. Before we start it running, go to the View menu and add Disassembly and Register if these panes are not already open. (See below.)

b. From the Register pane, select Port 1/2" from the drop down list. These are the registers that control the digital I/O ports that we will use to control the LEDs. c. Expand the P1OUT and P1DIR registers, as shown below.

(7) We will now step through our code to watch it turn on an LED. a. To the left of the big red X button, are a series of buttons with blue arrows. (These are also available under the debug menu.) These buttons control the execution of the program. The Go button runs the program without stopping

ENEE 4700

IAR Workbench Tutorial

Fall 2011

between instructions. The other buttons halt execution at various points. Select the Next Statement button. Click this and watch how the green line on your code indicates where we are in the program. Note that when you write to a register, its value changes in the Register pane is it is highlighted in red. b. The LED should turn on when you reach the end of your program. (8) To stop debugging your code, select the red X button. You can now modify your code. Do the following: a. Turn the LED on (as above) and then off. Step through your program to see it in action. If you run the program at full-speed, using the Go button, can you see the LED flash? b. Modify your program so that the LED blinks at a constant rate that humans can discern. You will need two loops for this. An outer loop that runs forever and an inner, delay loop. We have yet to cover timers, so our delays will be approximate values. To create a delay loop in C we need to make a loop that executes a certain number of times. for(i = 0; i < 50000; i = i + 1) {} // Delay loop c. The delay loop above does absolutely nothing, but the compiler can realize this and remove it. We need it to remain in the code, so we must declare i as a volatile variable, meaning the compiler shouldnt mess with it. volatile unsigned int i;// loop counter volatile d. When creating your blink code, remember that the MSP430 uses 16-bit numbers. So you cannot easily choose a large delay.

Potrebbero piacerti anche