In this code the one LED is glowing at one pin PC0 with flash every 50 ms. It has XTAL of 16 MHz. With CPU frequency 16 MHz, even a maximum delay of 16.384 ms can be achieved using a 1024 prescaler. Every 256 prescalar value, it is achieving interrupt.
- DDRC |= (1 << 0)…. In the given code, what does it mean.
- I want to glow all LED at PORTC. For this, what i have to change in
DDRC |= (1 << 0).
#include <avr/io.h>
#include <avr/interrupt.h>
volatile uint8_t tot_overflow;
void timer0_init()
{
TCCR0 |= (1 << CS02);
TCNT0 = 0;
TIMSK |= (1 << TOIE0);
sei();
tot_overflow = 0;
}
ISR(TIMER0_OVF_vect)
{
tot_overflow++;
}
int main(void)
{
DDRC |= (1 << 0);
timer0_init();
while(1)
{
if (tot_overflow >= 12)
{
if (TCNT0 >= 53)
{
PORTC ^= (1 << 0);
TCNT0 = 0;
tot_overflow = 0;
}
}
}
}
Best Answer
Read Bitwise operations!
Read a datasheet!