Question

In: Electrical Engineering

Below is a code created on CCS for a ti MSP-432 lauchpad. Port 2(LED2) is showing...

Below is a code created on CCS for a ti MSP-432 lauchpad. Port 2(LED2) is showing a total of 7 colors instead of the 3 colors wanted. What can I change on the code, so it only displays RED, GREEN, and BLUE one after another?

#include <stdint.h> //exact-width integer types
#include <ti\devices\msp432p4xx\driverlib\driverlib.h> //driver library

#define DCO_FREQ    48e6 //unit: Hz

void main(void)
{
    uint32_t n;
    uint16_t p2_data = 0;

    WDT_A_holdTimer(); //stop watchdog timer

    //Enable FPU for DCO Frequency calculation.
    FPU_enableModule();

    //Change VCORE to 1 to support a frequency larger than 24MHz.
    //See data sheet for Flash wait-state requirement for a given frequency.
    PCM_setCoreVoltageLevel(PCM_VCORE1);
    FlashCtl_setWaitState(FLASH_BANK0, 1);
    FlashCtl_setWaitState(FLASH_BANK1, 1);

    //Set the DCO Frequency.
    //DCO nominal frequencies: 1.5, 3, 6, 12, 24, 48 MHz.
    CS_setDCOFrequency(DCO_FREQ);

    //Init clock signals: MCLK, HSMCLK, SMCLK.
    //Can be divided by 1, 2, 4, 8, 16, 32, 64, or 128.
    CS_initClockSignal(CS_MCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1);
    CS_initClockSignal(CS_HSMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_8);
    CS_initClockSignal(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_16);

    //Configure P1.0, P2.0, P2.1, P2.2 as output.
    //P1.0 is connected to a red LED on LaunchPad.
    //P2.0, P2.1, P2.2 are connected to a RGB tri-color LED on LaunchPad.
    GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0);
    GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN0|GPIO_PIN1|GPIO_PIN2);

    while(1)
    {
        //simple delay loop
        for(n=0; n<1000000; n++)
        {
            //do nothing
        }

        GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0);
        GPIO_setOutputLowOnPin(GPIO_PORT_P2, (~p2_data)&0x07);
        GPIO_setOutputHighOnPin(GPIO_PORT_P2, p2_data);

        p2_data++;
        if(p2_data >= 0x08)
        {
            p2_data = 0;
        }
    } //end of while
}

Solutions

Expert Solution

#include <stdint.h> //exact-width integer types
#include <ti\devices\msp432p4xx\driverlib\driverlib.h> //driver library

#define DCO_FREQ    48e6        //unit: Hz

void main(void)
{
    uint32_t n;
    uint16_t p2_data = 1; //make here initial value as 1 instead of zero

    WDT_A_holdTimer(); //stop watchdog timer

    //Enable FPU for DCO Frequency calculation.
    FPU_enableModule();

    //Change VCORE to 1 to support a frequency larger than 24MHz.
    //See data sheet for Flash wait-state requirement for a given frequency.
    PCM_setCoreVoltageLevel(PCM_VCORE1);
    FlashCtl_setWaitState(FLASH_BANK0, 1);
    FlashCtl_setWaitState(FLASH_BANK1, 1);

    //Set the DCO Frequency.
    //DCO nominal frequencies: 1.5, 3, 6, 12, 24, 48 MHz.
    CS_setDCOFrequency(DCO_FREQ);

    //Init clock signals: MCLK, HSMCLK, SMCLK.
    //Can be divided by 1, 2, 4, 8, 16, 32, 64, or 128.
    CS_initClockSignal(CS_MCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_1);
    CS_initClockSignal(CS_HSMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_8);
    CS_initClockSignal(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_16);

    //Configure P2.0, P2.1, P2.2 as output.
  
    //P2.0, P2.1, P2.2 are connected to a RGB tri-color LED on LaunchPad.
   

/*   GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0);   */   //not required

GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN0|GPIO_PIN1|GPIO_PIN2); //only this is required now for RGB

   

while(1)
    {
        //simple delay loop
        for(n=0; n<1000000; n++)
        {
            //do nothing
        }

        /* GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0); */ //not required now


/* GPIO_setOutputLowOnPin(GPIO_PORT_P2, (~p2_data)&0x07); */ //not required


        GPIO_setOutputHighOnPin(GPIO_PORT_P2, p2_data);

        p2_data *= 2;
        if(p2_data >= 0x04)
        {
            p2_data = 1;
        }
    } //end of while
}

