write a C function void waitForSignature ( unsingned cher pinNum , unsigned int
ID: 3840744 • 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
In the given method we are priting the pin number when the desired time has been elapsed.
As we know that in C the time in steps of 20 milliseconds. For example, time = 50 refers to one second.
So you can set your Starttimer accordingly and provide it a delay.
waitForSignature ( unsingned cher pinNum , unsigned int min , unsigned int max )
{
while( 1 )
{
printf("Timer to start");
starttimer( (max-min)*50);
while( !endtimer())
{
delay( 50 );
}
printf(" Done go to desired pin"+pinNum);
stopTimer();
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.