#include #define __STDIO_FDEVOPEN_COMPAT_12 #include #include char g_aMemory[256]; int usart_putchar(char c) { if(c=='\n') usart_putchar('\r'); loop_until_bit_is_set(UCSRA,UDRE); UDR=c; return 0; } int usart_getchar(void) { loop_until_bit_is_set(UCSRA,RXC); return UDR; } void io_init(void) { UCSRB=_BV(RXEN)|_BV(TXEN); UBRRL=25; //9600 baud 6MHZ:38 4MHZ:25 fdevopen(usart_putchar,usart_getchar,0); } int main(void) { char *p; int i; char c; io_init(); __malloc_heap_start=g_aMemory; __malloc_heap_end=g_aMemory+256; while(1) { p=malloc(100); if(p!=0) { for(i=0;i<100;i++) p[i]=i; for(i=0;i<100;i++) printf("%d\n",p[i]); free(p); } else printf("memory alloc fail!\n"); scanf("%c",&c); } }