PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : AVR-GCC Probleme mit Compiler und PonyProg



Jul-ian
19.03.2006, 11:07
Hallo zusammen,

Nachdem ich nun erfolgreich Bascom zum laufen gebracht und dort ein wenig rum experimentiert habe, möchte ich nun auf die C-Programmierung übergehen.
Bin dort zwar auch kein großer Experte, aber auch im Studium muss ich teilweise mit C programmieren... von daher passt das ganz gut.

Ich habe mir WinAVR installiert und alles wie in folgendem Tutorial eingerichtet: http://www.dirkbaumann.de/html/software.html

Das Beispiel-Programm habe ich auch runtergeladen, aber ich bekomme es einfach nicht kompiliert.


8bitzähler.c: (.text+0x34): undefined reference to 'outp'
8bitzähler.c: (.text+0x42): undefined reference to 'outp'
8bitzähler.c: (.text+0x50): undefined reference to 'outp'
8bitzähler.c: (.text+0x5e): undefined reference to 'outp'
8bitzähler.c: (.text+0x72): undefined reference to 'outp'
>Process Exit Code: 1


Kann es eventuell sein, dass die io.h nicht eingebunden wird?
Als Controller habe ich meinen AT90S2313 und meinen ATMega8 eingerichtet. Mit keinem funktioniert's.

Ausserdem habe ich noch eine Frage zu dem PonyProg:
Welche Einstellungen muss ich dort vornehmen? Meinen Controller erkennt er nämlich nicht.
Als Schnittstelle habe ich mir folgendes nachgebaut:
https://www.roboternetz.de/wissen/index.php/AVR-ISP_Programmierkabel

Schonmal vielen Dank für Euer Bemühen :)

Gruß
Julian

EDIT:
Frage zu PonyProg hat sich erledigt 8-[

Kjion
19.03.2006, 11:49
outp() gibt es wie sbi()/cbi() nicht mehr. Benutz einfach

PORTB = 0x00;
x = PINB;
usw.

MfG Kjion

Jul-ian
19.03.2006, 11:51
Ahso, ok. Das erklärt dann einiges :)

Mit Ein- und Ausgabe am Controller habe ich mich gerade beschäftigt. Das dürfte kein Problem sein :)

Jul-ian
19.03.2006, 13:16
ähm, ja. Nachdem die erste Hürde genommen ist, kann ich die Ports nach belieben ansteuern.
Jetzt habe ich versucht auf mein LCD zu schreiben, aber das funktioniert bisher noch nicht.

angeschlossen ist es wie hier:
https://www.roboternetz.de/wissen/index.php/Bascom_und_LCD%27s

techn. Infos:
ATMega8 16PU @ 4Mhz
2*16 LCD HD44780

Ich habe hier im Forum ein bisschen rumgesucht und bin auf folgende Seite gestoßen: http://homepage.hispeed.ch/peterfleury/avr-lcd44780.html

Die Library habe ich mir bereits runtergeladen und auch schon angepasst.
Mein Programm:


#include <stdlib.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <lcd.h>
#include <lcd.c>

void main (void) {
lcd_clrscr();
lcd_puts("Hallo\n");
}


Kompilieren usw. und auch das Übertragen ist kein Problem.
Er zeigt halt nix an :/

Gibt es vielleicht ein Tutorial oder soetwas zu diesem Thema?

Wie würde es prinzipiell funktionieren, wenn ich einen Zustand auf meinem PC an dem Display anzeigen möchte? Also z.B. CPU-Auslastung, Song in Winamp o.ä.

Murphywareinoptimist
19.03.2006, 19:03
Hi!



outp() gibt es wie sbi()/cbi() nicht mehr. Benutz einfach
PORTB = 0x00;
x = PINB;
usw.



Ich fange gerade erst an mit der C-Programmierung und den µControllern aber ich glaube da muss ich widersprechen



#include <avr/io.h>

typedef int BYTE;

BYTE RECHTS;
BYTE LINKS;

int main (void)

