write a C function void waitForSignature ( unsingned cher pinNum , unsigned int
ID: 3840738 • Letter: W
Question
write a C function void waitForSignature ( unsingned cher pinNum , unsigned int min , unsigned int max ) where pinNum is a number from 0to 7 representing PD0 toPD7 . The function simply waits for a pulse of width in the range (min - max ) appar on pinNum (in port d ) for example . waitForSignature (5 , 20 , 90 ) means wait for a pulse of width in the range 20 - 90 millisecond to appear on pin PD5 .
a. use the function Delay(ms) which accepts an integer in milliseconds
b . use the timer to measure time . you do not need to setup the timer , Assume you have a function called startTimer() which initializes the time to zero . Also assume a function call stopTimer() which will return the number of CPU clocks ( Assume Clock speed is 16MHZ ) since startTimer () function was called .
Explanation / Answer
Given, to write a function in "C" having pinNum,min,max as input variables that prints the pin number when the desired time gets.
In C the time in steps of 20 milliseconds.
Ex: Time = 50 refers one sec,Based on that you can set your Start_timer accordingly and it provides delay.
Function
waitForSignature(unsigned char pinNum,unsigned int min,unsigned int max) {
while(1)
{
printf("start time");
start_timer((max-min)*50); // function takes " (max-min)*50 " as input
while(!endtimer()) // loop runs on end time
{
delay(50);// calculates delay
}
printf(" Go to desired pin"+pinNum); // It Displays pin number
stop_timer(); // stops the timer
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.