Write a small assembly subroutine named delay to poll the TO

Write a small assembly subroutine named delay to poll the TOVF1 flag. When the flag is set (TOV1 = 1), clear the TOV1 flag by writing a 1 (sbi TIFR1, TOV1), and reset the timer value (TCNT1H:TCNT1L = 0 times 0BDC). You may think I just made a mistake by saying write a 1 to the TOV1 flag to clear it - but this is in fact how you clear a flag within the ATmega architecture. Do not ask me why.

Solution

; --------------------------

; ------Delay 250ms ------

Delay:

push r16

wait:

sbis TIFR1, TOV1

rjmp wait

sbi TIFR1, TOV1 // clear flag bit by 1

ldi r16,0x0B // load value high byte 0x0B

sts TCNT1H,r16

ldi r16,0xDC // load value low byte 0xDC

sts TCNT1L,r16

pop r16

ret

 Write a small assembly subroutine named delay to poll the TOVF1 flag. When the flag is set (TOV1 = 1), clear the TOV1 flag by writing a 1 (sbi TIFR1, TOV1), an

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site