Arduino LCD C-code not working in AVR-GCC

In trying to get a KS0073-based LCD to work (20x4), I’m running into a strange problem. The following code works from the Arduino IDE, but doesn’t work at all in GCC:

// vim:set ts=2 sw=2 si syn=c:

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

void ena(void);
void setup(void);
void milli(unsigned int delay);
int  main(void);
void loop(void);

void ena(void) {
  milli(10);
  PORTD |= (1 << 4);
  milli(10);
  PORTD &= ~(1 << 4);
  milli(10);
}

void setup(void) {
  PORTD = 0x00;
  DDRD = 0xff;

  // power on
  // > 20ms
  milli(100);

  // func set
  PORTD = 0x02;      
  ena();

  // > 40us
  milli(1);

  // func set
  PORTD = 0x02;
  ena();
  PORTD = 0x08;
  ena();

  // > 40us
  milli(1);

  // disp on
  PORTD = 0x00;
  ena();
  PORTD = 0x0f;
  ena();

  // > 40us
  milli(1);      

  // clear disp
  PORTD = 0x00;
  ena();
  PORTD = 0x01;
  ena();

  // > 1.5ms
  milli(5);

  // entry mode
  PORTD = 0x00;
  ena();
  PORTD = 0x06;
  ena();
}

void milli(unsigned int delay) {
  for (unsigned int ms=0; ms<delay; ms++) {
    _delay_ms(1);
  }
}

void loop(void) {
  DDRB = (1 << 5);

  while (1) {
    PORTB |= (1 << 5);
    milli(25);
    PORTB = ~PORTB;
    milli(475);
  }
}

int main(void) {
      setup();
      loop();

      return 0;
}

When programming the Diecimila board from the IDE (after removing the main(void) routine, obviously), the connected LCD initializes properly and shows a blinking cursor. When compiling with the supplied Makefile (from arduino-0011), the exact same code just doesn’t do anything at all except for blink the LED. No compilation warnings or errors, just an LCD as blank as my stare… :wink:

So, does anyone have any clue as to what’s happening here? I really love Vim, so using the IDE is a bit unconvenient for me (not saying that it isn’t a great piece of work, just not what I’m used to using). Any insights are greatly appreciated! (Just wanna get the %#$! display to work with pure C).

Hmm, check out the command line page here: http://www.arduino.cc/en/Hacking/CommandLine. It may have a more recent Makefile than the one in Arduino 0011. In either case, it should generate main() for you. In particular, you need a call to init() (defined in wiring.c) in there.

Thanks, that was it! The only thing differing from plain GCC is the bootloader automatically connecting the USART to pins PD0 and PD1. Clearing UCSR0B solved the issue for me.