Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
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.
#include/* * 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 = 25; volatile unsigned int j = 0; volatile unsigned int k = 1; volatile unsigned int l = 0; for(; i > 0; i--) { j += 2; k += 2; } 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); }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started