This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/MSP430G2231-EP: CCS/MSP430G2231

Part Number: MSP430G2231-EP
Other Parts Discussed in Thread: MSP430G2231

Tool/software: Code Composer Studio

Hello to every body,

I am a german student and i have a project on Montay on the launchpad msp430 .Were are supposed to write a programm to make the both  LEDs on the Launchpad to shine but i don t have any idea how that is supposed to work and i will be very  thankful when someone could help me.

The task ist we have to make the Leds alternaty shine with a waiting period of 0.1 second anf for that a for Loope should be used .

-How could the the Loop Hull looks like (including the abord condition ) on addressing mode in assembler looks like ?

-How many instructions cycle does this command  on addressing mode needs ?

I will be very gratefull when someone could help me .I wich everybody a nice day and sorry for the language.

  • Hello,

    Luckily TI has example code ready for you to use that implements simple pin toggling. On the TI Resource Explorer there is a folder with code examples for the MSP430G2231. There are two different folders, one is for register level code examples in C-code and the other is for assembly level code examples.

    I'm assuming that since you would like to implement a delay using a "for" loop, then working in the C code example domain would be your best bet. There is a code example called "msp430g2xx1_1.c" which toggles P1.0 in a period of time defined by the "do while" delay loop.

    In your case, you can set P1.6 as an output as well, because P1.0 and P1.6 are connected to the LED's on the MSP430G2xx Launchpads.

    Inside of the for(;;) (a.k.a. while(1) loop), you can set one LED, delay, turn that LED off, set the other LED, delay, turn that LED off, set the other LED, etc...

    The "do while" loop can be replaced with a "for" loop as shown below in order to easily see a delay instruction. Changing the duration of the delay can be done by increasing or decreasing the value that "i" counts down from. Using an oscilloscope or logic analyzer can be used to accurately determine the delay in order to know how to adjust the "i" value.

    Remove:

    i = 50000; // Delay
    do (i--);
    while (i != 0);

    Replace With:

    for(i=50000;i>0;i--);                   // Delay

    Hopefully this helps you get a good start on your project and allows you to finish it up successfully.

    Best regards,

    Matt Calvo

  • hello Math ,

    Thank you very much for your help and sorry for the late reply.you answer was very helpful to me but i have another question.How is the code  (for(i=50000;i>0;i--);                   // Delay) a  delay ? How should the code look likes if i have to make blink each LED for 0,1 second .

  • That statement requests that the CPU count down from 50000 to 0, while doing nothing else. The counting itself provides the delay. If you changed this to count down from, say, 10000 to 0, that would delay for 1/5th of the time.

    The comments in the example don't say how long counting from 50000 is expected to take. My first guess would be 1/2 a second (1Hz blink), but it's best if you try it yourself.

    If indeed the LED stays on for 1/2 (0.5) second each cycle, then divide 50000/5 to get 1/10th (0.1) of a second. If not, adjust the 50000 up/down until you get 1/2 second (judging 1/2 second by eye is much easier than judging 1/10th second).
  • Hi,

    As Bruce suggested, to achieve the delay time of 100ms, you must lower the countdown value to achieve the smaller delay. Currently with a value of 50,000, the delay is approximately 500ms ( I measured it out to be exactly 467ms). Divide the value by 5 down to 10,000 and then measure the pins to tweak the value to get a perfect delay of 100ms.

    Best regards,

    Matt calvo
  • Hello Rony,

    If our support has helped you solve your issues then please go ahead and click "Resolved" so that I can close this thread out and log it.

    Thanks and best regards,

    Matt Calvo
  • hello Matt,

    thank you very much for your help and all your support has help me enougn thank you to every body .Have a nice day you all .

    Thanks and best regards,

    Matt Calvo.

**Attention** This is a public forum