WinAVR-noob compiler problem

Go To Last Post
11 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello again experts!
I've been writing a small test program for my hardware, and now I'm trying to compile it, but the compiler gives me some error messages, which I don't understand, but I have a feeling, that I should know what the problem is. Maybe some of you have seen something like these error codes and can help me out by giving me a clue...
My code:

// #include < >
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
//----------------------------------
//Fuses settings notes
//Serial program downloading (SPI) enabled (SPIEN=0)
//Ext. Full-swing Crystal; Start-up time PWRDWN/RESET: 1k CK/14 CK + 0 ms; (CKSEL=0110 SUT=10)
//Eventuelt Clock Output on PORTB0;(CKOUT=0) for at kontrollere at clock prescaling fungerer korrekt.
//Fuses settings notes
//----------------------------------
//Function prototyping område
void init(void);
//Function prototyping område
//----------------------------------
//Defines

//Defines
//----------------------------------
//Global variables
int analogref;	//Global variable for analog part control
int one_reg; //Global variables
int ten_reg; //
int hundred_reg; //


//Globale variable
//----------------------------------

int main(void)
{
init();

//Analog part and displays clear
//clearanalog();

//DEBUG-OPTION
activatedisplay(1);
segmentvalue(1);
activatedisplay(2);
segmentvalue(2);
activatedisplay(3);
segmentvalue(3);
activatedisplay(4);
segmentvalue(4);
activatedisplay(5);
segmentvalue(5);
activatedisplay(6);
for(;;)
	{
//Endless loop
	}

}
//----------------------------------------------------

void init(void)
{
//SETUP OF PROCESSOR
//------------------------------------
//CLOCK SETUP
CLKPR=0x80; //CLKPR change enable
CLKPR=0x02; //Clock prescaling.
//NOTE: this might have to be run twice, see: https://www.avrfreaks.net/index.php?module=PNphpBB2&file=viewtopic&t=10830&highlight=

//TIMER SET-UP
OCR1A=55000; //OCR1A is Compare Timer Clear register. 
TCCR1A=0x00; 
TCCR1B |= (1<<WGM12) | (1<<CS10); //Timer 1 runs CTC with no prescaling with OCR1A as compare reg.
TIMSK1 |= (1<<OCIE1A); //Timer/counter Overflow Interrupt Enable 1 set.
//Note: CS10 starts/stops the timeren. 1=start, 0=stop.

//INTERRUPT-SETUP
PCICR |= 0x02; //PCIE1 enable
PCMSK1 |= 0x0F; //Pin Change Mask set to activate PCINT 8-11.

//I/O-PORT SETUP
DDRC=48; //Some bits on PortC are set as inputs and other as outputs
DDRD=255; //PortD is set up as an out-port.
DDRB=0x03;

//Global interrupt enable
SREG |= 0x80; //I bittet i SREG sættes, hvorved interrupts enables globalt.
}



The error messages I get from the compiler are:

Compiling C: main.c
avr-gcc -c -mmcu=atmega88 -I. -gdwarf-2 -DF_CPU=4000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=./main.lst  -std=gnu99 -Wundef -MMD -MP -MF .dep/main.o.d main.c -o main.o 
main.c: In function 'activatedisplay':
main.c:39: warning: 'main' is normally a non-static function
main.c:120: error: static declaration of 'init' follows non-static declaration
main.c:21: error: previous declaration of 'init' was here
main.c:147: error: expected declaration or statement at end of input
main.c:32: warning: unused variable 'hundred_reg'
main.c:31: warning: unused variable 'ten_reg'
main.c:30: warning: unused variable 'one_reg'
main.c:29: warning: unused variable 'analogref'
make.exe: *** [main.o] Error 1

> Process Exit Code: 2

The "unused variable" thing, I understand, because they are there to be used later with one of the timers, but all the talk about static and non-static functions as well as the "expected statement or declaration" bit got me confused, and I can't seem to figure out what the problems are.
I bet it's really obvious for routined programmers, and if any of you spot one or more errors, please let me know.
Thanks :)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

My guess:

activatedisplay is missing a } bracket.

There are pointy haired bald people.
Time flies when you have a bad prescaler selected.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Dammit! That was impressingly sharp and quick. I didn't even post that function's code, and your guess was right on. Thanks!
... Oh, and pardon my french :)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The output from your compiler is your friend. Learn to understand him, and he will help you.

There are pointy haired bald people.
Time flies when you have a bad prescaler selected.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As a side note, do not include

#include 

directly. It is automatically included in:

#include  

assuming that you set the proper AVR in the makefile (or project settings if you are using AVR Studio).

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hi everyone , i m making a project on resistive touch based wireless mouse , here is my program

#include 
#define F_CPU 9600000
#include 
#include 

unsigned char data;
volatile char trigger;

voidadc_init()
{
   DIDR0 |= 1 << ADC2D;
   ADMUX |= 1 << MUX1;
   ADCSRA |= (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0);
   ADCSRA |= (1 << ADEN);
}

intadc_read(char a)
{
   ADMUX = a;
int dig;
   ADCSRA |= 1 << ADSC;
while (ADCSRA & (1 << ADSC)) ;
dig = ADCW;
return dig;
}