{
outp (0xff,DDRC);
outp (0x00,DDRD);
outp (0x07,PORTD);

RECHTS = 0;
LINKS = 0;


for (;;) {

if (bit_is_clear (PIND, PIND0) & LINKS == 0){
RECHTS = 1;}
if (bit_is_clear (PIND, PIND1) & RECHTS == 0) {
LINKS = 1;}
if bit_is_clear (PIND, PIND2) {
LINKS = 0;
RECHTS = 0;}


if (RECHTS == 1 ) {
sbi (PORTC, 1);}
if (RECHTS == 0 ) {
cbi (PORTC, 1);}
if (LINKS == 1 ) {
sbi (PORTC, 0);}
if (LINKS == 0 ) {
cbi (PORTC, 0);}

}


Das ist ein kleines Programm mit dem ich noch vor zwei Tagen gespielt habe... funktioniert wunderbar. Mit PonyProg und einem Mega8.

Macht auch wenig Sinn wenn man eine Bitausgabe hat immer den ganzen Port beschreiben zu müssen.

Gruß Olli

Superhirn
20.03.2006, 09:14
Hi,
das geht sicher nur, da du eine alte AVR-GCC version installiert hast. das neue GCC kann das normalerweiße nicht mehr.

Murphywareinoptimist
20.03.2006, 11:27
Und wie ist da die Bitmanipulation geregelt? Ganz ohne kann doch nicht sein oder?

Gruß Olli

SprinterSB
20.03.2006, 11:33
Man schreibt Bitmanipulationen in Standard-C

Bit setzen : PORTB |= (1<<2); // setzt PortB.2
Bit Löschen: PORTB &= ~(1<<4); // löscht PortB.4

Wenn einem das zu viel getippsel ist, kann man sich ja Makros nach eigenem Gusto bauen.

Jul-ian
20.03.2006, 12:53
Das ist zwar alles sehr informativ, aber was ist mit meinen Fragen? =)

SprinterSB
20.03.2006, 13:12
Kann es eventuell sein, dass die io.h nicht eingebunden wird?
Nö, zumindest nich nach der Fehlermeldung. Wenn er die avr/io.h nicht fände, gäbe es eine entsprechende Fehlermeldung. Oder welche Frage ist noch offen?

Jul-ian
20.03.2006, 13:30
Das hat sich schon geklärt :)
Aktuell würde ich gerne mein LCD ansteuern, aber dafür habe ich noch keine Dokumentation o.ä. gefunden.

Mein Beitrag s.o. oder hier: https://www.roboternetz.de/phpBB2/viewtopic.php?p=168374#168102

Murphywareinoptimist
20.03.2006, 13:43
Hi!

Ja ich bin wohl ein wenig verdorben. Bin zyklische Programmbearbeitung und eine sehr gute Bitverarbeitung gewöhnt.

Aber mal im Ernst ... warum nimmt man solche Befehle aus dem Vorrat?
Wenn ihr mir jetzt noch erzählt "bit is clear" und "bit is set" ist in den neueren Versionen auch nicht mehr verfügbar dann hat sich das mit der C programmierung uber AVR-GCC für mich erledigt noch bevor ich richtig angefangen habe.

Gruß Olli

SprinterSB
20.03.2006, 13:46
Hey, net weinen. Da ist das Zeug:
/* Copyright (c) 2002, Marek Michalkiewicz <marekm@amelek.gda.pl>
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. */

/* avr/sfr_defs.h - macros for accessing AVR special function registers */

/* $Id: sfr_defs.h,v 1.10.2.2 2004/04/22 17:41:05 troth Exp $ */

#ifndef _AVR_SFR_DEFS_H_
#define _AVR_SFR_DEFS_H_ 1

