Shouldnt these codes work the same, or i am messing something ?? because in CTC mode it doesnt work the same
Code 1:
Code 2 :
Moderators note: Please use code tags for pieces of code
Code 1:
Code:
#include <avr/io.h>
#include <avr/interrupt.h>
char x=0;
int main(void)
{
DDRA=0xFF;
PORTA=0x00;
OCR0=0xFF;
TIMSK=(1<<OCIE0);
TCCR0=(1<CS00)|(1<CS02)|(1<WGM01);
sei();
while(1)
{
}
}
ISR(TIMER0_COMP_vect)
{
if(x==4)
{
PORTA++;
x=0;
if (PORTA == 10)
{
PORTA=0;
}
}
x++;
}
Code 2 :
Code:
#include <avr/io.h>
#include <avr/interrupt.h>
int x=0;
int main(void)
{
DDRC|=0xf;
PORTC=0x00;
TCCR0=(1<<CS00)|(1<<CS02);
TIMSK=(1<<TOIE0);
sei();
while(1)
{
}
}
ISR(TIMER0_OVF_vect)
{
if(x==4)
{
if (PORTC==9)
{
PORTC=0;
x=0;
}
else
{
PORTC+=1;
x=0;
}
}
x++;
}
Last edited by a moderator: