I am new to programming microcontroller.....I have a got a program from a friend in embedded c for ATmega8 and when i compile in avr studio i get the following error
"c:/winavr-20081205/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr4/crtm8.o
.init9+0x0): undefined reference to `main'
"
I know it is something very basic...but i can't understand it....It is a program on multiple number lock system....Please could anyone just tell if there is any mistake in basic structure...There are four functions(display,key detection,delay and password check) first and then main program... For those who have patience i give the 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 t 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);
}