Announcement: there is an
English version of this forum on
EmbDev.net . Posts you create there will be displayed on Mikrocontroller.net
and EmbDev.net.
Hallo,
ich habe eine Funktion mit der ich über "SendDisplayData(Buffer)" den
Buffer eines sprintf an mein Display sende. Wenn ich nun einen Text an
das Display senden möchte muss ich immer folgendes machen:
SendDisplayData("#ZL,100,100,Hier der Text\r");
wenn ich z.b. den Wert eines ADCs ausgeben möchte dann muss ich sprintf
vorher nutzen, das sieht dann so aus:
1 char Buffer [ 50 ];
2 sprintf ( Buffer , "#ZL,100,100,ADC-Wert: %d \r " , adc_variable );
3 SendDisplayData ( Buffer );
Ich hätte das ganze aber gerne so:
1 write_display ( 100 , 100 , "Hier der Text" );
oder 1 write_display ( 100 , 100 , adc_variable );
und die function soll dann so aussehen:
1 void write_display ( int x_variable , int y_variable , char ausgabewert )
2 {
3 sprintf ( Buffer , "#ZL {hier die x_variable}, {hier die y_variable}, {hier den ausgabetext} \r " , x_variable , y_variable , ausgabewert );
4 SendDisplayData ( Buffer );
5 }
Leider habe ich mit sprintf nur sehr wenige erfahrungen. Der compiler
mekkert immer und sagt was von %c oder %s und wie ich mehr als nur einen
Wert mit sprintf in den Buffer "übergebe" weiss ich leider auch nicht.
Wenn der Compiler dann mal nicht mekkert dann geht es entweder nicht,
also ich bekomme auf die Display keine Ausgabe oder die Ausgabe erfolgt
schon ab der, in diesem falle, 100, was nicht sein dürfte.
Ich danke euch schonmal.
17.01.2016 21:50 :
Bearbeitet durch User
von
Peter II (Gast)
17.01.2016 22:00
1 void write_display ( int x_variable , int y_variable , char * ausgabewert ) {
2 sprintf ( Buffer , "#ZL %d, %d, %s \r " , x_variable , y_variable , ausgabewert );
3 SendDisplayData ( Buffer );
4 };
sollte gehen.
Hallo, danke. Klappt sogar war nur ein semikolon zu viel. Aber was mich
wundern, warum mekkert Win-Avr trotzdem?
1 display.c: In function 'write_display':
2 display.c:158: warning: implicit declaration of function 'sprintf'
3 display.c:158: warning: incompatible implicit declaration of built-in function 'sprintf'
17.01.2016 22:08 :
Bearbeitet durch User
von
Peter II (Gast)
17.01.2016 22:10
Christian B. schrieb:
> warum mekkert Win-Avr trotzdem?
vermutlich hast du das #include <stdio.h> vergessen.
Jau. Danke. Das brauchte ich für das Display ja nicht. Jetzt kam ja eine
funktion dazu die die stdio.h benötigt g
Manchmal sind es die kleinen Dinge :)
Super.
Danke Danke
Wenn wir schon dabei sind. Warum mekkert der Compiler z.b. "function is
an prototype? Habe mir für den ds1307 ein paar funktionen erstellt. die
gehen zwar aber er mekkert immer prototyp bla
17.01.2016 22:14 :
Bearbeitet durch User
Hier mal die Dateien:
ds1307.h
1 #include <avr/io.h>
2 #include <stdio.h>
3
4 void ds1307_second_write ( unsigned char second );
5 void ds1307_minute_write ( unsigned char minute );
6 void ds1307_hour_write ( unsigned char hour , unsigned char hour_format , unsigned char am_pm );
7 void ds1307_day_write ( unsigned char day );
8 void ds1307_date_write ( unsigned char date );
9 void ds1307_month_write ( unsigned char month );
10 void ds1307_year_write ( unsigned char year );
11
12 unsigned char ds1307_read_second ();
13 unsigned char ds1307_read_minute ();
14 unsigned char ds1307_read_hour ();
15 unsigned char ds1307_read_day ();
16 unsigned char ds1307_read_date ();
17 unsigned char ds1307_read_month ();
18 unsigned char ds1307_read_year ();
19 unsigned char convert_decimal_to_bcd ( unsigned char decimal_number );
20 unsigned char convert_bcd_to_decimal ( unsigned char bcd_number );
21
22 void read_uhr ();
und die ds1307.c
1 #include "i2c.h"
2 #include "ds1307.h"
3 #include "bcdata.h"
4 #include "display.h"
5
6 unsigned char convert_decimal_to_bcd ( unsigned char decimal_number )
7 {
8 decimal_number = (( decimal_number / 10 ) * 16 ) + ( decimal_number % 10 );
9 return decimal_number ;
10 }
11
12 unsigned char convert_bcd_to_decimal ( unsigned char bcd_number )
13 {
14 bcd_number = (( bcd_number >> 4 ) * 10 ) + ( bcd_number & 0x0f );
15 return bcd_number ;
16 }
17
18 // Schreibe funktionen
19 void ds1307_second_write ( unsigned char second )
20 {
21 i2c_start ( 0xd0 );
22 i2c_write ( 0x00 );
23 second = convert_decimal_to_bcd ( second );
24 i2c_write ( second );
25 i2c_stop ();
26 }
27
28 void ds1307_minute_write ( unsigned char minute )
29 {
30 i2c_start ( 0xd0 );
31 i2c_write ( 0x01 );
32 minute = convert_decimal_to_bcd ( minute );
33 i2c_write ( minute );
34 i2c_stop ();
35 }
36
37 void ds1307_hour_write ( unsigned char hour , unsigned char hour_format , unsigned char am_pm )
38 {
39 i2c_start ( 0xd0 );
40 i2c_write ( 0x02 );
41 if ( hour_format == 1 )
42 {
43 hour = convert_decimal_to_bcd ( hour );
44 hour = hour | ( 1 << 6 ) | ( am_pm << 5 );
45 i2c_write ( hour );
46 }
47 else
48 {
49 hour = convert_decimal_to_bcd ( hour );
50 i2c_write ( hour );
51 }
52 i2c_stop ();
53 }
54
55 void ds1307_day_write ( unsigned char day )
56 {
57 i2c_start ( 0xd0 );
58 i2c_write ( 0x03 );
59 day = convert_decimal_to_bcd ( day );
60 i2c_write ( day );
61 i2c_stop ();
62 }
63
64 void ds1307_date_write ( unsigned char date )
65 {
66 i2c_start ( 0xd0 );
67 i2c_write ( 0x04 );
68 date = convert_decimal_to_bcd ( date );
69 i2c_write ( date );
70 i2c_stop ();
71 }
72
73 void ds1307_month_write ( unsigned char month )
74 {
75 i2c_start ( 0xd0 );
76 i2c_write ( 0x05 );
77 month = convert_decimal_to_bcd ( month );
78 i2c_write ( month );
79 i2c_stop ();
80 }
81
82 void ds1307_year_write ( unsigned char year )
83 {
84 i2c_start ( 0xd0 );
85 i2c_write ( 0x06 );
86 year = convert_decimal_to_bcd ( year );
87 i2c_write ( year );
88 i2c_stop ();
89 }
90
91
92 // Lese funktionen
93 unsigned char ds1307_read_second ()
94 {
95 unsigned char sec ;
96 i2c_start ( 0xd0 );
97 i2c_write ( 0x00 );
98 i2c_start ( 0xd1 );
99 sec = i2c_readNak ();
100 i2c_stop ();
101 return sec ;
102 }
103
104 unsigned char ds1307_read_minute ()
105 {
106 unsigned char min ;
107 i2c_start ( 0xd0 );
108 i2c_write ( 0x01 );
109 i2c_start ( 0xd1 );
110 min = i2c_readNak ();
111 i2c_stop ();
112 return min ;
113 }
114
115 unsigned char ds1307_read_hour ()
116 {
117 unsigned char hour ;
118 i2c_start ( 0xd0 );
119 i2c_write ( 0x02 );
120 i2c_start ( 0xd1 );
121 hour = i2c_readNak ();
122 i2c_stop ();
123 return hour ;
124 }
125
126 unsigned char ds1307_read_day ()
127 {
128 unsigned char day ;
129 i2c_start ( 0xd0 );
130 i2c_write ( 0x03 );
131 i2c_start ( 0xd1 );
132 day = i2c_readNak ();
133 i2c_stop ();
134 return day ;
135 }
136
137 unsigned char ds1307_read_date ()
138 {
139 unsigned char date ;
140 i2c_start ( 0xd0 );
141 i2c_write ( 0x04 );
142 i2c_start ( 0xd1 );
143 date = i2c_readNak ();
144 i2c_stop ();
145 return date ;
146 }
147
148 unsigned char ds1307_read_month ()
149 {
150 unsigned char month ;
151 i2c_start ( 0xd0 );
152 i2c_write ( 0x05 );
153 i2c_start ( 0xd1 );
154 month = i2c_readNak ();
155 i2c_stop ();
156 return month ;
157 }
158
159 unsigned char ds1307_read_year ()
160 {
161 unsigned char year ;
162 i2c_start ( 0xd0 );
163 i2c_write ( 0x06 );
164 i2c_start ( 0xd1 );
165 year = i2c_readNak ();
166 i2c_stop ();
167 return year ;
168 }
169
170 void read_uhr ()
171 {
172 bcdata [ UHR_SEKUNDE ] = convert_bcd_to_decimal ( ds1307_read_second ());
173 bcdata [ UHR_MINUTE ] = convert_bcd_to_decimal ( ds1307_read_minute ());
174 bcdata [ UHR_STUNDE ] = convert_bcd_to_decimal ( ds1307_read_hour ());
175 sprintf ( Buffer , "#ZB730,20,800,20,4,%d:%d \r " , bcdata [ UHR_STUNDE ], bcdata [ UHR_MINUTE ]);
176 SendDisplayData ( Buffer );
177 }
und dann der Compiler
1 In file included from main.c:16:
2 ds1307.h:12: warning: function declaration isn't a prototype
3 ds1307.h:13: warning: function declaration isn't a prototype
4 ds1307.h:14: warning: function declaration isn't a prototype
5 ds1307.h:15: warning: function declaration isn't a prototype
6 ds1307.h:16: warning: function declaration isn't a prototype
7 ds1307.h:17: warning: function declaration isn't a prototype
8 ds1307.h:18: warning: function declaration isn't a prototype
9 ds1307.h:22: warning: function declaration isn't a prototype
10
11 Compiling C: ds1307.c
12 avr-gcc -c -mmcu=atmega128 -I. -gdwarf-2 -DF_CPU=16000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=./ds1307.lst -std=gnu99 -MMD -MP -MF .dep/ds1307.o.d ds1307.c -o ds1307.o
13 In file included from ds1307.c:2:
14 ds1307.h:12: warning: function declaration isn't a prototype
15 ds1307.h:13: warning: function declaration isn't a prototype
16 ds1307.h:14: warning: function declaration isn't a prototype
17 ds1307.h:15: warning: function declaration isn't a prototype
18 ds1307.h:16: warning: function declaration isn't a prototype
19 ds1307.h:17: warning: function declaration isn't a prototype
20 ds1307.h:18: warning: function declaration isn't a prototype
21 ds1307.h:22: warning: function declaration isn't a prototype
22 ds1307.c:94: warning: function declaration isn't a prototype
23 ds1307.c:105: warning: function declaration isn't a prototype
24 ds1307.c:116: warning: function declaration isn't a prototype
25 ds1307.c:127: warning: function declaration isn't a prototype
26 ds1307.c:138: warning: function declaration isn't a prototype
27 ds1307.c:149: warning: function declaration isn't a prototype
28 ds1307.c:160: warning: function declaration isn't a prototype
29 ds1307.c:171: warning: function declaration isn't a prototype
Das macht er, da du vernünftigerweise -Wstrict-prototypes angegeben
hast.
Mit dieser Zeile 1 unsigned char ds1307_read_second ();
sagst du dem Compiler, dass es eine Funktion ds1307_read_second gibt,
die einen unsigned char zurückgibt und irgendeine unbekannte Liste von
Parametern nimmt. Soll die Funktion keine Parameter haben, musst du das
explizit sagen, indem du schreibst:
1 unsigned char ds1307_read_second ( void );
Hallo,
ja, das habe ich versucht. Wenn ich das jedoch mache, dann mekkert der
compiler zwar nicht, aber eine ausgabe bekomme ich dann auch nicht mehr.
Lasse ich das als "prototyp" laufen dann bekomme ich eine ausgabe.
Das ist das was mich verwundert
Und da haben wir wieder gleich ein Problem mit dem write_display() von
vorhin
1 main.c: In function 'main':
2 main.c:76: warning: passing argument 3 of 'write_display' makes pointer from integer without a cast
und dort steht
1 // Display I2C Buffer
2 DisplayBufferStatus = ReadDisplayBufferStatus ();
3 if ( DisplayBufferStatus == 1 )
4 {
5 readdata = ReadDisplayData ();
6 }
7 // Display I2C Buffer ende
8
9 write_display ( 100 , 150 , readdata );
von
Peter II (Gast)
17.01.2016 22:48
Christian B. schrieb:
> Und da haben wir wieder gleich ein Problem mit dem write_display() von
> vorhin
du zeigst und viel zu wenig.
readdata was ist das für eine Variable?
1 int DisplayBufferStatus ;
2 char readdata ;
3
4 int main ( void )
5 {
6
7 while ( 1 )
8 {
9
10 // Display I2C Buffer
11 DisplayBufferStatus = ReadDisplayBufferStatus ();
12 if ( DisplayBufferStatus == 1 )
13 {
14 readdata = ReadDisplayData ();
15 }
16 // Display I2C Buffer ende
17
18 write_display ( 100 , 150 , readdata );
19
20 read_fotowiderstand ();
21 display_helligkeit ();
22 write_display ( 100 , 100 , "das ist ein test" );
23
24
25
26 // Display Buffer löschen
27 readdata = 0 ;
28 // Display Buffer löschen ende
29 }
30
31 }
Das write_display mit dem "das ist ein test" funktioniert.
17.01.2016 22:54 :
Bearbeitet durch User
von
Peter II (Gast)
17.01.2016 22:55
char readdata;
da wird wohl kein String reinpassen
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.