Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

msp430g2553 issues with C programming : Below is my script: #include unsigned in

ID: 2988609 • Letter: M

Question

msp430g2553 issues with C programming :

Below is my script:

#include

unsigned int i = 0; // Initialize variables. This will keep count of how many cycles between LED toggles

void main(void)

{

WDTCTL = WDTPW + WDTHOLD;

// Stop watchdog timer. This line of code is needed at the beginning of most MSP430 projects.

// This line of code turns off the watchdog timer, which can reset the device after a certain period of time.

                P1DIR |= 0x01; // P1DIR is a register that configures the direction (DIR) of a port pin as an output or an input.

                                                                // To set a specific pin as output or input, we write a '1' or '0' on the appropriate bit of the register.

                                                                // P1DIR =

                                                                // Since we want to blink the on-board red LED, we want to set the direction of Port 1, Pin 0 (P1.0) as an output

                                                                // We do that by writing a 1 on the PIN0 bit of the P1DIR register

                                                                // P1DIR =

                                                                // P1DIR = 0000 0001

                                                                // P1DIR = 0x01 <-- this is the hexadecimal conversion of 0000 0001

                P1OUT = 0x00; // Initialize the red LED to off state

                for (;;) // This empty for-loop will cause the lines of code within to loop infinitely

                {

                                P1OUT ^= 0x01; // Toggle P1.0 using exclusive-OR operation (^=)

                                                                                                // P1OUT is another register which holds the status of the LED.

                                                                                                // '1' specifies that it's ON or HIGH, while '0' specifies that it's OFF or LOW

                                                                                                // Since our LED is tied to P1.0, we will toggle the 0 bit of the P1OUT register

                for(i=0; i< 20000; i++);                  // Delay between LED toggles. This for-loop will run until the condition is met.

                                                                                                                                                //In this case, it will loop until the variable i increments to 20000.

                }

}

I am to make the following happen in a sequence :

Make the red LED blink 10 times faster.

Restore the red LED's blinking rate to previous value

Make green LED also blink

Make Red LED blink twice as fast as the green LED

--> I can only do the above in SEPARATE PROGRAMS, I don't know how to make them happen all in one run.

REQUIRED ORDER:

GREEN RED

0 0

1 1

0 0

0 1

0 0

1 1

Explanation / Answer

You dont need to write different programs for the sequence of events,you just have to write the segments of the codes to perform the specific functions between time delays,just like the for loop time delay you have used in your code for toggling,to increase the blinking rate to 10x,just multiply the current number of increments to 10 times of the previous(you can also write a delay function which calculates exact amount of time and use that function to provide time specific delays),to bring back the blinking rate back to the original just write the same code back(reduce the toggling delay) after a short delay in the continuous loop ,you are running in your program,similarly you can perform all the functions sequentially using delays.

to make the green led also blink,just set the output of the pin to which the green led is attached,you can adjust the blinking rate like the red led case here as well,and as far as the REQUIRED ORDER is concerned,you can set the two outputs(of the red and green leds respectively) simultaneously or individually,so that is not much of a problem