/** \defgroup avr_sfr_notes Additional notes from <avr/sfr_defs.h>
\ingroup avr_sfr

The \c <avr/sfr_defs.h> file is included by all of the \c <avr/ioXXXX.h>
files, which use macros defined here to make the special function register
definitions look like C variables or simple constants, depending on the
<tt>_SFR_ASM_COMPAT</tt> define. Some examples from \c <avr/iom128.h> to
show how to define such macros:

\code
#define PORTA _SFR_IO8(0x1b)
#define TCNT1 _SFR_IO16(0x2c)
#define PORTF _SFR_MEM8(0x61)
#define TCNT3 _SFR_MEM16(0x88)
\endcode

If \c _SFR_ASM_COMPAT is not defined, C programs can use names like
<tt>PORTA</tt> directly in C expressions (also on the left side of
assignment operators) and GCC will do the right thing (use short I/O
instructions if possible). The \c __SFR_OFFSET definition is not used in
any way in this case.

Define \c _SFR_ASM_COMPAT as 1 to make these names work as simple constants
(addresses of the I/O registers). This is necessary when included in
preprocessed assembler (*.S) source files, so it is done automatically if
\c __ASSEMBLER__ is defined. By default, all addresses are defined as if
they were memory addresses (used in \c lds/sts instructions). To use these
addresses in \c in/out instructions, you must subtract 0x20 from them.

For more backwards compatibility, insert the following at the start of your
old assembler source file:

\code
#define __SFR_OFFSET 0
\endcode

This automatically subtracts 0x20 from I/O space addresses, but it's a
hack, so it is recommended to change your source: wrap such addresses in
macros defined here, as shown below. After this is done, the
<tt>__SFR_OFFSET</tt> definition is no longer necessary and can be removed.

Real example - this code could be used in a boot loader that is portable
between devices with \c SPMCR at different addresses.

\verbatim
<avr/iom163.h>: #define SPMCR _SFR_IO8(0x37)
<avr/iom128.h>: #define SPMCR _SFR_MEM8(0x68)
\endverbatim

\code
#if _SFR_IO_REG_P(SPMCR)
out _SFR_IO_ADDR(SPMCR), r24
#else
sts _SFR_MEM_ADDR(SPMCR), r24
#endif
\endcode

You can use the \c in/out/cbi/sbi/sbic/sbis instructions, without the
<tt>_SFR_IO_REG_P</tt> test, if you know that the register is in the I/O
space (as with \c SREG, for example). If it isn't, the assembler will
complain (I/O address out of range 0...0x3f), so this should be fairly
safe.

If you do not define \c __SFR_OFFSET (so it will be 0x20 by default), all
special register addresses are defined as memory addresses (so \c SREG is
0x5f), and (if code size and speed are not important, and you don't like
the ugly #if above) you can always use lds/sts to access them. But, this
will not work if <tt>__SFR_OFFSET</tt> != 0x20, so use a different macro
(defined only if <tt>__SFR_OFFSET</tt> == 0x20) for safety:

\code
sts _SFR_ADDR(SPMCR), r24
\endcode

In C programs, all 3 combinations of \c _SFR_ASM_COMPAT and
<tt>__SFR_OFFSET</tt> are supported - the \c _SFR_ADDR(SPMCR) macro can be
used to get the address of the \c SPMCR register (0x57 or 0x68 depending on
device).

The old inp()/outp() macros are still supported, but not recommended to use
in new code. The order of outp() arguments is confusing. */

#ifdef __ASSEMBLER__
#define _SFR_ASM_COMPAT 1
#endif

#ifndef __ASSEMBLER__
/* These only work in C programs. */
#include <inttypes.h>

#define _MMIO_BYTE(mem_addr) (*(volatile uint8_t *)(mem_addr))
#define _MMIO_WORD(mem_addr) (*(volatile uint16_t *)(mem_addr))
#endif

#if _SFR_ASM_COMPAT

#ifndef __SFR_OFFSET
/* Define as 0 before including this file for compatibility with old asm
sources that don't subtract __SFR_OFFSET from symbolic I/O addresses. */
#define __SFR_OFFSET 0x20
#endif

#if (__SFR_OFFSET != 0) && (__SFR_OFFSET != 0x20)
#error "__SFR_OFFSET must be 0 or 0x20"
#endif

#define _SFR_MEM8(mem_addr) (mem_addr)
#define _SFR_MEM16(mem_addr) (mem_addr)
#define _SFR_IO8(io_addr) ((io_addr) + __SFR_OFFSET)
#define _SFR_IO16(io_addr) ((io_addr) + __SFR_OFFSET)

#define _SFR_IO_ADDR(sfr) ((sfr) - __SFR_OFFSET)
#define _SFR_MEM_ADDR(sfr) (sfr)
#define _SFR_IO_REG_P(sfr) ((sfr) < 0x40 + __SFR_OFFSET)

#if (__SFR_OFFSET == 0x20)
/* No need to use ?: operator, so works in assembler too. */
#define _SFR_ADDR(sfr) _SFR_MEM_ADDR(sfr)
#elif !defined(__ASSEMBLER__)
#define _SFR_ADDR(sfr) (_SFR_IO_REG_P(sfr) ? (_SFR_IO_ADDR(sfr) + 0x20) : _SFR_MEM_ADDR(sfr))
#endif

#else /* !_SFR_ASM_COMPAT */

#define _SFR_MEM8(mem_addr) _MMIO_BYTE(mem_addr)
#define _SFR_MEM16(mem_addr) _MMIO_WORD(mem_addr)
#define _SFR_IO8(io_addr) _MMIO_BYTE((io_addr) + 0x20)
#define _SFR_IO16(io_addr) _MMIO_WORD((io_addr) + 0x20)

#define _SFR_MEM_ADDR(sfr) ((uint16_t) &(sfr))
#define _SFR_IO_ADDR(sfr) (_SFR_MEM_ADDR(sfr) - 0x20)
#define _SFR_IO_REG_P(sfr) (_SFR_MEM_ADDR(sfr) < 0x60)

#define _SFR_ADDR(sfr) _SFR_MEM_ADDR(sfr)

#endif /* !_SFR_ASM_COMPAT */

#define _SFR_BYTE(sfr) _MMIO_BYTE(_SFR_ADDR(sfr))
#define _SFR_WORD(sfr) _MMIO_WORD(_SFR_ADDR(sfr))

/** \name Bit manipulation */

/*@{*/
/** \def _BV
\ingroup avr_sfr

\code #include <avr/io.h>\endcode

Converts a bit number into a byte value.

\note The bit shift is performed by the compiler which then inserts the
result into the code. Thus, there is no run-time overhead when using
_BV(). */

#define _BV(bit) (1 << (bit))

/*@}*/

#ifndef _VECTOR
#define _VECTOR(N) __vector_ ## N
#endif

#ifndef __ASSEMBLER__


/** \name IO register bit manipulation */

/*@{*/



/** \def bit_is_set
\ingroup avr_sfr

\code #include <avr/io.h>\endcode

Test whether bit \c bit in IO register \c sfr is set.
This will return a 0 if the bit is clear, and non-zero
if the bit is set. */

#define bit_is_set(sfr, bit) (_SFR_BYTE(sfr) & _BV(bit))

/** \def bit_is_clear
\ingroup avr_sfr

\code #include <avr/io.h>\endcode

Test whether bit \c bit in IO register \c sfr is clear.
This will return non-zero if the bit is clear, and a 0
if the bit is set. */

#define bit_is_clear(sfr, bit) (!(_SFR_BYTE(sfr) & _BV(bit)))

/** \def loop_until_bit_is_set
\ingroup avr_sfr

\code #include <avr/io.h>\endcode

Wait until bit \c bit in IO register \c sfr is set. */

#define loop_until_bit_is_set(sfr, bit) do { } while (bit_is_clear(sfr, bit))

/** \def loop_until_bit_is_clear
\ingroup avr_sfr

\code #include <avr/io.h>\endcode

Wait until bit \c bit in IO register \c sfr is clear. */

#define loop_until_bit_is_clear(sfr, bit) do { } while (bit_is_set(sfr, bit))

/*@}*/

#endif /* !__ASSEMBLER__ */

/* Backwards compatibility, do not use in new programs. */

/** \name Deprecated Macros */
/*@{*/


/** \def cbi
\ingroup avr_sfr
\deprecated
\code #include <avr/io.h>\endcode
For backwards compatibility only. This macro will eventually be removed.

Clear bit \c bit in IO register \c sfr. */

#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))

