PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : C Code Problem



Nadors
21.02.2006, 22:24
moin,
hab grade mit avr angefangen. benutze winavr.
nun habe ich folgendes problem, wenn ich mein programm so schreibe

#include <io.h>

int main(void) {
DDRB = 0xff;
PORTB = 0x07;
}

und auf "make all" drücke compiliert er und es läuft alles wunderbar

wenn ich es aber so schreibe

#include <io.h>

int main(void) {
outp (0xff,DDRB);
outp (0x07,PORTB);
}

dann bekomme ich folgende meldung

> "make.exe" all

-------- begin --------
avr-gcc (GCC) 3.4.5
Copyright (C) 2004 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


Compiling: bubu.c
avr-gcc -c -mmcu=atmega8 -I. -gstabs -DF_CPU=8000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=bubu.lst -std=gnu99 -MD -MP -MF .dep/bubu.o.d bubu.c -o bubu.o
bubu.c:1:16: io.h: No such file or directory
bubu.c: In function `main':
bubu.c:4: warning: implicit declaration of function `outp'
bubu.c:4: error: `DDRB' undeclared (first use in this function)
bubu.c:4: error: (Each undeclared identifier is reported only once
bubu.c:4: error: for each function it appears in.)
bubu.c:5: error: `PORTB' undeclared (first use in this function)
bubu.c:6:2: warning: no newline at end of file
make.exe: *** [bubu.o] Error 1

> Process Exit Code: 2
> Time Taken: 00:01

kann mir jemand sagen woran das liegt ?

danke,

Nadors

ruediw
21.02.2006, 22:43
moin,
hab grade mit avr angefangen. benutze winavr.
nun habe ich folgendes problem, wenn ich mein programm so schreibe

#include <io.h>

int main(void) {
DDRB = 0xff;
PORTB = 0x07;
}

und auf "make all" drücke compiliert er und es läuft alles wunderbar

wenn ich es aber so schreibe

#include <io.h>

int main(void) {
outp (0xff,DDRB);
outp (0x07,PORTB);
}

dann bekomme ich folgende meldung

> "make.exe" all

-------- begin --------
avr-gcc (GCC) 3.4.5
Copyright (C) 2004 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


Compiling: bubu.c
avr-gcc -c -mmcu=atmega8 -I. -gstabs -DF_CPU=8000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=bubu.lst -std=gnu99 -MD -MP -MF .dep/bubu.o.d bubu.c -o bubu.o
bubu.c:1:16: io.h: No such file or directory
bubu.c: In function `main':
bubu.c:4: warning: implicit declaration of function `outp'
bubu.c:4: error: `DDRB' undeclared (first use in this function)
bubu.c:4: error: (Each undeclared identifier is reported only once
bubu.c:4: error: for each function it appears in.)
bubu.c:5: error: `PORTB' undeclared (first use in this function)
bubu.c:6:2: warning: no newline at end of file
make.exe: *** [bubu.o] Error 1

> Process Exit Code: 2
> Time Taken: 00:01

kann mir jemand sagen woran das liegt ?

danke,

Nadors

Beim 1. Teil da machst Du eine Zuweisung von je einer Variablen mit einem Wert. Diese Variablen musst Du irgendwo deklariert haben, sonst hättest Du auch schon Fehlermeldungen gehabt.

Beim 2. Teil benutzt Du ione Funktion outp mit 2 Parametern. Wahrscheinlich hast Du falsche Parameter übergeben oder die Funktion ist nicht bekannt (Includefile nicht angegeben).

super_castle
22.02.2006, 07:27
outp (0xff,DDRB);
outp (0x07,PORTB);

gibt es seit 02.05 nicht mehr in winavr-c

SprinterSB
22.02.2006, 10:38
Ausserdem sollte es
#include <avr/io.h>
heissen

Nadors
22.02.2006, 16:09
danke, hatte das von einer internet seite die wohl schon etwas älter ist.

werde jetzt mal ein wenig weiter rumprobieren.

mfg, nadors

Nadors
28.02.2006, 13:40
moin,
neues problem. ich probiere jetzt schon lange hin und her, aber bekomme es einfach nicht hin. ich möchte das wenn ich eine Taste am Port D drücke eine LED an Port B leuchtet. könnte mir vielleicht jemand den nötigen code posten ?

schon mal danke

mfg, nadors

SprinterSB
28.02.2006, 14:01
#include <avr/io.h>

int main()
{
DDRB |= (1 << PB3); // PortB.3 als Ausgang

while (1) // Endlosschleife
{
if (PIND & (1 << PD6)) // ist PinD.6 HIGH?
PORTB |= (1 << PB3); // Ja, dann PortB.3 = HIGH
else
PORTB &= ~(1 << PB3); // ansonsten PortB.3 = LOW
}
return 0;
}

Nadors
28.02.2006, 14:23
danke SprinterSB

werde darauf aufbauend mal weiter versuchen.

mfg, nadors