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

implement the same time delay, but to do so using only standard ANSI C code; spe

ID: 2085365 • Letter: I

Question

implement the same time delay, but to do so using only standard ANSI C code; specifically, you will implement a time delay using for loops. Once you have the delay put it in a function called TimeDelay(unsigned int delay, unsigned int resolution)

I was thinking on using a nested for loop but I don't know what to put for delay an resolution. Also if you can help me putting it inside the function and with the content of the loop

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

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

// Infinite loop while () TURN_ON_LED1; TURN_ON_LED2; // Wait for approximately 1/4 second delay cycles(2509 TURN OFF LED1 TURN OFF LED2; // Wait for approximately 1/4 second delay_cycles (258000); -

Explanation / Answer

Delay and resolution are the parameters by which you can vary the delay of the delay function. The outer loop decides the value of delay. Every microcontroller needs discrete amount of time to increment a variable. So we have used one intrinsic delay function of 0.25s. Suppose you want delay of 10 seconds, the inner loop executing the intrinsic delay of 0.25second with the resolution of 40

so 0.25 s X 40 = 10sec, So we have to enter the value of delay 10 and resolution 40.   

#include<stdio.h>

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

printf("Enter the values of Delay, resolution");
scanf ("%d,%d", &delay, &resolution );
TimeDelay(delay,resolution);
}

void TimeDelay(unsigned int delay, unsigned int resolution)
{
int i,j;
for(i = 0; i < delay; i++)
for(j= 0; j < resolution; j++)

_delay_cycles(250000); // 1/4th of second

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote