PDA

View Full Version : help debug



snk_naveen
12-11-2009, 08:50 PM
hi friends , i wrote a source code for atmega8 for a line follower in C , AVR STUDIO

#include<avr/io.h>

void Delay(unsigned int itime)

{

unsigned int i,j;

for(i=0;i<itime;i++)

for(j=0;j<1275;j++); //Idle loop

}



void main ()
{
DDRC = 0b11111111;
PORTC = 0x00;
DDRD = 0x00; //make port d as input
PORTD = 0xFF; //enable all pull-ups
while(1)
{
if((PIND.0==0)&&(PIND.1==1)){
PORTC|=0b00000001;
Delay(50); /*Delay of 50 ms*/
}
else if((PIND.0==1)&&(PIND.1==0)){
PORTC|=0b00000100;
Delay(50); /*Delay of 50 ms*/
}
else{
PORTC|=0b00000101;
Delay(50); /*Delay of 50 ms*/
}
}
}

the problem is that the "error: expected ')' before numeric constant " pops up for all if else statements .tere might be more problems with this code i guess !! my programming skills are limited so please help!!!!

most of the code is only cut copy paste from different online sources .

avinash_g
12-12-2009, 09:20 AM
Their is no such thing as



PIND.0


in WinAVR (avg-gcc). As you have said u r using AVR Studio but NOT mentioned which COMPILER u are using.

Please see the following tutorial on how you can test a bit within a register in avr-gcc way.

http://extremeelectronics.co.in/avr-tutorials/programming-in-c-tips-for-embedded-development/

snk_naveen
12-12-2009, 04:47 PM
ok i knew i was doing something wrong so please tell me what is the right way to do it !!!

avinash_g
12-12-2009, 05:17 PM
see the link I gave to know how to check a bin in a Byte

snk_naveen
12-14-2009, 05:33 PM
i read the tutorial but its not much use but the othet tutorial

http://extremeelectronics.co.in/avr-tutorials/part-v-digital-io-in-avrs/

was usefull .then again the same method is not working in this program although it works as such as used in your example program ! i tried many methods but none seems to be working..
i would happy if someone could edit my code or hint at someother similar code so that it would work !!!!

shakerobo
12-16-2009, 03:00 PM
here's the code

//delay can be used like _delay_ms(500); for 5sec
//line follower black line on white background
//sensor a2 is the left side sensor and a1 is the right side
//right motor is d3 d4 and left motor is d0 d1 connected via h bridge
#include<avr/io.h>
#include<util/delay.h>

void main ()
{
DDRD = 0b11110000;
DDRA = 0b11111001;
PORTA = 0b00000110;

while(1)
{
if (PINA & 0b00000010)//a1 on white and a2 on black
{
PORTD = 0b00010000;//turn m1 forward
}
else if(PINA & 0b00000100)//a1 on black and a2 on white
{
PORTD = 0b01000000;//turn m2 forward
}
else
{
PORTD = 0b01010000;
}
}
}

snk_naveen
12-16-2009, 05:11 PM
thank you for your help . i will let you know the results....

snk_naveen
12-26-2009, 08:07 PM
hey i have used the above mentioned code but for some reason when i tested it only takes one sensor input and the other doesn't respond to what ever i do !!!!!

rao
12-27-2009, 10:06 AM
hey i have used the above mentioned code but for some reason when i tested it only takes one sensor input and the other doesn't respond to what ever i do !!!!!

Hi Naveen,

Just checking, but what pins have you connected your sensors to?

Rao

snk_naveen
12-27-2009, 12:51 PM
since i use ATMEGA8 i changed the PINA to PINC and connected the sensor to pins 1 and 2 respectively , the inputs to pin1 works fine but pin2 doesn't work.

rao
12-27-2009, 03:23 PM
Hi Naveen, if you are numbering the pins from 0-7 then the code is meant for pins 1 and 2 , if you are numbering the pins from 1-8 then the code is for pins 2 and 3. I am just checking to confirm with you.

It is weird though that pin the pin 1 sensor works and the pin 2 sensor doesnt work.. can you please make sure that all your circuits are correct and the other sensor is actually sending some signal to the pin?? Sometimes we overlook the most basic issues and blame it on conceptual (coding) parts. Please make sure and let me know.

Rao

snk_naveen
12-28-2009, 02:14 PM
hi rao ,
i am numbering from 0-7 only and i removed the sensor and tested it with a breadbord instead and got wierd result !!
when i grounded pin1 and left the pin2 alone one led turns one ,when i grounded pin2 and left the pin1 alone the other led turns on . When i ground both the leds turn off so no problem with that but when i left both pins without any connection or if i connect both to +5 only one led lights up !! i want both led to turn on at this point . i double checked all connections there is nothing wrong in it....
i modified the previous code like this

#include<avr/io.h>
#include<util/delay.h>

void main ()
{
DDRD = 0b11111111;
PORTC= 0b00000000;
DDRC = 0b11111001;
PORTC= 0b00000110;

while(1)
{
if (PINC & 0b00000010)
{
PORTD = 0b00010000;
_delay_ms(50);
PORTD&= 0b11101111;
}
else if(PINC & 0b00000100)
{
PORTD = 0b00001000;
_delay_ms(50);
PORTD&= 0b11110111;
}
else if(PINC & 0b00000110)
{
PORTD = 0b00000000;
_delay_ms(50);
PORTD&= 0b11111111;
}
else if(PINC & 0b00000000)
{
PORTD = 0b00011000;
_delay_ms(50);
PORTD&= 0b11100111;
}
}
}