Narendra1190
Member level 2
- Joined
- Jan 23, 2014
- Messages
- 44
- Helped
- 6
- Reputation
- 12
- Reaction score
- 6
- Trophy points
- 1,288
- Activity points
- 1,666
hi everyone!!
I am using ATmega32 MCU running at internal osci. frequency 1 Mhz.I have interfaced stepper motor on PORT A.motor moves when ext int occur when '_delay_ms' function is used. It dsnt move when i use timers..check my code.help me.
I am using ATmega32 MCU running at internal osci. frequency 1 Mhz.I have interfaced stepper motor on PORT A.motor moves when ext int occur when '_delay_ms' function is used. It dsnt move when i use timers..check my code.help me.
Code:
#include<avr/io.h>
#include<util/delay.h>
#include<avr/interrupt.h>
unsigned char x[]={0x0A,0x09,0x05,0x06};
unsigned int i = 0,p = 0;
unsigned int j,k,l;
int main()
{
DDRD = 0xFF;
PORTD = ~(1<<PD2);
GICR = 1<<6; // Enable INT0
MCUCR = (1<<ISC01) | (1<<ISC00); // Trigger INT0 on rising edge
SREG = 1<<7; //Enable Global Interrupt
DDRA =0xFF;
TCCR1B = (1<<CS10);
while(1)
{
PORTA = 0x00;
}
}
ISR(INT0_vect)
{
for(l=0;l<100;l++)
{
for(j=0;j<50;j++)
{
if(TCNT1>2000)
{
PORTA = x[i];
TCNT1 = 0;
// _delay_us(2200);
i++;
if(i>3)
i=0;
}
}
for(k=0;k<50;k++)
{
if(TCNT1>2000)
{
i--;
PORTA = x[i];
TCNT1 = 0;
// _delay_us(2200);
if(i==0)
i=4;
}
}
}
}