sexta-feira, 6 de maio de 2011

Creating a Workspace and debugging your program

In the last post we teach how to create a library to run Morse code in the LED, in this one we will show how to use the workbench to create a desktop and debug the program.
Libraries "CodigoMorse.c" and "CodigoMorse.h" already for download.
 
Create a folder to put the files in any location of "Users", as it is created (C: \ programfiles) the Workbech will always need to be run  as administrator for Windows Vista and 7.
Add this to the libraries folder "inc" found in (C: \ Program Files (x86) \ IAR Systems \ Embedded Workbench 6.0 Kickstart \ 430), and create another folder named "projects".
Put the two libraries ready in the "inc."

Now open the Workbench and go to (File New → File).
Enter your code "main", which can also be found for download:

#include "msp430.h"
#include "CodigoMorse.h"

int main(void)
{
      unsigned char i;
      WDTCTL = WDTPW + WDTHOLD;    // Interrompe o watchdog
      P1DIR |= 0x01;                            // Seta P1 como saida
      for (;;)                                         // Inicia loop infinito
      {
           CodigoMorse('S');
           CodigoMorse('O');
           CodigoMorse('S');
           P1OUT = 0x00;     //Termina a mensagem e aguarda antes de reiniciar
          for(i=0;i<10;i++)
         {
              TempoEntreLetras();
         }
      }
}

Save this file in the "inc" named "MainMorce.c."
After all processes completed, the includes tree looks like this:

The principal libraries of the MSP430 are basic to the main program and all of our libraries that we create, so do not forget to include them.
Now you have everything you need to create a worspace and download the program for the microcontroller.

Let's start by creating and configuring the desktop:
Go (File → New → Workspace), and then (Project → Create New Project).
In the window that opens select "Empty Project" and press "OK".
A new window will open, save with the name "CodigoMorse.ewp" in the "projects".
Go (Project → Options → Options → General Device), select (→ Family MSP430x2xx MSP430F2013)
Finally in (Project → Options → Debugger → Driver), make sure it is selected "FET Debugger" and not "Simulator"

Now your workspace is ready to receive the files:
Click the right mouse button in the left window with the name "Workspace" and then (Add → Add Files).
Add the two ".c" previously created (CodigoMorse.ce MainMorse.c).
Go (File → Save Workspace), and save your desktop with the name "CodigoMorse.eww", not forgetting to be saved in the "projects".

Before running the download you must make sure that no files have errors:
Go (Project → Rebuild All). You should see the following window:


As the Workspace has no errors, the project will be compiling to the microprocessor.
Note also that the entire  includes tree was automatically included.


Go (Project → Download and Debug).
If your computer can not communicate with the microprocessor, probably the board is not been recognized, see the post about installation.
If the communication does not fail the project will be downloaded and Workspace will change.
 
Now you will learn how to use the buttons that control the microprocessor, and can even help you "debug" the program.
From left to right:

1.       
    
1. Reset: resets the project is running.
2. Break: stop the  project, will be inoperable unless the project is being executed.
3. Step Over: Executes the current line of code, and goes to the next.
4. Step Into: Executes the next step of the code. For example, in a for (i = 0; i <5; i + +): if i = 3  is the next step increment i, but without leaving the for.
5. Step Out: ends the steps of the current line. In the previous case is going to be finished directly.
6. Next Statement: Go to the next command line the main program.
7. Run to Cursor: run the program to the line indicated by the cursor. The indicated line will not run.
8. Go: get to run the project.
9. Stop Debugging: Stops the debugging and back to the desktop before.

But, the buttons only work that way if there are functions, if the code does not provide functions, then the button 6 will function the same as 4.
 
It is also useful to use the window "watch", go to (View → Watch).
Now you can select any variable of the code and drag it to that window so you can follow their changing values ​​and thus better understand what is happening.
Now that you know how to use the buttons you can see the SOS step by step, or all at once,  
enjoy!
 
Finally, after two weeks you finally saw the long awaited SOS, but now with all the information you already have and the complete library, you can write whatever you want, you can modify the routines of time, to create functions to perform phrases, etc.

Well, I guess for now is that, send us your questions through the comments, we will try to fix them up, if they need help with workbench, look in your datasheet.

Thanks and until next week when we start talking about the hardware!

Nenhum comentário:

Postar um comentário