banglore
Offline
Newbie
Karma: 0
Posts: 2
|
 |
« on: May 03, 2012, 02:15:48 pm » |
#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; }
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
|
 |
« Reply #1 on: May 03, 2012, 02:21:42 pm » |
Comments. Yeah, I'm really into comments.
And code tags.
And lack of txt.
But apart from all that, and the poll, great post.
|
|
|
|
« Last Edit: May 03, 2012, 02:23:38 pm by AWOL »
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Scotland
Offline
God Member
Karma: 3
Posts: 513
Have you had your Arduino fix today?
|
 |
« Reply #2 on: May 03, 2012, 02:22:17 pm » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
Germany
Offline
Edison Member
Karma: 27
Posts: 1511
|
 |
« Reply #3 on: May 03, 2012, 03:40:25 pm » |
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? 
|
|
|
|
|
Logged
|
|
|
|
|
banglore
Offline
Newbie
Karma: 0
Posts: 2
|
 |
« Reply #4 on: May 04, 2012, 03:03:33 am » |
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
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
|
 |
« Reply #5 on: May 04, 2012, 03:11:09 am » |
if u have any program for dc motor delay code If you can explain what "DC motor delay code" is, we'll probably be happy to help. The code you posted above is not Arduino, and this is an Arduino forum, so our answers may not match your expectations. (please try not to use txt)
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Germany
Offline
Edison Member
Karma: 27
Posts: 1511
|
 |
« Reply #6 on: May 04, 2012, 03:13:34 am » |
Sorry.
But you're on the wrong site, not only in the wrong forum. Programming Arduino means main() is hidden, and for delays you deal with the millis() function or even use the delay() function.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 219
Posts: 13898
Lua rocks!
|
 |
« Reply #7 on: May 04, 2012, 03:15:18 am » |
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
Read this before posting a programming questionWe don't make these stickies just for our own amusement you know.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 219
Posts: 13898
Lua rocks!
|
 |
« Reply #8 on: May 04, 2012, 03:16:28 am » |
What do these options even mean?
|
|
|
|
|
Logged
|
|
|
|
|
Durham UK
Offline
Full Member
Karma: 1
Posts: 163
aka Craig Turner
|
 |
« Reply #9 on: May 04, 2012, 03:25:07 am » |
Hi I don't know how the delay function works in C but this looks wrong 12000000 is 12MHz not 8MHz #define F_CPU 12000000UL // 8MHz crystal freq Here is a C program I found that uses <util/delay.h> : /* * Hello world of AVR. Blink led PORTB5 (Arduino digital 13). * * To compile and upload run: make clean; make; make program; * * Copyright 2009-2011 Mika Tuupola * * Licensed under the MIT license: * http://www.opensource.org/licenses/mit-license.php * */ #include <avr/io.h> #include <util/delay.h>
#define F_CPU 16000000UL // 16MHz crystal freq
int main(void) { /* Make PORTB5 (Arduino pin 13) an output. */ DDRB |= _BV(PORTB5);
for(;;){ /* Toggle state of PORTB5 (Arduino pin 13). */ PORTB ^= _BV(PORTB5); // _delay_ms(1000); } /* Never reached. */ return 0; }
I tried it and works.
|
|
|
|
« Last Edit: May 04, 2012, 03:29:58 am by trendski »
|
Logged
|
Craig Turner, blog: http://gampageek.blogspot.co.uk/ It helps with my learning if I write things down, esp. for others to follow (constructive comments welcomed to improve)
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
|
 |
« Reply #10 on: May 04, 2012, 03:28:15 am » |
I've pretty much given up trying to reconcile comments with code. Too much cut-and-paste, too little comprehension.
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 219
Posts: 13898
Lua rocks!
|
 |
« Reply #11 on: May 04, 2012, 03:34:38 am » |
i need the delay for this motor in c lang Whatever that means.
|
|
|
|
|
Logged
|
|
|
|
|
|