Also gut,
in C bin ich ein Noob und versuche mich hinein zufinden. Denke es klappt so gaanz langsam. Mit Zeiger habe ich mich noch nicht beschäftigt, will hier ja"nur" den Inhalt lesen.
Der Compiler gibt mir nach erfolgreichen compilieren diese 3 Warnungen:
Kompletter Code:Code:c:17: warning: function declaration isn't a prototype c: In function `main': c:41: warning: passing arg 1 of `string_senden' makes pointer from integer without a cast c: At top level: c:49: warning: function declaration isn't a prototype
(Benutze AVR Studio)Code:#include <avr/io.h> #include <string.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; char puffer[8]; void string_senden (char *string); void usart_initial(); int main(void) { DDRD |= (1<<2) | (1<<3) | (1<<4) | (1<<6) | (1<<7); DDRA &= ~( (1<<PA0)); usart_initial(); while(1) { PORTD |= (1<<2) | (1<<3) | (1<<4) | (1<<6) | (1<<7); bPortd = PIND; utoa(bPortd,puffer,2); string_senden(puffer); string_senden ("\n\r"); if (PINA & (1<<PINA0)){ string_senden ("Taster nicht gedrueckt\r\n"); } if ( !(PINA & (1<<PINA0))){ string_senden ("Taster gedrueckt\r\n"); } for (i=0; i<100; i++) { _delay_ms(10); } string_senden (puffer[5]); string_senden ("\n\r"); } } //----------------------------------------------------- void usart_initial() { UBRRH = 0; UBRRL = 7; UCSRB = (1<<RXCIE)|(1<<RXEN)|(1<<TXEN); UCSRC = (1<<URSEL)|(1<<UCSZ1)|(1<<UCSZ0); } //----------------------------------------------------- void string_senden (char *string) { while (*string) { while (!(UCSRA & (1<<UDRE))) {} UDR = *string++; } } //-----------------------------------------------------
Ziel:
Bei einem PC-Beispiel
Also will ich einen einzelnen Portzustand aus diesem String erhalten.Code:#include <stdio.h> #include <stdlib.h> char vari[] = { "Hallo" }; int main(void) { int i; printf("%c", vari[0]); /* H */ printf("%c'", vari[3]); /* l */ return EXIT_SUCCESS; }
ZB. mit puffer[5]: PinD5
Falls ich total auf dem Holzweg bin, kann Kritik einstecken. Bin halt noch sehr am Anfang der Programmierung (Mechanik ist mein Lieblingsgebiet).







Zitieren

Lesezeichen