Fix the broken C Code The program should blink the Green LED

Fix the broken C Code. The program should blink the Green

LED every half second, but the Red LED is steadily lit. You

may NOT delete or add code, you may only change values

being stored in a variable or register.

Time an iteration of the delay subroutine using the CPU timer

and breakpoints.

Solution

#include <msp430g2553.h>

/*
* Fix this code! You may NOT delete or add code, you may only change values being stored in a variable or register.
*/

void DELAY();
unsigned int CLS(unsigned int x);
unsigned int CRS(unsigned int x);

int main(void) {
WDTCTL = WDTPW | WDTHOLD;

volatile unsigned int m = 1;
volatile unsigned int s = 0;
volatile unsigned int p = 65535;

P1DIR |= m;

while(s)
{
p = CRS(p);
P1OUT = p;
DELAY();
}
}

void DELAY(){
volatile unsigned int i = 15;
volatile unsigned int j = 0;
volatile unsigned int k = 1;
volatile unsigned int l = 0;
  
for(; i > 0; i--)
{
j += 1;
k += 1;
}

l = CLS(j + k);
}

unsigned int CLS(unsigned int x){
return (x << 1) | (x >> 15);
}

unsigned int CRS(unsigned int x){
return (x >> 1) | (x << 15);
}

Fix the broken C Code. The program should blink the Green LED every half second, but the Red LED is steadily lit. You may NOT delete or add code, you may only c
Fix the broken C Code. The program should blink the Green LED every half second, but the Red LED is steadily lit. You may NOT delete or add code, you may only c

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site