title: Big hex file from small AVR program
body: <p>I am now teaching my friend how to program AVR microcontrollers. We've written this small program, which sends simple morse-like code.</p>
  
  <p>The problem is that, after compilling it both with AVR-GCC and WinAVR the a.out file is almost 30KB and the hex file is 11KB, so that it doesn't fit the attiny2313 flash.</p>
  
  <p>WinAVR CMD: <code>avr-gcc -mmcu=attiny2313 -Os -g main.c</code></p>
  
  <p>Avr-objcopy: <code>avr-objcopy -O ihex a.out a.hex</code></p>
  
  <p>Here is the code:</p>
  
  <pre><code>#define F_CPU 8000000L
  #include &lt;avr/io.h&gt;
  #include &lt;util/delay.h&gt;
  
  void light_led(int ms)
  {
   PORTD |= (1 &lt;&lt; 4);
   _delay_ms(ms);
   PORTD &amp;= ~(1 &lt;&lt; 4);
   _delay_ms(1000);
  }
  
  void send_char(int c)
  {
   int i;
   for(i = 1; i &lt; 8+1; i++)
   {
    if(c &amp; i) light_led(1000);
    else light_led(500); 
   }
  }
  
  int main(void)
  {
   DDRD |= (1 &lt;&lt; 4);
   //char text[] = {'t', 'e', 's', 't'};
   int i;
   for(i = 0; i &lt; 1; i++) send_char(100);//text[i]);
   return 0;
  }
  </code></pre>