Lab Two - Lab Two - Timer/Counter and Interrupt Wallace...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Lab Two - Timer/Counter and Interrupt Wallace Kerrigan, 1541317 wallace.kerrigan@uconn.edu 3 October 2011 Part One
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Figure 1. Flow Chart of Timer/Counter0 and Interrupt with LED Blinking Frequency of 1Hz Explanation An unsigned integer was defined at the start of the program as “x” equal to zero. The port configuration was set up first. DDRD set the LEDs as output, while pins 2, 3, 4, and 6 on PORTD were set to off by default. The timer was configured next. The timer/counter0 control register A was implemented as the general timer of the program, and set to normal mode. Register B was implemented as it sets the rate at which the timer was updated. This pre-scalar value was set to 64. The interrupt enable/disable settings were found in the Timer/Counter Interrupt Mask Register. This allowed the program to interrupt the timer, toggle the LEDs, and reset the timer back to its original value. The unsigned variable which was defined at the beginning was used with a “for” statement as a post-increment operation. An “if” statement was used to define when the interrupt would occur. In this case, the timer counted up to 30, toggled the LEDs, reset the timer to zero, and started over again. Code #include <avr/io.h> #include <avr/interrupt.h> unsigned int x=0; int main (void)
Background image of page 2
// Port configuration DDRD |= 0x5c; // Set LEDs as output PORTD = 0x5c; // Turn off pins 2, 3, 4, 6 (PORTD) // TIMER0 configuration TCCR0A = 0x00; // Set to normal mode, no PWM TCCR0B = 0b00000011; // Sets the rate at which the timer is updated TIMSK0 |= (1 << TOIE0); // Enable overflow interrupt sei(); // Enable global interrupts for (;;) {} } ISR(TIMER0_OVF_vect) // Each time the TCNT overflows - 256 cycles { x++; if (x>30) // Cycles up to 30, then toggles and the LEDs blink; resets to zero, numbers are under 30, nothing happens. Once it's over 30, it will toggle again. { PORTD ^= 0x5c;
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/21/2011 for the course ECE 3411 taught by Professor Park during the Fall '11 term at UConn.

Page1 / 9

Lab Two - Lab Two - Timer/Counter and Interrupt Wallace...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online