Microcontroller › AVR › Issue regarding waveform generation › Hi Lokesh, Try these
March 5, 2013 at 4:19 pm
#9249
Participant
Hi Lokesh,
Try these modifications.
#include <avr/io.h>
#define F_CPU 1000000UL
#include <util/delay.h>
#include <avr/interrupt.h>
//int counter,flag;
int counter = 0, flag = 0; //modification
void timer_init()
{
TCCR1B |= (1 << WGM12)|(1 << CS10)|(1 << CS11);
TIMSK |= (1 << OCIE1A);
TCNT1 = 0;
}
void timer_set()
{
OCR1A = 15624;
sei();
}
ISR(TIMER1_COMPA_vect)
{
//counter++; //modification
if(counter == 60)
{
counter=0;
flag=1;
}
else
counter++;
}
int main()
{
DDRC = 0xFF;
DDRD = 0xFF;
timer_init();
timer_set();
while(1)
{
if(flag) //modification
{
PORTD = 0x80;
_delay_ms(125);
PORTD = 0x00;
_delay_ms(125);
PORTC=0x01;
_delay_ms(125);
PORTC = 0x00;
_delay_ms(125);
PORTC=0x02;
_delay_ms(125);
PORTC = 0x00;
_delay_ms(125);
PORTC=0x80;
_delay_ms(125);
PORTC = 0x00;
_delay_ms(125); //modification
flag = 0; //modification
}
}
}