Data sheet for chip Attiny 2313A http://www.atmel.com/images/doc8246.pdf Write a
ID: 3863339 • Letter: D
Question
Data sheet for chip Attiny 2313A
http://www.atmel.com/images/doc8246.pdf
Write a C function that makes use of the ATtiny2313A's Timer 1 input capture facility to measure and return the time (in seconds, accurate to the nearest multiple of a timer count) of a positive pulse (0 rightarrow 1 and then 1 rightarrow 0) applied to the relevant input pin. You may assume that the timer's prescaler is set to divide-by-one, and that F_CPU has been defined elsewhere in the program. Please do not use interrupts: your routine may/is expected to block (wait) until a full pulse has been received. Further, a pulse may be up to 30 minutes in duration, but is guaranteed to never exceed that duration^1. Ensure that the function is appropriately commented; printouts of code are welcomed.Explanation / Answer
Answer:-
#include <avr/io.h>
int main()
{
DDRB = 0x01; //set port B bit zero to output
TCCR1A = 0x00; //normal mode
TCCR1B = (1<<CS11) | (1<<CS10); //use clk/64
TCCR1C = 0x00; //no forced compare
while(1) {
if (TIFR & (1<<TOV1)) { //if overflow bit TOV1 is set
TIFR |= (1<<TOV1); //clear it by writing a one to TOV1
PORTB ^= (1<<PB0); //toggle PB0 each time this happens
} //if
} //while
} // main
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.