LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Closed Thread
  Search this Thread
Old 02-26-2009, 10:10 AM   #1
zack670303
LQ Newbie
 
Registered: Feb 2009
Posts: 23

Rep: Reputation: 15
'Undefined refrence to main error' in winavr gcc compiler????


Hi,I am new in compiling programs for microcontrollers...My program gives a undefined reference to main error when done in avr studio 4.15 ysing winavr gcc compiler in ATmega8L.....
This is my program
# include <avr/io.h>
/*
PROGRAM FOR MULTIPLE NUMBER LOCK USING ATmega8.

************************************************************

Function for displaying a digit
*/


void display(int y)
{
if(y==0)
PORTB=0xC0;

else if(y==1)
PORTB=0x79;

else if(y==2)
PORTB=0x24;

else if(y==3)
PORTB=0x30;

else if(y==4)
PORTB=0x19;

else if(y==5)
PORTB=0x12;

else if(y==6)
PORTB=0x02;

else if(y==7)
PORTB=0x78;

else if(y==8)
PORTB=0x00;

else if(y==9)
PORTB=0x10;

else if(y==10)
PORTB=0x3F;

else if(y==11)
PORTB=0x7E;
}
/*
Function to detect a key from key board
*/

int keydetect(void)
{
unsigned char i,y,z;
int dgt=15;
while(dgt==15)
{
int k=0;
y=0x00;
PORTD=0x02;
while(y==0x00)
{
k=0;
i=PIND;
y=(i&0xE0);
if(PORTD==0x10)
{
k=1;
PORTD=0x01;
}

PORTD=(PORTD*0x02);
}
if(k!=1)
PORTD=PORTD/0x02;
else
PORTD=0x10;
z=PORTD;

if(z==0x02)
{
if(y==0x20)
dgt=1;
else if(y==0x40)
dgt=2;
else if(y==0x80)
dgt=3;
}

else if(z==0x04)
{
if(y==0x20)
dgt=4;
else if(y==0x40)
dgt=5;
else if(y==0x80)
dgt=6;
}

else if(z==0x08)
{
if(y==0x20)
dgt=7;
else if(y==0x40)
dgt=8;
else if(y==0x80)
dgt=9;
}

else if(z==0x10)
{
if(y==0x20)
dgt=10;
else if(y==0x40)
dgt=0;
else if(y==0x80)
dgt=11;
}
display(dgt);
while((PIND&0xE0)!=0);
}
return(dgt);
}
/*
Delay function
*/
void delay(int y)
{
int x,z;
for(x=0;x<y;x++)
{
for(z=0;z<30000;z++);
}
}

/*
Function to check a password
*/

int check(int y)
{
int x[3],i,j,e;
int p[3]={5,5,5};
int p2[3]={2,3,4};
int p3[3]={3,4,5};
int p4[3]={4,5,6};
int p5[3]={5,6,7};
int p6[3]={6,7,8};

PORTB=0x0C;
for(i=0;i<3;i++)
{
x[i]=keydetect();
PORTB=0x77;
for(j=0;j<1000;j++);
}
PORTB=0x7E;
e=0;
while(e!=10)
e=keydetect();
j=0;

if(y==0)
{
for(i=0;i<3;i++)
{
if(x[i]!=p[i])
j=1;
}
}

else if(y==1)
{
for(i=0;i<3;i++)
{
if(x[i]!=p1[i])
j=1;
}
if(j==0)
{
PORTB=0x08;
PORTC=(PORTC^0x01);
delay(2000);
}
}

else if(y==2)
{
for(i=0;i<3;i++)
{
if(x[i]!=p2[i])
j=1;
}
if(j==0)
{
PORTB=0x08;
PORTC=(PORTC^0x02);
delay(2000);
}
}

else if(y==3)
{
for(i=0;i<3;i++)
{
if(x[i]!=p3[i])
j=1;
}
if(j==0)
{
PORTB=0x08;
PORTC=(PORTC^0x04);
delay(2000);
}
}

else if(y==4)
{
for(i=0;i<3;i++)
{
if(x[i]!=p4[i])
j=1;
}
if(j==0)
{
PORTB=0x08;
PORTC=(PORTC^0x08);
delay(2000);
}
}

else if(y==5)
{
for(i=0;i<3;i++)
{
if(x[i]!=p5[i])
j=1;
}
if(j==0)
{
PORTB=0x08;
PORTC=(PORTC^0x10);
delay(2000);
}
}

else if(y==6)
{
for(i=0;i<3;i++)
{
if(x[i]!=p6[i])
j=1;
}
if(j==0)
{
PORTB=0x08;
PORTC=(PORTC^0x20);
delay(2000);
}
}

return(j);
}

/*
The main function
*/

int main(void)
{
DDRD=0x1E;
DDRB=0xFF;
DDRC=0x7F;
int y,i,j,e;

while(1)
{
i=check(0);

while(i==0)
{
PORTB=0x2B;
y=keydetect();
display(y);
e=0;
while(e!=10)
e=keydetect();
j=check(y);
if(j==1)
{
PORTB=0X86;
e=0;
while(e!=11)
e=keydetect();
}
}
}
return(1);
}

This my miniproject program......Any help on ports will be given....
 
Old 02-26-2009, 12:47 PM   #2
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 179Reputation: 179
This seems to be a duplicate of this thread; the linked-to thread contains more info. (Reported as duplicate, posted here to prevent automatic reposting of this thread tomorrow.)
 
  


Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting undefined reference to main error?? Mistro116@yahoo.com Programming 14 07-29-2011 08:28 AM
GCC compiler giving syntax error before 'double' error dragonmint Programming 2 06-02-2007 02:07 PM
undefined refrence return status link error azucarmom Programming 7 03-30-2005 11:15 AM
gcc ld error. Undefined reference redness Linux - Software 4 02-08-2005 02:01 AM
Undefined reference error using gcc with Redhat Linux 9.0 armesk Programming 2 08-28-2003 06:42 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:10 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration