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

I\'m suppose to use C programing to replace the _delay_cycles(250000); with for

ID: 2246865 • Letter: I

Question

I'm suppose to use C programing to replace the _delay_cycles(250000); with for loops that produce thett exact same function. I tried to midify the code, by calling the function TimeDelay() which is suppose to replace the _delay_cycles(250000) with for loops. However when I connect the micontroller to my computer and compile the program the LEDs don't light up, which is something the happended with the _delay_cycles(250000). Can someone help me? My main.c code is below

#include <msp430.h>

#include "LED.h"

#define TRUE 1

// Function prototypes

void ConfigureClockModule(void);

void main(void)

{

unsigned int delay=250;

unsigned int resolution=250;

// Stop the watchdog timer, and configure the clock module.

WDTCTL = WDTPW + WDTHOLD;

ConfigureClockModule();

InitializeLEDPortPins();

// Infinite loop

while (TRUE)

{

TURN_ON_LED1;

TURN_ON_LED2;

// Wait for approximately 1/4 second

TimeDelay(delay,resolution);

TURN_OFF_LED1;

TURN_OFF_LED2;

// Wait for approximately 1/4 second

TimeDelay(delay,resolution);

}

}

void TimeDelay(unsigned int delay, unsigned int resolution){

int i,j;

// Wait for approximately 1/4 second

for(i=0; i<delay;i++){

for(j=0; j<resolution; j++);

}

}

void ConfigureClockModule(void)

{

// Configure Digitally Controlled Oscillator (DCO) using factory calibrations.

DCOCTL = CALDCO_1MHZ;

BCSCTL1 = CALBC1_1MHZ;

}

Explanation / Answer

You can create your own delay function by using

Use this function to provide delay.

For example if you want the delay of 2500 ms . then you can use above method like

for (int i=0; i<10;i++){

delay(250);

}

So just find that for how many mili seconds you want the delay and you can use this function. Don't forget to include   #include <time.h>