/* * BasicPrintf.c * * Created: 5.6.2014 7:54:08 * Author: maticpi */ #include #define F_CPU 18432000UL #include #include int MyPutcFunction(char c, FILE* stream); void Init(); //Prepare a stream printf can use (global variable of type FILE): FILE MyStr=FDEV_SETUP_STREAM(MyPutcFunction, NULL, _FDEV_SETUP_WRITE); //MyStr stream contains the pointer to my putc function int main(void) { Init(); stdout = &MyStr; //tell printf which stream to use while(1) { printf("It Works!"); PORTB=0; //Clear leads _delay_ms(3000); // for 3s, then start again } } int MyPutcFunction(char c, FILE* stream) { PORTB=c; //Display characters as binary values on PORTB (LEDs) _delay_ms(1000); //and wait 1s after each character, so we can see it. return 0; //All OK } void Init() { //IO port PORTA=0x08; //0000 1000 PORTB=0x00; //0000 0000 PORTC=0x3E; //0011 1110 PORTD=0x7D; //0111 1101 //1-output, 0-input DDRA=0xF0; //1111 0000 DDRB=0xFF; //1111 1111 DDRC=0xC1; //1100 0001 DDRD=0x82; //1000 0010 }