/** \def sbi
\ingroup avr_sfr
\deprecated
\code #include <avr/io.h>\endcode
For backwards compatibility only. This macro will eventually be removed.

Set bit \c bit in IO register \c sfr. */

#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))



/** \def inb
\ingroup avr_sfr
\deprecated
\code #include <avr/io.h>\endcode
For backwards compatibility only. This macro will eventually be removed.

\par
Use direct access in new programs. */

#define inb(sfr) _SFR_BYTE(sfr)



/** \def outb
\ingroup avr_sfr
\deprecated
\code #include <avr/io.h>\endcode

For backwards compatibility only. This macro will eventually be removed.

\par
Use direct access in new programs.

\note The order of the arguments was switched in older versions of
avr-libc (versions <= 20020203). */


#define outb(sfr, val) (_SFR_BYTE(sfr) = (val))

/* The outb/outw macros now have the correct order of arguments. */

/** \def inw
\ingroup avr_sfr
\deprecated
\code #include <avr/io.h>\endcode
For backwards compatibility only. This macro will eventually be removed.

Read a 16-bit word from IO register pair \c sfr.

\par
Use direct access in new programs. */

#define inw(sfr) _SFR_WORD(sfr)


/** \def outw
\ingroup avr_sfr
\deprecated
\code #include <avr/io.h>\endcode
For backwards compatibility only. This macro will eventually be removed.

Write the 16-bit value \c val to IO register pair \c sfr. Care
will be taken to write the lower register first. When used to
update 16-bit registers where the timing is critical and the
operation can be interrupted, the programmer is the responsible for
disabling interrupts before accessing the register pair.

\par
Use direct access in new programs.

\note The order of the arguments was switched in older versions of
avr-libc (versions <= 20020203). */


#define outw(sfr, val) (_SFR_WORD(sfr) = (val))


/** \def outp
\ingroup avr_sfr
\deprecated
For backwards compatibility only. This macro will eventually be removed.

\par
Use direct access in new programs. */

#define outp(val, sfr) outb(sfr, val)

/** \def inp
\ingroup avr_sfr
\deprecated
For backwards compatibility only. This macro will eventually be removed.

\par
Use direct access in new programs. */

#define inp(sfr) inb(sfr)

/** \def BV
\ingroup avr_sfr
\deprecated
For backwards compatibility only. This macro will eventually be removed.

\par
Use _BV() in new programs. */

#define BV(bit) _BV(bit)

/*@}*/

#endif /* _SFR_DEFS_H_ */

Einfach wo hinschreiben und vor avr/io.h includen, und die Welt ist wieder heile.

Murphywareinoptimist
20.03.2006, 13:59
Hi!

Danke =D>

Was ist denn an den neueren Versionen anders? Oder kann ich als Otto-Normalverbraucher auch mit einer älteren weitermachen?
Die habe ich übrigens von der Asuro-CD.

Gruß Olli

SprinterSB
20.03.2006, 14:11
Die 4-er Version von GCC ist wohl noch nicht so ganz in trockenen Tüchern.

Die 3-Version erzeugt eigentlich nen sehr guten Code, wenn man ein paar Kleinigkeiten beachtet. Ein Umstieg ist also nicht dringlich. GCC wird ständig weiter entwickelt, aber deswegen sollte man nicht in Hektik verfallen und immer das neueste haben müssen, wie mancher es von PCs oder Händis kennen mag...

Vom Frontend haben sich ein paar Bezeichner geändert, etwa bei den Namen der IRQ-Vetoren. Keine Ahnung, was das soll. Ist voll unnötig. Zudem gibt's die Änderungen in der Headern, etc.

Im Middleend gibt's ne neue interne algebraische Repräsentation des Programmes in SSA-Form, die auf lange Sicht noch besseren Code erwarten lassen. Inwieweit das auf AVR durchschlägt, bleibt abzuwarten.

Jul-ian
20.03.2006, 17:16
Ich will Eure Diskussion ja ungerne unterbrechen, aber kann mir nun jemand helfen mein LCD anzusteuern?
Leider finde ich keinerlei Dokumentation zu diesem Thema