Wenn aber Enable == 3 wäre, sollte doch die dritte if (Enable = READ + WRITE) anspringen oder?
Hier der momentane Code (Die ifs hab ich erstmal drin gelassen)
Code:#include <inttypes.h> #include <avr/io.h> #include <avr/interrupt.h> #include <avr/signal.h> #define Pin1 0 #define Pin2 1 #define Pin3 2 #define Pin4 3 #define Pin5 4 #define Pin6 5 #define Pin7 6 #define Pin8 7 #define READ 1 #define WRITE 2 #define F_CPU 8000000 #define USART_BAUD_RATE 9600 #define USART_BAUD_SELECT (F_CPU/(USART_BAUD_RATE*16l)-1) volatile unsigned char data; volatile int changed; void usart_init(int Enable, int Interupts) { if (Enable & READ) UCSRB = (1<<RXEN); if (Enable & WRITE) UCSRB |= (1<<TXEN); if (Enable & (READ + WRITE) ) UCSRB = ( (1<<RXEN) | (1<<TXEN) ); if (Interupts & READ) UCSRB |= (1<<RXCIE); if (Interupts & WRITE) UCSRB |= (1<<TXCIE); if (Interupts & (READ + WRITE) ) UCSRB |= ( (1<<RXCIE) | (1<<TXCIE) ); UBRRL = (unsigned char) USART_BAUD_SELECT; } void usart_writeChar(unsigned char c) { while (!(UCSRA & (1<<UDRE))) {} UDR = c; while(!(UCSRA & (1<<TXC))) {} } unsigned char usart_readChar(void) { while(!(UCSRA & (1<<RXC))) {} return UDR; } void usart_writeString(unsigned char *string) { while (!(UCSRA & (1<<UDRE))) {} while ( *string) usart_writeChar(*string++); } SIGNAL (SIG_UART_RECV) { data = UDR; changed = 1; usart_writeChar('['); usart_writeChar(data); usart_writeChar(']'); } int main (void) { usart_init( (READ + WRITE) , READ); DDRD = 0xFF; PORTD = 0x00; changed = 0; usart_writeString("Hello World"); sei(); while (1) { if (changed == 1) { if (data == 'l') { PORTD = (1 << Pin6); usart_writeString("[Motor left]"); } else if (data == 'r') { PORTD = (1 << Pin7); usart_writeString("[Motor right]"); } else if (data == 's') { PORTD = 0x00; usart_writeString("[Motor stop]"); } else usart_writeChar(data); changed = 0; } } }







Zitieren

Lesezeichen