Гм. А в чём фича-то? Ну если хотите...
#include <avr/io.h>
#include <avr/eeprom.h>
#include <util/delay.h>
#include <stdio.h>/*Это для извращенцев - можно и не замарачиваться =)*/
static int uart_putchar(char c, FILE *stream);
static FILE mystdout = FDEV_SETUP_STREAM(uart_putchar, NULL, _FDEV_SETUP_WRITE);
static int
uart_putchar(char c, FILE *stream)
{
loop_until_bit_is_set(UCSR0A, UDRE0);
UDR0 = c;
return 0;
}
/**/
// start reading from the first byte (address 0) of the EEPROM
int address = 0;
uint8_t value;
int main(void)
{
#define BAUD 9600
#include <util/setbaud.h>
UBRR0H = UBRRH_VALUE;
UBRR0L = UBRRL_VALUE;
#if USE_2X
UCSR0A |= (1 << U2X0);
#else
UCSR0A &= ~(1 << U2X0);
#endif
stdout = &mystdout;
while(1)
{
// read a byte from the current address of the EEPROM
value = eeprom_read_byte ((uint8_t *)address);
printf("%d\t%d\n", address, value);
// advance to the next address of the EEPROM
address++;
// there are only E2END bytes of EEPROM, from 0 to E2END-1, so if we're
// on address E2END, wrap around to address 0
if (address == E2END)
address = 0;
_delay_ms(500);
};
return 0;
}
AVR Memory Usage
----------------
Device: atmega168
Program: 1836 bytes (11.2% Full)
(.text + .data + .bootloader)
Data: 31 bytes (3.0% Full)
(.data + .bss + .noinit)
Если не замарачиваться с printf будет ещё меньше. А во что компилится Ваш код? Ассемблерники сравним?
Да, исходник получился почти в два раза длиннее, но итоговый код наверняка во столько же (если не больше) эфективнее. Конечно под контроллеры можно писать на крестах, но умеючи - только статические классы, статическое наследование и шаблоны - всё остальное это ненужный оверхед.