I am now teaching my friend how to program AVR microcontrollers. We've written this small program, which sends simple morse-like code.
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.
WinAVR CMD: avr-gcc -mmcu=attiny2313 -Os -g main.c
Avr-objcopy: avr-objcopy -O ihex a.out a.hex
Here is the code:
#define F_CPU 8000000L
#include <avr/io.h>
#include <util/delay.h>
void light_led(int ms)
{
PORTD |= (1 << 4);
_delay_ms(ms);
PORTD &= ~(1 << 4);
_delay_ms(1000);
}
void send_char(int c)
{
int i;
for(i = 1; i < 8+1; i++)
{
if(c & i) light_led(1000);
else light_led(500);
}
}
int main(void)
{
DDRD |= (1 << 4);
//char text[] = {'t', 'e', 's', 't'};
int i;
for(i = 0; i < 1; i++) send_char(100);//text[i]);
return 0;
}