Note:-

Now we need to glow RGB LEDs one after another. Initially p2_data = 1 i.e 0b000_0001, so LED zero on port2 will glow. After this p2_data changes to twice of it i.e 1 x 2 = 2 = 0b00000010, so LED one on port2 will glow. Next time p2_data = 2x2 = 4 = 0b00000100 i.e LED 2 on port2 will glow.

Now p2_data = 4x2 =8 i.e. greater than 4, so again p2_data = 1. Infinite loop do the same again and again.


Related Solutions

4.What is the purpose of padding, Message Authentication Code (MAC), handshake protocol, change cyber suite (CCS)...
4.What is the purpose of padding, Message Authentication Code (MAC), handshake protocol, change cyber suite (CCS) protocol? 5.How does TLS provide: confidentiality, availability, integrity, non-repudiation? 6.Is TCP a user of TLS services or does it provide services to TLS (hard question) – explain your answer in one sentence? 7.Does TLS use sequence numbers? 8.Sequence numbers can be used to launch replay attacks (as in TCP).How does TLS protect against replay attacks?
Write the C code required to configure pin 0 on port B to be an input...
Write the C code required to configure pin 0 on port B to be an input with the pullup resistor enabled.
Create a code showing Arduino IMU data being plotted by your Python code.  
Create a code showing Arduino IMU data being plotted by your Python code.  
Below is my code, Replace the 2 static_cast codes to a simpler C++ code. I would...
Below is my code, Replace the 2 static_cast codes to a simpler C++ code. I would like to find another way to compile the program without using static_cast in my code. Thank you #include <iostream> #include <iomanip> using namespace std; class Population { private: int population, birth, death; public: Population() { population = 2; birth = 0; death = 0; } Population(int x, int y, int z) { if (x < 2) population = 0; else population = x; if...
The code below is giving an arithmetic overflow. Correct the below given the below code, so...
The code below is giving an arithmetic overflow. Correct the below given the below code, so that the value of s0 is printed before calling the function fun1, inside the function Fun1 and after returning from Fun1 in main. Upload the corrected .asm or .s file in the drop box. .text main: addi $s0,$zero,2 jal Disp jal Fun1 jal Disp j Exit Fun1: addi $sp,$sp,-4 sw $s0,0($sp) addi $s0,$s0,15 jal Disp lw $s0,0($sp) addi $sp,$sp,4 jr $ra Disp: li $v0,1...
how can B cells be turned on using TI-2 ?
how can B cells be turned on using TI-2 ?
The table below shows data collected on the vessel calls for a port in Ghana, from...
The table below shows data collected on the vessel calls for a port in Ghana, from 2007-2016 to study the relationship between the number of Commercial Vessels (C.V.) and Offshore Vessels (O. V.). Year 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 C. V. (X) 527 486 481 558 623 611 606 543 615 673 O. V. (Y ) 67 129 475 719 1175 1053 758 844 910 928 Assuming a linear regression model E(Y |X = x)...
Q1- Write code in C language(Atmel atmega32 avr microcontroller) (a)-Switches are connected to Port C and...
Q1- Write code in C language(Atmel atmega32 avr microcontroller) (a)-Switches are connected to Port C and Port B and LED’s with PORTD. Write a code to read input from PortB and C and perform following. Addition of both inputs, Subtraction, Multiplication, Division, And, Or, Nor,Xor. (b)- A switch is connected to PD0 and LED’s to Port B and Port C. Write a code to perform following: When switch is 0 send your roll number to Port B. When Switch is...
Answer the following bootstrap question by showing the R code : A set of data X...
Answer the following bootstrap question by showing the R code : A set of data X contains the following numbers: 119.7 104.1 92.8 85.4 108.6 93.4 67.1 88.4 101.0 97.2 95.4 77.2 100.0 114.2 150.3 102.3 105.8 107.5 0.9 94.1 We generated n = 20 observations Xi = 10 Wi+100, where Wi has a contaminated normal distribution with proportion of contamination 20% and σc = 4. Suppose we are interested in testing: H0 : μ = 90 versus H1 :...
.Code for a game of Tetris in C# .Short explanation for a first time user, showing...
.Code for a game of Tetris in C# .Short explanation for a first time user, showing them how to use it and pointing out all of the pertinent features. (1 paragraph) .Provide a few screen shots if possible
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT