write a program in IAR embedded workbench that simulates a s

write a program in IAR embedded workbench that simulates a street light. Using the watchdog timer and making sure the blinkin LED light on the MSP430 is on while the program is being executed. Please and thank you

Solution

Answer:-

IAR Embedded Workbench :

IAR Embedded Workbench for TI MSP430 about which I mentioned in the introductory tutorial on MSP430. We also discussed about input-output operations, and some basic aspects of C programming.

IAR Embedded Workbench is available for a vast range of processors and controllers which includes ARM and AVR as well.

The window of EW430 is usually divided into three parts.

1) Workspace Window :

The EW430 Workspace Window looks something like this. If the image is too small to view, click on it to enlarge.

The top left pane in the IAR window is workspace. This is where the IDE keeps track of all the source code, linker, libraries and dependencies.

You can see and access the source code (usually .c or .asm files), header and library files (usually .h files) being used in compiling and building your project.

2) Editor Window :

It is the big white space where we write the code. It goes without saying that it is the top right pane covering most of the area. Remember that code is poetry you write code.

You can change the font type, font size, color scheme and tons of other features by going to Tools > Options > Editor> Expand Editor and play around.

You can also open multiple editor windows in a project and save them in your project directory, or replace them with the current one anytime you want.

The editor window also comes in handy during simulation of the code.

3) Message Window :

The message window usually shows the errors and warnings during building. Clicking the error will move the cursor to the line in the code where the error has occurred.

First Project – Hello World :

If you are working on MSP430 for the first time, creating your first project will surely titillate you. So, without taking much time, let’s go about your Hello World project step by step.

Step 1 – Create New Project

Open IAR Embedded Workbench. Go to Project > Create New Project. A dialog box will appear. We will write the code in C language, hence expand Cand click on main. Click OK and usual Save as window will appear. Create a separate directory where you can save all your projects, and save each project and associated files in a separate folder inside it.

Step 2 – Workspace and Editor appears

The window containing the workspace and the editor space will appear. The window is shown below. You can also see some lines of code already written for you in the editor.

Step 3 – Write Code

Please make sure you’ve read and understood the previous post before you even continue to read further. Let’s write our first program to light up the two LEDs on the MSP430 Launchpad. If you notice, the red LED (LED1) is connected to P1.0 and the green LED (LED2) is connected to P1.6. Both of them are in active high configuration.

Example Code :

#include \"io430.h\"

int main (void)

{

    // Stop Watchdog Timer to prevent timeout reset

    // We\'ll learn about it a little later

    // For now, just keep in mind that it is needed

    // for most MSP430 projects

    WDTCTL = WDTPW + WDTHOLD;    // WDTCTL = WDTPW | WDTHOLD; would work as well

P1DIR = 0xFF; // Making port 1 output ports

    P1OUT = 0x41; // Making pins P1.0 and P1.6 high

}

Step 4 – Choose your Device

Now, go to Project > Options, and then select General Options under Category. This is where you get to choose the device you are using. I am using MSP430G2131 which is present on the Launchpad.

Step 5 – Save and Compile your Code

If you haven’t done so already, save the project and your code. You can choose any fancy name you like (it’s your project after all). We will now compile our code. Go to Project > Compile or simply press Ctrl+F7. You should see some messages in the message window show up.

Step 6 – Build your Code

Now that we have our source code ready and compiled, the next step is to make the code. Go to Projects > Make or press F7 to make the code. This will build your code and update your built tree in workspace. You shouldn’t see any errors with the program in context, but in case you get any error, please comment below the post.

Step 7 – Debug/Simulate your Code

The next step is to debug the code we just made (or built). Since, we chose simulator in step 4, we don’t need any hardware and we can see the state of registers in the IDE itself.

Step 8 – Step Through your Code

Once you enter debug mode, you can see a new debug toolbar appear in your IDE. Click on the Step-in button in the toolbar and you will see the highlighted line getting executed and states of registers getting changed in the Register partition.

Step 9 – Connect your Hardware

Now, let’s debug using the emulator. Remember in step 4 we mentioned the need for a hardware in order to emulate? Connect your LaunchPad to your computer using mini-USB cable provided with it. Your computer shouldn’t show any error in getting the device connected, since the drivers should have been installed while you were installing IAR EW430. Once connected, go to Project > Options and change the Debugger driver to FET Debugger and click OK.

Step 10 – Debug/Emulate your Code

Again, go to Project >Download and Debug. It will initialize your device and check the connections first. Sometimes, it might give you some type of fatal errors, which means your emulation hardware is not connected to MSP430. If it says, communication error, it means that your Rx and Tx pins are not connected.

Blink LED Light :

Well, up until now, we were merely glowing the two LEDs. Now let’s blink one of them. Modify the code to the following and repeat all the steps. This code blinks the red LED (LED1) on the LaunchPad.

Example code:

#include \"io430.h\"

int main(void)

{

    int i;

// stop watchdog timer

    WDTCTL = WDTPW | WDTHOLD;

// set up P1.0 (LED1) as output

    P1DIR = 0x01;

    // intialize P1.0 (LED1) to 0 (off)

    P1OUT = 0x00;

// loop forever

    for(;;) {

        // toggle LED1 on P1.0

        P1OUT ^= 0x01;

        // wait! we need to see it at least

        for (i = 0; i < 0x6000; i++);

    }

}

write a program in IAR embedded workbench that simulates a street light. Using the watchdog timer and making sure the blinkin LED light on the MSP430 is on whil
write a program in IAR embedded workbench that simulates a street light. Using the watchdog timer and making sure the blinkin LED light on the MSP430 is on whil
write a program in IAR embedded workbench that simulates a street light. Using the watchdog timer and making sure the blinkin LED light on the MSP430 is on whil

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site