Click here to Skip to main content
15,867,833 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
void delay()
{
TCNT1H = 0;
TCNT1L = 0; 
OCR1A= 15625;
TCCR1A = 0;
TCCR1B = 0x05;
while((TIFR1&(1<<OCF1A))==0){ }
TCCR1A = 0;
TCCR1B = 0;
TIFR1 = 1<<OCF1A;
}


What I have tried:

Anyone can explain the given piece of code. (AVR Embedded C Programming)
Posted
Updated 18-Oct-22 7:31am
Comments
Richard MacCutchan 18-Oct-22 12:03pm    
Since TIFR1 and OCF1A are not defined in that extract, all we can guess is that the function (possibly) waits for some external event to occur.
Waqas Ch 18-Oct-22 12:09pm    
I have tested on Proteus, and it is generating a delay of 1 sec but I'm confused about the mode of the timer is it ctc or normal, there's no any external event scene.
Richard MacCutchan 18-Oct-22 13:55pm    
How can we tell? there is not enough information to answer. I suggest you talk to the person who wrote the code, or ask at the website that you found it on.

1 solution

How are we supposed to know? There is no timer visible in this excerpt of code.

What is going to happen is the processor is going to spin in the while loop until the OFC1A bit is set in TIFR1. The bit shift operator (<<) shifts one by OFC1A places and then a binary AND operation (the &) will test that bit in TIFR1 and if it is zero the while will continue looping.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900