voiduart_send_byte(unsigned char data)
{
unsigned char i;
   TIMSK0 &= ~(1 << OCIE0A);
   TIFR0 |= 1 << OCF0A;
   TCNT0 = 0;
   TIMSK0 |= 1 < OCIE0A;
   PORTB &= ~(1 << PB3);
while (!(TIFR0 & (1 << OCF0A))) ;
   TIFR0 |= 1 << OCF0A;
for (i = 0; i < 8; i++) {
if (data & 1)
         PORTB |= 1 << PB3;
else
         PORTB &= ~(1 << PB3);
data>>= 1;
while (!(TIFR0 & (1 << OCF0A))) ;
      TIFR0 |= 1 << OCF0A;
   }
   PORTB |= 1 << PB3;
while (!(TIFR0 & (1 << OCF0A))) ;
   TIFR0 |= 1 << OCF0A;
}

print(char *p)
{
while (*p) {
uart_send_byte(*p++);
   }
}

voiduart_print_num(int i)
{
if (i < 0) {
uart_send_byte('-');
i *= -1;
   } else if (i == 0) {
uart_send_byte('+');
uart_send_byte('0');
return;
   } else
uart_send_byte('+');
char count = 0;
unsigned char b[5] = { 0 };
while (i) {
b[count++] = i % 10;
i /= 10;
   }
for (count = 4; count >= 0; count--)
uart_send_byte(b[count] + '0');
}

main()
{
int x, y;

   DDRB |= 1 << PB3;
   PORTB |= 1 << PB3;
   TCCR0A |= 1 << WGM01;   // compare mode
   TCCR0B |= (1 << CS00);   //no prescaler
adc_init();
   OCR0A = 83;      //for baudrate 57600
char a = 0;
while (1) {
      DDRB |= (1 << PB2) | (1 << PB0);
      DDRB &= ~((1 << PB4) | (1 << PB1));   //ADC 2
      PORTB &= ~((1 << PB4) | (1 << PB1));
      PORTB |= 1 << PB2;
      PORTB &= ~(1 << PB0);
      //              _delay_ms(10);
      x = adc_read(2);

      DDRB |= (1 << PB4) | (1 << PB1);
      DDRB &= ~((1 << PB2) | (1 << PB0));   //ADC 1
      PORTB &= ~((1 << PB2) | (1 << PB0));
      PORTB |= 1 << PB1;
      PORTB &= ~(1 << PB4);
      //              _delay_ms(10);
      y = adc_read(1);
if (x < 900 && y < 900) {
print("X: ");
uart_print_num(x);
uart_send_byte(' ');
print("Y: ");
uart_print_num(y);
uart_send_byte('\n');
      }
   }

nd m getting this error

error: expected declaration or statement at end of input

cn anyone help me to resolve it ?????????

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Doesn't your indentation tell the whole story? I get the same error shown in AS6. The fact us that your very last '}' is not flush with the left margin as it just closes the while() loop in main() not the end of main() itself.

If I add just one more } to the very end of the code that error goes away and the file compiles OK (though with lots of warnings!). I finally get link errors at the end about a missing uart_send_byte(), uart_print_num() and adc_read() but that's because I haven't got all the .c files in your project.

The thing that comes out of this is the importance of indentation. If you ever get to what you think is "the end" having indented at each { and outdented at each } then there is very likely an inbalance - which is kind of the whole point of using indentation in the first place!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Also, why did you tack this question on to a seven year old thread instead of making your own?

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

HI guys, i am a newbie, in this coding world, and i also had made some codes, but now i'm facing some problems in this code given below:-

 

the robot i'm making is from Spark Lab, India and has an ATmel Mega8 MCU, and when writing the code, it has some errors like, expected declaration or statement at the end of the input, etc.

so, what should i hace to do, plz guys tell fast.

 

#include <avr/io.h>

#include <util/delay.h>

int main(void)

 

{

    while(1)

    {

        DDRB=0b11111111;

PORTB=0b00011110;

//_delay_ms(2000)

PORTB=0b00000000;

//_delay_ms(2000)

PORTB=0b00001010;

//_delay_ms(2000)

PORTB=0b00010100;

}

DDRB=0b11111111;

DDRC=0b11001000;

for (;;)

{       int ls, rs;

ls=PINC&&0b00000010;

rs=PINC&&0b00000100;

}

 

if ((ls==0b00000010)&&(rs==0b00001000));

PORTB=0b00000010;

}

if ((ls==0b00000000)&&(rs==0b00000011));

{

PORTB=0b00001000;

}

 

}

Always away, far away!!!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Place your variables at the start of main.  e.g.

int main(void)
{
    int rs, ls;            //scope is valid for all of function
    while(1)
    {
        DDRB = ...
        ...
        for (;;) 
        {
            ls = ... 
            ...
            if ((ls == ...
        }
    }

//

In fact it all comes down to indenting your program blocks properly.    Then you can see how the program flows.    i.e. put the braces in the right places.

 

David.

 

 

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Also, why did you tack this question on to a seven year old thread instead of making your own?

 

And why am I repeating myself?

Regards,
Steve A.

The Board helps those that help themselves.