Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

WRITE USING AVR ASSEMBLY LANGUAGE. Use a timer/counter to track the number of pu

ID: 2266201 • Letter: W

Question

WRITE USING AVR ASSEMBLY LANGUAGE. Use a timer/counter to track the number of pulses from an external source. The T5 pin on port L associated with timer/counter5 is convenient for this purpose. Use either the A or B signal from the rotary encoder to generate the pulses. Display the number of pulses generated per second on a seven segment display. Use a second timer/counter to measure how much time has passed. You should calculate the average number of pulses per second and update the display every second.  

Explanation / Answer

#include <avr/io.h>
  
void timer0_init()
{
// set up timer with no prescaling
TCCR0 |= (1 << CS00);
  
// initialize counter
TCNT0 = 0;
}
  
int main(void)
{
// connect led to pin PC0
DDRC |= (1 << 0);
  
// initialize timer
timer0_init();
  
// loop forever
while(1)
{
// check if the timer count reaches 191
if (TCNT0 >= 191)
{
PORTC ^= (1 << 0); // toggles the led
TCNT0 = 0; // reset counter
}
}
}