Go Down

Topic: delay prob (Read 980 times) previous topic - next topic

abhishek_s5s

#include <avr/io.h>       //for all avr atmega microcontrollers
#include <util/delay.h>    // busy-wait header file
#include <stdio.h>        // for c code
#include <math.h> 
#define F_CPU 12000000UL  // 8MHz crystal freq

void move_forward(void)
{
int i;
PORTA=0x22;
PORTC=0x02;
for(i=0;i<10;i++)
_delay_ms(1000);
PORTA=0x84;
PORTC=0x08;
for(i=0;i<10;i++)
_delay_ms(1000);
PORTA=0x11;
PORTC=0x01;
for(i=0;i<10;i++)
_delay_ms(1000);
PORTA=0x48;
PORTC=0x04;
for(i=0;i<10;i++)
_delay_ms(1000);

PORTC=0x20;
PORTD=0x22;
for(i=0;i<10;i++)
_delay_ms(1000);
PORTC=0x40;
PORTD=0x84;
for(i=0;i<10;i++)
_delay_ms(1000);
PORTC=0x10;
PORTD=0x11;
for(i=0;i<10;i++)
_delay_ms(1000);
PORTC=0x80;
PORTD=0x48;
for(i=0;i<10;i++)
_delay_ms(1000);
}

void move_backward(void)
{int i;
PORTA=0x22;
PORTC=0x02;
for(i=0;i<10;i++)
_delay_ms(1000);
PORTA=0x48;
PORTC=0x04;
for(i=0;i<10;i++)
_delay_ms(1000);
PORTA=0x11;
PORTC=0x01;
for(i=0;i<10;i++)
_delay_ms(1000);
PORTA=0x84;
PORTC=0x08;
for(i=0;i<10;i++)
_delay_ms(1000);

PORTC=0x20;
PORTD=0x22;
for(i=0;i<10;i++)
_delay_ms(1000);
PORTC=0x80;
PORTD=0x48;
for(i=0;i<10;i++)
_delay_ms(1000);
PORTC=0x10;
PORTD=0x11;
for(i=0;i<10;i++)
_delay_ms(1000);
PORTC=0x40;
PORTD=0x84;
for(i=0;i<10;i++)
_delay_ms(1000);

}

void turn_right(void)
{int i;
PORTA=0x22;
PORTC=0x02;
for(i=0;i<10;i++)
_delay_ms(1000);
PORTA=0x48;
PORTC=0x04;
for(i=0;i<10;i++)
_delay_ms(1000);
PORTA=0x11;
PORTC=0x01;
for(i=0;i<10;i++)
_delay_ms(1000);

PORTC=0x20;
PORTD=0x22;
for(i=0;i<10;i++)
_delay_ms(1000);
PORTC=0x80;
PORTD=0x48;
for(i=0;i<10;i++)
_delay_ms(1000);
PORTC=0x10;
PORTD=0x11;
for(i=0;i<10;i++)
_delay_ms(1000);

}

void turn_left(void)
{int i;
PORTA=0x22;
PORTC=0x02;
for(i=0;i<10;i++)
_delay_ms(1000);
PORTA=0x84;
PORTC=0x08;
for(i=0;i<10;i++)
_delay_ms(1000);
PORTA=0x11;
PORTC=0x01;
for(i=0;i<10;i++)
_delay_ms(1000);

PORTC=0x20;
PORTD=0x22;
for(i=0;i<10;i++)
_delay_ms(1000);
PORTC=0x40;
PORTD=0x84;
for(i=0;i<10;i++)
_delay_ms(1000);
PORTC=0x10;
PORTD=0x11;
for(i=0;i<10;i++)
_delay_ms(1000);

}

int main(void)
{
unsigned int k,h;
DDRA=0xff;               //all pins of portA made as output
DDRB=0x00;               //all pins of portb made as input   
DDRC=0xff;
DDRD=0xff;
while(1)
  {
   k=~PINA;
   h=k & 0x0f;
   PORTB=0x0f;            // pin made to exhibit high initially (pull up reg)
   
   switch (h)
   {
    case 0x02:
    {
     move_forward();
     break;
    }
    case 0x08:
    {
     move_backward();
     break;
    }
    case 0x06:
    {
     turn_right();
     break;
    }
    case 0x04:
    {
     turn_left();
     break;
    }
   }
  }
   return 0;
}







AWOL

#1
May 03, 2012, 09:21 pm Last Edit: May 03, 2012, 09:23 pm by AWOL Reason: 1
Comments.
Yeah, I'm really into comments.

And code tags.

And lack of txt.

But apart from all that, and the poll, great post.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

spycatcher2k

1 - You have started a poll, not asked a question.
2 - This is an arduino forum - use the AVR-Studio or BASCOM or whatever software your are using FORUMS.
Drew.
http://www.uk-pcb.co.uk - My UK Based PCB Fab & Assembly Company
Design work undertaken
SMD & Thru-Hole assembly

michael_x


You have started a poll, not asked a question.

Why do you want a question? A question asks for an answer, a poll for an opinion.

Look at the alternatives given, what's your opinion? ;)

abhishek_s5s

dude michael_x i started using this forum just yesterday, and dont know where to ask the que,if u have any program for dc motor delay code then please post it

Go Up