Hi, ich habe den Code von Ulrich Radig auf einem AVR Net IO am laufen, da gibt es in der USART.c einen code den ich nicht verstehe. Meine Frage ist jetzt ob den mir einer Erklären kann? Das Einzige was ich deuten kann das dort irgendetwas mit Pointer passiert. Aber wie ?!?! Keine Ahnung. Was genau sind Pointer? Wäre über jeden Tip dankbar.
1 | /------------------------------------------------------------------------------
|
2 | void usart_write_P (const char *Buffer,...) |
3 | {
|
4 | va_list ap; |
5 | va_start (ap, Buffer); |
6 | |
7 | int format_flag; |
8 | char str_buffer[10]; |
9 | char str_null_buffer[10]; |
10 | char move = 0; |
11 | char Base = 0; |
12 | int tmp = 0; |
13 | char by; |
14 | char *ptr; |
15 | |
16 | //Ausgabe der Zeichen
|
17 | for(;;) |
18 | {
|
19 | by = pgm_read_byte(Buffer++); |
20 | if(by==0) break; // end of format string |
21 | |
22 | if (by == '%') |
23 | {
|
24 | by = pgm_read_byte(Buffer++); |
25 | if (isdigit(by)>0) |
26 | {
|
27 | |
28 | str_null_buffer[0] = by; |
29 | str_null_buffer[1] = '\0'; |
30 | move = atoi(str_null_buffer); |
31 | by = pgm_read_byte(Buffer++); |
32 | }
|
33 | |
34 | switch (by) |
35 | {
|
36 | case 's': |
37 | ptr = va_arg(ap,char *); |
38 | while(*ptr) { usart_write_char(*ptr++); } |
39 | break; |
40 | case 'b': |
41 | Base = 2; |
42 | goto ConversionLoop; |
43 | case 'c': |
44 | //Int to char
|
45 | format_flag = va_arg(ap,int); |
46 | usart_write_char (format_flag++); |
47 | break; |
48 | case 'i': |
49 | Base = 10; |
50 | goto ConversionLoop; |
51 | case 'o': |
52 | Base = 8; |
53 | goto ConversionLoop; |
54 | case 'x': |
55 | Base = 16; |
56 | //****************************
|
57 | ConversionLoop:
|
58 | //****************************
|
59 | itoa(va_arg(ap,int),str_buffer,Base); |
60 | int b=0; |
61 | while (str_buffer[b++] != 0){}; |
62 | b--; |
63 | if (b<move) |
64 | {
|
65 | move -=b; |
66 | for (tmp = 0;tmp<move;tmp++) |
67 | {
|
68 | str_null_buffer[tmp] = '0'; |
69 | }
|
70 | //tmp ++;
|
71 | str_null_buffer[tmp] = '\0'; |
72 | strcat(str_null_buffer,str_buffer); |
73 | strcpy(str_buffer,str_null_buffer); |
74 | }
|
75 | usart_write_str (str_buffer); |
76 | move =0; |
77 | break; |
78 | }
|
79 | |
80 | }
|
81 | else
|
82 | {
|
83 | usart_write_char ( by ); |
84 | }
|
85 | }
|
86 | va_end(ap); |
87 | }
|