Hallo,
schlage mich mal wieder mit C herum.
Nun habe ich das Problem, dass die Variable bPortD nicht korrekt gesendet wird.
Kann es daran liegen, dass dies eine int ist und das eine char gesendet wird?
Code:#include <avr/io.h> #include <stdint.h> #include <util/delay.h> #include <inttypes.h> #include <string.h> #include <stdlib.h> #include <stdio.h> int i; uint8_t bPortD; void string_senden (const char *string); void usart_initial(); int main(void) { DDRD |= (1<<4) | (1<<5); usart_initial(); while(1) { bPortD = PIND; string_senden (bPortD); string_senden ("\n\r"); if (PIND & (1<<PIND7)){ string_senden ("Taster nicht gedrueckt\r\n"); } if ( !(PIND & (1<<PIND7))){ string_senden ("Taster gedrueckt\r\n"); } for (i=0; i<100; i++) { _delay_ms(10); } } } //----------------------------------------------------- void usart_initial() { UBRRH = 0; UBRRL = 7; UCSRB = (1<<RXCIE)|(1<<RXEN)|(1<<TXEN); UCSRC = (1<<URSEL)|(1<<UCSZ1)|(1<<UCSZ0); } //----------------------------------------------------- void string_senden (const char *string) { while (*string) { while (!(UCSRA & (1<<UDRE))) {} UDR = *string++; } } //-----------------------------------------------------







Zitieren

Lesezeichen