我现在正在教我的朋友如何编程AVR微控制器.我们编写了这个小程序,它发送简单的莫尔斯式代码.
问题是,在用AVR-GCC和WinAVR对其进行加工后,a.out文件几乎为30KB,十六进制文件为11KB,因此它不适合attiny2313闪存.
WinAVR CMD: avr-gcc -mmcu=attiny2313 -Os -g main.c
AVR-objcopy命令: avr-objcopy -O ihex a.out a.hex
这是代码:
#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 …Run Code Online (Sandbox Code Playgroud)