Danke Thorsten,
hab selber auch schon was gemacht ( aus dem Blackout wurde ein whitein) 
	Code:
	#include <avr/io.h>
#include <stdlib.h>
#define ms 10
#define SYSCLK 12000000
int
uart_putchar(char c)
{
  if (c == '\n')
    uart_putchar('\r');
  loop_until_bit_is_set(UCSRA, UDRE);
  UDR = c;
  return 0;
}
void
uart_puts(const char *s)
{
  char c;
  while ((c = *s++) != '\0')
    uart_putchar(c);
}
int init_usart(void)
{
	UBRRL=78;        // bei 12MHz
	outp(_BV(TXEN),UCSRB);
}
int usartprintnl(void) /* print new line */
{
	while (! (UCSRA & _BV(UDRE)) )
		;
	UDR = 10; /* LF */
	while (! (UCSRA & _BV(UDRE)) )
		;
	UDR = 13; /* CR */	
	return 2;
}
int usartprintcr(void)
{
   while (! (UCSRA & _BV(UDRE)) )
		;
	UDR = 13; /* CR */	
	return 2;
}
int usartprint(int buf) 
{
	int i;
	//for (i=0;i<8;i++) {
		/* if the UDRE bit is set this means that the UDR buffer is
		 * empty. New data can be transmitted */
		while ( !(UCSRA & _BV(UDRE)) ) 
			;
		UDR = buf;
	//}			
	
	
}		
void wait(unsigned int multiplier50us) { 
	unsigned int i; 
	
	for(i=0;i<multiplier50us;i++) { 
		asm volatile( 
			"ldi r16, 125"   "\n\t" 
			"L_%=:dec r16"   "\n\t" //1 
			"tst r16"      "\n\t" //1 
			"brne L_%="   "\n\t" //2 
			:::"r16"); 
	} 
}
int init_ausgang(void)
{
 
	/*outp(0xFF, DDRC); // Alle Ports von C als Output setzen
	outp(0xFF, PORTC); // Alle LEDs aus
	*/
	
	DDRC=(1<<DDC0);
	PORTC=(1<<DDC0);
}
int ausgabe_on(void)
{
	PORTC=(0<<DDC0);
}
int ausgabe_off(void)
{
	PORTC=(1<<DDC0);
}
int init_eingang(void)
{
	DDRA  = 0x00;
}
int main(void) {
  unsigned int keys;
  unsigned char i;
  unsigned int x;
  unsigned char ledout[10];
  
  
  	init_ausgang();
	init_eingang();
	init_usart();
	i=0;
	x=0;
	
	
	//itoa(x, ledout, 10);
    //uart_puts("Ist doch ein stück weiter\n");
	
	
     for (;;) {                  
        keys = PINA;
		
		if ( !(PINA & (1<<0)) & i==0 ) {		
            ausgabe_on();
			i=1;
			wait(500*ms);
			x++;
			usartprintnl();
			usartprintcr();
			uart_puts(itoa(x, ledout, 10));
		}
		
		if ( !(PINA & (1<<0)) & i==1 ) {		
            ausgabe_off();
			i=0;
			wait(500*ms);
			x++;
			usartprintnl();
			usartprintcr();
			uart_puts(itoa(x, ledout, 10));
		}
		
		
		
		
		
	
	}
	
	
	return 0;
}
 ( Codetag eingefügt, Kjion )
						
					
Lesezeichen