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

program for microcontroller msp430fr6989 use code composer studio.DO NOT ANSWER

ID: 3348839 • Letter: P

Question

program for microcontroller msp430fr6989 use code composer studio.DO NOT ANSWER IN ASSEMBLY LANGUAGE

2 (b)Write a program that simulates a motor coming up to speed. When S1 is pressed, LED1 blinks at 50% duty cycle for 10 cycles (indicating a motor coming up to speed). After that time, LED2 comes on (indicating the motor is at speed), and can be turned off by pressing S2. 3) Create a flexible program for 2(b) that will reverse the operation of the LEDs if S2 is pressed first (LED2 shows ramp-up, and LED1 shows motor at full speed). Must use functions to control all timing, LED access, etc… Main program should just have loops and function calls.

Explanation / Answer

Let us assume that S1 = PIN1.0 , S2 = PIN1.1 , LED1 = PIN1.2 , LED2 = PIN1.3

Our first task is to identify that the S1 is pressed. When that occurs we need to turn on LED1 at 50% duty cycle for almost 10 cycles and then turn LED2 on for the rest of the time.(Note that for practical demonstration we have to wisely choose the frequency of the LED1 so that we can visually see the dim light of LED1).

Our second task is to reverse the above operation. That is when S2 is pressed LED2 must blink for 10 cycles at 50% duty cycle and LED1 stays ON.

This means we have to write functions which accept inputs as PIN1.x. We must have a function to identify press of the switch and another to blink the Led and another to turn it on. We must also have a function to initialize appropriate variables.

We will use the variable 'case' to choose from the two alternatives.

Here are details of the codewords I have used.

PxDIR --> selects INPUT or OUTPUT mode

PxOUT --> If the pin’s pull?up/down resistor is enabled, the corresponding bit in the PxOUT register selects pull-up or pull-down.
Bit = 0: The pin is pulled down
Bit = 1: The pin is pulled up

Note: I have compiled the code with NO errors in CCS. I haven't run it on hardware yet.

CODE:

#include <msp430.h>

const int delayt = 10000; //Global variable to set the frequency of the 10 cycles of blinking

void toggle(int casex)
{
int i = 0;
int j = 0;
if(casex ==0)
{
for(i = 0;i<10;i++)
{
P1OUT &= BIT2;
_delay_cycles(delayt);
P1OUT &= 0;
_delay_cycles(delayt);
}
}
else
{
for(i = 0;i<10;i++)
{   
P1OUT &= BIT3;
_delay_cycles(delayt);
P1OUT &= 0;
_delay_cycles(delayt);
}
}
}

void sel(int casex)
{
P1DIR |= 0xC; // 00001100 LEDs are configured as ouput and switches as input
P1OUT &= 0xFF; //All outputs are off initially
P1OUT |= BIT1; // Code for switch (S2)to be used
P1REN |= BIT1; // Code for switch (S2) to be used
P1OUT |= BIT0; // Code for switch (S1) to be used
P1REN |= BIT0; // Code for switch (S1) to be used

if(casex==0)
{
if (!(BIT0 & P1IN)) //when S1 is pressed
{
toggle(casex);
P1OUT &= BIT3;
}
if (!(BIT1 & P1IN)) //when S2 is pressed
{
P1OUT = 0xFF;
}
}
else
{
if (!(BIT1 & P1IN)) //when S2 is pressed
{
toggle(casex);
P1OUT &= BIT2;
}
if (!(BIT0 & P1IN)) //when S1 is pressed
{
P1OUT = 0xFF;
}
}
}

int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
int casex = 0; //By defualt we will choose 2(b). Set this to 1 to choose 3
while(1)
{
sel(casex);
}
return 0;
}