Återkommande fel i Arduino-koden. (FIXAT igen)
Återkommande fel i Arduino-koden. (FIXAT igen)
Det här kommer ofta upp när jag försöker ta in färdiga kodexempel.
Är det någon som har en aning om vad som är fel, och vad man kan göra åt det?
In function 'void loop()':
error: 'class DateTime' has no member named 'get'
Serial.println(now.get());
Har försökt leta i dom h-filer som blir includade, men hittar inget get, hmm...
Är det någon som har en aning om vad som är fel, och vad man kan göra åt det?
In function 'void loop()':
error: 'class DateTime' has no member named 'get'
Serial.println(now.get());
Har försökt leta i dom h-filer som blir includade, men hittar inget get, hmm...
Senast redigerad av jojje 27 juli 2010, 19:58:54, redigerad totalt 3 gånger.
- ElectricMan
- Inlägg: 4874
- Blev medlem: 21 februari 2007, 20:22:48
- Skype: ElectricManSwe
- Ort: Luleå
- Kontakt:
Re: Återkommande fel i Arduino-koden.
Säker på att du ska använda "get"?
Många funktioner är definierat så att de har en "get" & en "put" men då menas ibland att "get" betyder att man hämtar värdet ("X = now()") och "put" att ett värde ges till funktionen ("now(X)" eller "now() = X")
Många funktioner är definierat så att de har en "get" & en "put" men då menas ibland att "get" betyder att man hämtar värdet ("X = now()") och "put" att ett värde ges till funktionen ("now(X)" eller "now() = X")
Re: Återkommande fel i Arduino-koden.
Icecap, det är inte jag som skrivit koden, dom är färdiga exempel, bara att öppna.
Här är hela koden.
När man kompilerar (Verify) så kommer följande upp i nederkant på fönstret.
In function 'void loop()':
error: 'class DateTime' has no member named 'get'
Här är hela koden.
Kod: Markera allt
// Date and time functions using just software, based on millis() & timer
#include <Wire.h>
#include "RTClib.h"
RTC_Millis RTC;
void setup () {
Serial.begin(57600);
// following line sets the RTC to the date & time this sketch was compiled
RTC.begin(DateTime(__DATE__, __TIME__));
}
void loop () {
DateTime now = RTC.now();
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(' ');
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
Serial.print(" seconds since 2000: ");
Serial.println(now.get());
// calculate a date which is 7 days and 30 seconds into the future
DateTime future (now.get() + 7 * 86400L + 30);
Serial.print(" now + 7d + 30s: ");
Serial.print(future.year(), DEC);
Serial.print('/');
Serial.print(future.month(), DEC);
Serial.print('/');
Serial.print(future.day(), DEC);
Serial.print(' ');
Serial.print(future.hour(), DEC);
Serial.print(':');
Serial.print(future.minute(), DEC);
Serial.print(':');
Serial.print(future.second(), DEC);
Serial.println();
Serial.println();
delay(3000);
}
In function 'void loop()':
error: 'class DateTime' has no member named 'get'
Re: Återkommande fel i Arduino-koden.
Gissar att det är C.
I så fall
Du skapar en variabel med namn "now" av typen DateTime, vilket förmodligen är en struct eller nått liknande.
Ett par rader längre ner, används now.get() vilket rimligtvis borde vara ett funktionsanrop.
Du får försöka hitta definitionen av DateTime, vilket sannolikt ligger i RTCLib.h (eller snarare troligen i RTCLib.c)
I så fall
Du skapar en variabel med namn "now" av typen DateTime, vilket förmodligen är en struct eller nått liknande.
Ett par rader längre ner, används now.get() vilket rimligtvis borde vara ett funktionsanrop.
Du får försöka hitta definitionen av DateTime, vilket sannolikt ligger i RTCLib.h (eller snarare troligen i RTCLib.c)
Re: Återkommande fel i Arduino-koden.
Har du installerat bibloteken som används eller bara öppnat exempelkoden?
Re: Återkommande fel i Arduino-koden.
Är det denna du använder? De har nog ändrat i "biblioteket" och glömt uppdatera exemplet. Om du byter "now.get()" till "now.secondstime()" tror jag det skall funka.
Re: Återkommande fel i Arduino-koden.
TomasL:
Har försökt att leta överallt, men hittar ingenting. Kan nog vara min kunskap som är begränsande.
Uttis:
Jepp, allt är inne, iaf så långt jag kan förstå, men...
Solly snigelen, men det kommer bara flera felmeddelanden nu.
Skulle vara bra att ha lite draghjälp från färdiga "moduler" när jag ska göra alarmklocka.
Jag har hittat bibliotek även för alarm, men det blir liknande fel även där.
Det är mest den där "get" som trasslar till det för mig.
Har försökt att leta överallt, men hittar ingenting. Kan nog vara min kunskap som är begränsande.

Uttis:
Jepp, allt är inne, iaf så långt jag kan förstå, men...

Solly snigelen, men det kommer bara flera felmeddelanden nu.

Det är väl bara att hitta på nåt annat roligt att fördriva tiden med.o: In function `loop':
C:\DOCUME~1\GAREN~1\LOKALA~1\Temp\build1089958537974416911.tmp/softrtc.cpp:34: undefined reference to `DateTime::secondstime() const'
C:\DOCUME~1\GAREN~1\LOKALA~1\Temp\build1089958537974416911.tmp/softrtc.cpp:37: undefined reference to `DateTime::secondstime() const'
C:\DOCUME~1\GAREN~1\LOKALA~1\Temp\build1089958537974416911.tmp\RTClib\RTClib.cpp.o: In function `RTC_Millis::adjust(DateTime const&)':
C:\Dev\arduino-0018\libraries\RTClib/RTClib.cpp:178: undefined reference to `DateTime::secondstime() const'

Skulle vara bra att ha lite draghjälp från färdiga "moduler" när jag ska göra alarmklocka.
Jag har hittat bibliotek även för alarm, men det blir liknande fel även där.
Det är mest den där "get" som trasslar till det för mig.
Re: Återkommande fel i Arduino-koden.
Tror jag fått med mig allt nu.
RTCLib.h
RTClib.cpp
Wire.h
pgmspace.h
WProgram.h

RTCLib.h
Kod: Markera allt
// Code by JeeLabs http://news.jeelabs.org/code/
// Released to the public domain! Enjoy!
// Simple general-purpose date/time class (no TZ / DST / leap second handling!)
class DateTime {
public:
DateTime (uint32_t t =0);
DateTime (uint16_t year, uint8_t month, uint8_t day,
uint8_t hour =0, uint8_t min =0, uint8_t sec =0);
DateTime (const char* date, const char* time);
uint16_t year() const { return 2000 + yOff; }
uint8_t month() const { return m; }
uint8_t day() const { return d; }
uint8_t hour() const { return hh; }
uint8_t minute() const { return mm; }
uint8_t second() const { return ss; }
uint8_t dayOfWeek() const;
// 32-bit times as seconds since 1/1/2000
long secondstime() const;
// 32-bit times as seconds since 1/1/1970
uint32_t unixtime(void) const;
protected:
uint8_t yOff, m, d, hh, mm, ss;
};
// RTC based on the DS1307 chip connected via I2C and the Wire library
class RTC_DS1307 {
public:
static uint8_t begin(void);
static void adjust(const DateTime& dt);
uint8_t isrunning(void);
static DateTime now();
};
// RTC using the internal millis() clock, has to be initialized before use
// NOTE: this clock won't be correct once the millis() timer rolls over (>49d?)
class RTC_Millis {
public:
static void begin(const DateTime& dt) { adjust(dt); }
static void adjust(const DateTime& dt);
static DateTime now();
protected:
static long offset;
};
Kod: Markera allt
// Code by JeeLabs http://news.jeelabs.org/code/
// Released to the public domain! Enjoy!
#include <Wire.h>
#include <avr/pgmspace.h>
#include "RTClib.h"
#include <WProgram.h>
#define DS1307_ADDRESS 0x68
#define SECONDS_PER_DAY 86400L
#define SECONDS_FROM_1970_TO_2000 946684800
////////////////////////////////////////////////////////////////////////////////
// utility code, some of this could be exposed in the DateTime API if needed
static uint8_t daysInMonth [] PROGMEM = { 31,28,31,30,31,30,31,31,30,31,30,31 };
// number of days since 2000/01/01, valid for 2001..2099
static uint16_t date2days(uint16_t y, uint8_t m, uint8_t d) {
if (y >= 2000)
y -= 2000;
uint16_t days = d;
for (uint8_t i = 1; i < m; ++i)
days += pgm_read_byte(daysInMonth + i - 1);
if (m > 2 && y % 4 == 0)
++days;
return days + 365 * y + (y + 3) / 4 - 1;
}
static long time2long(uint16_t days, uint8_t h, uint8_t m, uint8_t s) {
return ((days * 24L + h) * 60 + m) * 60 + s;
}
////////////////////////////////////////////////////////////////////////////////
// DateTime implementation - ignores time zones and DST changes
// NOTE: also ignores leap seconds, see http://en.wikipedia.org/wiki/Leap_second
DateTime::DateTime (uint32_t t) {
t -= SECONDS_FROM_1970_TO_2000; // bring to 2000 timestamp from 1970
ss = t % 60;
t /= 60;
mm = t % 60;
t /= 60;
hh = t % 24;
uint16_t days = t / 24;
uint8_t leap;
for (yOff = 0; ; ++yOff) {
leap = yOff % 4 == 0;
if (days < 365 + leap)
break;
days -= 365 + leap;
}
for (m = 1; ; ++m) {
uint8_t daysPerMonth = pgm_read_byte(daysInMonth + m - 1);
if (leap && m == 2)
++daysPerMonth;
if (days < daysPerMonth)
break;
days -= daysPerMonth;
}
d = days + 1;
}
DateTime::DateTime (uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t min, uint8_t sec) {
if (year >= 2000)
year -= 2000;
yOff = year;
m = month;
d = day;
hh = hour;
mm = min;
ss = sec;
}
static uint8_t conv2d(const char* p) {
uint8_t v = 0;
if ('0' <= *p && *p <= '9')
v = *p - '0';
return 10 * v + *++p - '0';
}
// A convenient constructor for using "the compiler's time":
// DateTime now (__DATE__, __TIME__);
// NOTE: using PSTR would further reduce the RAM footprint
DateTime::DateTime (const char* date, const char* time) {
// sample input: date = "Dec 26 2009", time = "12:34:56"
yOff = conv2d(date + 9);
// Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
switch (date[0]) {
case 'J': m = date[1] == 'a' ? 1 : m = date[2] == 'n' ? 6 : 7; break;
case 'F': m = 2; break;
case 'A': m = date[2] == 'r' ? 4 : 8; break;
case 'M': m = date[2] == 'r' ? 3 : 5; break;
case 'S': m = 9; break;
case 'O': m = 10; break;
case 'N': m = 11; break;
case 'D': m = 12; break;
}
d = conv2d(date + 4);
hh = conv2d(time);
mm = conv2d(time + 3);
ss = conv2d(time + 6);
}
uint8_t DateTime::dayOfWeek() const {
uint16_t day = date2days(yOff, m, d);
return (day + 6) % 7; // Jan 1, 2000 is a Saturday, i.e. returns 6
}
uint32_t DateTime::unixtime(void) const {
uint32_t t;
uint16_t days = date2days(yOff, m, d);
t = time2long(days, hh, mm, ss);
t += SECONDS_FROM_1970_TO_2000; // seconds from 1970 to 2000
return t;
}
////////////////////////////////////////////////////////////////////////////////
// RTC_DS1307 implementation
static uint8_t bcd2bin (uint8_t val) { return val - 6 * (val >> 4); }
static uint8_t bin2bcd (uint8_t val) { return val + 6 * (val / 10); }
uint8_t RTC_DS1307::begin(void) {
return 1;
}
uint8_t RTC_DS1307::isrunning(void) {
Wire.beginTransmission(DS1307_ADDRESS);
Wire.send(0);
Wire.endTransmission();
Wire.requestFrom(DS1307_ADDRESS, 1);
uint8_t ss = Wire.receive();
return !(ss>>7);
}
void RTC_DS1307::adjust(const DateTime& dt) {
Wire.beginTransmission(DS1307_ADDRESS);
Wire.send(0);
Wire.send(bin2bcd(dt.second()));
Wire.send(bin2bcd(dt.minute()));
Wire.send(bin2bcd(dt.hour()));
Wire.send(bin2bcd(0));
Wire.send(bin2bcd(dt.day()));
Wire.send(bin2bcd(dt.month()));
Wire.send(bin2bcd(dt.year() - 2000));
Wire.send(0);
Wire.endTransmission();
}
DateTime RTC_DS1307::now() {
Wire.beginTransmission(DS1307_ADDRESS);
Wire.send(0);
Wire.endTransmission();
Wire.requestFrom(DS1307_ADDRESS, 7);
uint8_t ss = bcd2bin(Wire.receive() & 0x7F);
uint8_t mm = bcd2bin(Wire.receive());
uint8_t hh = bcd2bin(Wire.receive());
Wire.receive();
uint8_t d = bcd2bin(Wire.receive());
uint8_t m = bcd2bin(Wire.receive());
uint16_t y = bcd2bin(Wire.receive()) + 2000;
return DateTime (y, m, d, hh, mm, ss);
}
////////////////////////////////////////////////////////////////////////////////
// RTC_Millis implementation
long RTC_Millis::offset = 0;
void RTC_Millis::adjust(const DateTime& dt) {
offset = dt.secondstime() - millis() / 1000;
}
DateTime RTC_Millis::now() {
return (uint32_t)(offset + millis() / 1000);
}
////////////////////////////////////////////////////////////////////////////////
Kod: Markera allt
/*
TwoWire.h - TWI/I2C library for Arduino & Wiring
Copyright (c) 2006 Nicholas Zambetti. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef TwoWire_h
#define TwoWire_h
#include <inttypes.h>
#define BUFFER_LENGTH 32
class TwoWire
{
private:
static uint8_t* rxBuffer;
static uint8_t rxBufferIndex;
static uint8_t rxBufferLength;
static uint8_t txAddress;
static uint8_t* txBuffer;
static uint8_t txBufferIndex;
static uint8_t txBufferLength;
static uint8_t transmitting;
static void (*user_onRequest)(void);
static void (*user_onReceive)(int);
static void onRequestService(void);
static void onReceiveService(uint8_t*, int);
public:
TwoWire();
void begin();
void begin(uint8_t);
void begin(int);
void beginTransmission(uint8_t);
void beginTransmission(int);
uint8_t endTransmission(void);
uint8_t requestFrom(uint8_t, uint8_t);
uint8_t requestFrom(int, int);
void send(uint8_t);
void send(uint8_t*, uint8_t);
void send(int);
void send(char*);
uint8_t available(void);
uint8_t receive(void);
void onReceive( void (*)(int) );
void onRequest( void (*)(void) );
};
extern TwoWire Wire;
#endif
Kod: Markera allt
/* Copyright (c) 2002 - 2007 Marek Michalkiewicz
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.
* Neither the name of the copyright holders nor the names of
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
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. */
/* $Id: pgmspace.h,v 1.40.2.2 2008/10/22 04:35:00 arcanum Exp $ */
/*
pgmspace.h
Contributors:
Created by Marek Michalkiewicz <marekm@linux.org.pl>
Eric B. Weddington <eric@ecentral.com>
Wolfgang Haidinger <wh@vmars.tuwien.ac.at> (pgm_read_dword())
Ivanov Anton <anton@arc.com.ru> (pgm_read_float())
*/
/** \file */
/** \defgroup avr_pgmspace <avr/pgmspace.h>: Program Space Utilities
\code
#include <avr/io.h>
#include <avr/pgmspace.h>
\endcode
The functions in this module provide interfaces for a program to access
data stored in program space (flash memory) of the device. In order to
use these functions, the target device must support either the \c LPM or
\c ELPM instructions.
\note These functions are an attempt to provide some compatibility with
header files that come with IAR C, to make porting applications between
different compilers easier. This is not 100% compatibility though (GCC
does not have full support for multiple address spaces yet).
\note If you are working with strings which are completely based in ram,
use the standard string functions described in \ref avr_string.
\note If possible, put your constant tables in the lower 64 KB and use
pgm_read_byte_near() or pgm_read_word_near() instead of
pgm_read_byte_far() or pgm_read_word_far() since it is more efficient that
way, and you can still use the upper 64K for executable code.
All functions that are suffixed with a \c _P \e require their
arguments to be in the lower 64 KB of the flash ROM, as they do
not use ELPM instructions. This is normally not a big concern as
the linker setup arranges any program space constants declared
using the macros from this header file so they are placed right after
the interrupt vectors, and in front of any executable code. However,
it can become a problem if there are too many of these constants, or
for bootloaders on devices with more than 64 KB of ROM.
<em>All these functions will not work in that situation.</em>
*/
#ifndef __PGMSPACE_H_
#define __PGMSPACE_H_ 1
#define __need_size_t
#include <inttypes.h>
#include <stddef.h>
#include <avr/io.h>
#ifndef __ATTR_CONST__
#define __ATTR_CONST__ __attribute__((__const__))
#endif
#ifndef __ATTR_PROGMEM__
#define __ATTR_PROGMEM__ __attribute__((__progmem__))
#endif
#ifndef __ATTR_PURE__
#define __ATTR_PURE__ __attribute__((__pure__))
#endif
/**
\ingroup avr_pgmspace
\def PROGMEM
Attribute to use in order to declare an object being located in
flash ROM.
*/
#define PROGMEM __ATTR_PROGMEM__
#ifdef __cplusplus
extern "C" {
#endif
#if defined(__DOXYGEN__)
/*
* Doxygen doesn't grok the appended attribute syntax of
* GCC, and confuses the typedefs with function decls, so
* supply a doxygen-friendly view.
*/
/**
\ingroup avr_pgmspace
\typedef prog_void
Type of a "void" object located in flash ROM. Does not make much
sense by itself, but can be used to declare a "void *" object in
flash ROM.
*/
typedef void PROGMEM prog_void;
/**
\ingroup avr_pgmspace
\typedef prog_char
Type of a "char" object located in flash ROM.
*/
typedef char PROGMEM prog_char;
/**
\ingroup avr_pgmspace
\typedef prog_uchar
Type of an "unsigned char" object located in flash ROM.
*/
typedef unsigned char PROGMEM prog_uchar;
/**
\ingroup avr_pgmspace
\typedef prog_int8_t
Type of an "int8_t" object located in flash ROM.
*/
typedef int8_t PROGMEM prog_int8_t;
/**
\ingroup avr_pgmspace
\typedef prog_uint8_t
Type of an "uint8_t" object located in flash ROM.
*/
typedef uint8_t PROGMEM prog_uint8_t;
/**
\ingroup avr_pgmspace
\typedef prog_int16_t
Type of an "int16_t" object located in flash ROM.
*/
typedef int16_t PROGMEM prog_int16_t;
/**
\ingroup avr_pgmspace
\typedef prog_uint16_t
Type of an "uint16_t" object located in flash ROM.
*/
typedef uint16_t PROGMEM prog_uint16_t;
/**
\ingroup avr_pgmspace
\typedef prog_int32_t
Type of an "int32_t" object located in flash ROM.
*/
typedef int32_t PROGMEM prog_int32_t;
/**
\ingroup avr_pgmspace
\typedef prog_uint32_t
Type of an "uint32_t" object located in flash ROM.
*/
typedef uint32_t PROGMEM prog_uint32_t;
/**
\ingroup avr_pgmspace
\typedef prog_int64_t
Type of an "int64_t" object located in flash ROM.
\note This type is not available when the compiler
option -mint8 is in effect.
*/
typedef int64_t PROGMEM prog_int64_t;
/**
\ingroup avr_pgmspace
\typedef prog_uint64_t
Type of an "uint64_t" object located in flash ROM.
\note This type is not available when the compiler
option -mint8 is in effect.
*/
typedef uint64_t PROGMEM prog_uint64_t;
#else /* !DOXYGEN */
typedef void prog_void PROGMEM;
typedef char prog_char PROGMEM;
typedef unsigned char prog_uchar PROGMEM;
typedef int8_t prog_int8_t PROGMEM;
typedef uint8_t prog_uint8_t PROGMEM;
typedef int16_t prog_int16_t PROGMEM;
typedef uint16_t prog_uint16_t PROGMEM;
typedef int32_t prog_int32_t PROGMEM;
typedef uint32_t prog_uint32_t PROGMEM;
#if !__USING_MINT8
typedef int64_t prog_int64_t PROGMEM;
typedef uint64_t prog_uint64_t PROGMEM;
#endif
#endif /* defined(__DOXYGEN__) */
/* Although in C, we can get away with just using __c, it does not work in
C++. We need to use &__c[0] to avoid the compiler puking. Dave Hylands
explaned it thusly,
Let's suppose that we use PSTR("Test"). In this case, the type returned
by __c is a prog_char[5] and not a prog_char *. While these are
compatible, they aren't the same thing (especially in C++). The type
returned by &__c[0] is a prog_char *, which explains why it works
fine. */
#if defined(__DOXYGEN__)
/*
* The #define below is just a dummy that serves documentation
* purposes only.
*/
/** \ingroup avr_pgmspace
\def PSTR(s)
Used to declare a static pointer to a string in program space. */
# define PSTR(s) ((const PROGMEM char *)(s))
#else /* !DOXYGEN */
/* The real thing. */
# define PSTR(s) (__extension__({static char __c[] PROGMEM = (s); &__c[0];}))
#endif /* DOXYGEN */
#define __LPM_classic__(addr) \
(__extension__({ \
uint16_t __addr16 = (uint16_t)(addr); \
uint8_t __result; \
__asm__ \
( \
"lpm" "\n\t" \
"mov %0, r0" "\n\t" \
: "=r" (__result) \
: "z" (__addr16) \
: "r0" \
); \
__result; \
}))
#define __LPM_enhanced__(addr) \
(__extension__({ \
uint16_t __addr16 = (uint16_t)(addr); \
uint8_t __result; \
__asm__ \
( \
"lpm %0, Z" "\n\t" \
: "=r" (__result) \
: "z" (__addr16) \
); \
__result; \
}))
#define __LPM_word_classic__(addr) \
(__extension__({ \
uint16_t __addr16 = (uint16_t)(addr); \
uint16_t __result; \
__asm__ \
( \
"lpm" "\n\t" \
"mov %A0, r0" "\n\t" \
"adiw r30, 1" "\n\t" \
"lpm" "\n\t" \
"mov %B0, r0" "\n\t" \
: "=r" (__result), "=z" (__addr16) \
: "1" (__addr16) \
: "r0" \
); \
__result; \
}))
#define __LPM_word_enhanced__(addr) \
(__extension__({ \
uint16_t __addr16 = (uint16_t)(addr); \
uint16_t __result; \
__asm__ \
( \
"lpm %A0, Z+" "\n\t" \
"lpm %B0, Z" "\n\t" \
: "=r" (__result), "=z" (__addr16) \
: "1" (__addr16) \
); \
__result; \
}))
#define __LPM_dword_classic__(addr) \
(__extension__({ \
uint16_t __addr16 = (uint16_t)(addr); \
uint32_t __result; \
__asm__ \
( \
"lpm" "\n\t" \
"mov %A0, r0" "\n\t" \
"adiw r30, 1" "\n\t" \
"lpm" "\n\t" \
"mov %B0, r0" "\n\t" \
"adiw r30, 1" "\n\t" \
"lpm" "\n\t" \
"mov %C0, r0" "\n\t" \
"adiw r30, 1" "\n\t" \
"lpm" "\n\t" \
"mov %D0, r0" "\n\t" \
: "=r" (__result), "=z" (__addr16) \
: "1" (__addr16) \
: "r0" \
); \
__result; \
}))
#define __LPM_dword_enhanced__(addr) \
(__extension__({ \
uint16_t __addr16 = (uint16_t)(addr); \
uint32_t __result; \
__asm__ \
( \
"lpm %A0, Z+" "\n\t" \
"lpm %B0, Z+" "\n\t" \
"lpm %C0, Z+" "\n\t" \
"lpm %D0, Z" "\n\t" \
: "=r" (__result), "=z" (__addr16) \
: "1" (__addr16) \
); \
__result; \
}))
#define __LPM_float_classic__(addr) \
(__extension__({ \
uint16_t __addr16 = (uint16_t)(addr); \
float __result; \
__asm__ \
( \
"lpm" "\n\t" \
"mov %A0, r0" "\n\t" \
"adiw r30, 1" "\n\t" \
"lpm" "\n\t" \
"mov %B0, r0" "\n\t" \
"adiw r30, 1" "\n\t" \
"lpm" "\n\t" \
"mov %C0, r0" "\n\t" \
"adiw r30, 1" "\n\t" \
"lpm" "\n\t" \
"mov %D0, r0" "\n\t" \
: "=r" (__result), "=z" (__addr16) \
: "1" (__addr16) \
: "r0" \
); \
__result; \
}))
#define __LPM_float_enhanced__(addr) \
(__extension__({ \
uint16_t __addr16 = (uint16_t)(addr); \
float __result; \
__asm__ \
( \
"lpm %A0, Z+" "\n\t" \
"lpm %B0, Z+" "\n\t" \
"lpm %C0, Z+" "\n\t" \
"lpm %D0, Z" "\n\t" \
: "=r" (__result), "=z" (__addr16) \
: "1" (__addr16) \
); \
__result; \
}))
#if defined (__AVR_HAVE_LPMX__)
#define __LPM(addr) __LPM_enhanced__(addr)
#define __LPM_word(addr) __LPM_word_enhanced__(addr)
#define __LPM_dword(addr) __LPM_dword_enhanced__(addr)
#define __LPM_float(addr) __LPM_float_enhanced__(addr)
#else
#define __LPM(addr) __LPM_classic__(addr)
#define __LPM_word(addr) __LPM_word_classic__(addr)
#define __LPM_dword(addr) __LPM_dword_classic__(addr)
#define __LPM_float(addr) __LPM_float_classic__(addr)
#endif
/** \ingroup avr_pgmspace
\def pgm_read_byte_near(address_short)
Read a byte from the program space with a 16-bit (near) address.
\note The address is a byte address.
The address is in the program space. */
#define pgm_read_byte_near(address_short) __LPM((uint16_t)(address_short))
/** \ingroup avr_pgmspace
\def pgm_read_word_near(address_short)
Read a word from the program space with a 16-bit (near) address.
\note The address is a byte address.
The address is in the program space. */
#define pgm_read_word_near(address_short) __LPM_word((uint16_t)(address_short))
/** \ingroup avr_pgmspace
\def pgm_read_dword_near(address_short)
Read a double word from the program space with a 16-bit (near) address.
\note The address is a byte address.
The address is in the program space. */
#define pgm_read_dword_near(address_short) \
__LPM_dword((uint16_t)(address_short))
/** \ingroup avr_pgmspace
\def pgm_read_float_near(address_short)
Read a float from the program space with a 16-bit (near) address.
\note The address is a byte address.
The address is in the program space. */
#define pgm_read_float_near(address_short) \
__LPM_float((uint16_t)(address_short))
#if defined(RAMPZ) || defined(__DOXYGEN__)
/* Only for devices with more than 64K of program memory.
RAMPZ must be defined (see iom103.h, iom128.h).
*/
/* The classic functions are needed for ATmega103. */
#define __ELPM_classic__(addr) \
(__extension__({ \
uint32_t __addr32 = (uint32_t)(addr); \
uint8_t __result; \
__asm__ \
( \
"out %2, %C1" "\n\t" \
"mov r31, %B1" "\n\t" \
"mov r30, %A1" "\n\t" \
"elpm" "\n\t" \
"mov %0, r0" "\n\t" \
: "=r" (__result) \
: "r" (__addr32), \
"I" (_SFR_IO_ADDR(RAMPZ)) \
: "r0", "r30", "r31" \
); \
__result; \
}))
#define __ELPM_enhanced__(addr) \
(__extension__({ \
uint32_t __addr32 = (uint32_t)(addr); \
uint8_t __result; \
__asm__ \
( \
"out %2, %C1" "\n\t" \
"movw r30, %1" "\n\t" \
"elpm %0, Z+" "\n\t" \
: "=r" (__result) \
: "r" (__addr32), \
"I" (_SFR_IO_ADDR(RAMPZ)) \
: "r30", "r31" \
); \
__result; \
}))
#define __ELPM_word_classic__(addr) \
(__extension__({ \
uint32_t __addr32 = (uint32_t)(addr); \
uint16_t __result; \
__asm__ \
( \
"out %2, %C1" "\n\t" \
"mov r31, %B1" "\n\t" \
"mov r30, %A1" "\n\t" \
"elpm" "\n\t" \
"mov %A0, r0" "\n\t" \
"in r0, %2" "\n\t" \
"adiw r30, 1" "\n\t" \
"adc r0, __zero_reg__" "\n\t" \
"out %2, r0" "\n\t" \
"elpm" "\n\t" \
"mov %B0, r0" "\n\t" \
: "=r" (__result) \
: "r" (__addr32), \
"I" (_SFR_IO_ADDR(RAMPZ)) \
: "r0", "r30", "r31" \
); \
__result; \
}))
#define __ELPM_word_enhanced__(addr) \
(__extension__({ \
uint32_t __addr32 = (uint32_t)(addr); \
uint16_t __result; \
__asm__ \
( \
"out %2, %C1" "\n\t" \
"movw r30, %1" "\n\t" \
"elpm %A0, Z+" "\n\t" \
"elpm %B0, Z" "\n\t" \
: "=r" (__result) \
: "r" (__addr32), \
"I" (_SFR_IO_ADDR(RAMPZ)) \
: "r30", "r31" \
); \
__result; \
}))
#define __ELPM_dword_classic__(addr) \
(__extension__({ \
uint32_t __addr32 = (uint32_t)(addr); \
uint32_t __result; \
__asm__ \
( \
"out %2, %C1" "\n\t" \
"mov r31, %B1" "\n\t" \
"mov r30, %A1" "\n\t" \
"elpm" "\n\t" \
"mov %A0, r0" "\n\t" \
"in r0, %2" "\n\t" \
"adiw r30, 1" "\n\t" \
"adc r0, __zero_reg__" "\n\t" \
"out %2, r0" "\n\t" \
"elpm" "\n\t" \
"mov %B0, r0" "\n\t" \
"in r0, %2" "\n\t" \
"adiw r30, 1" "\n\t" \
"adc r0, __zero_reg__" "\n\t" \
"out %2, r0" "\n\t" \
"elpm" "\n\t" \
"mov %C0, r0" "\n\t" \
"in r0, %2" "\n\t" \
"adiw r30, 1" "\n\t" \
"adc r0, __zero_reg__" "\n\t" \
"out %2, r0" "\n\t" \
"elpm" "\n\t" \
"mov %D0, r0" "\n\t" \
: "=r" (__result) \
: "r" (__addr32), \
"I" (_SFR_IO_ADDR(RAMPZ)) \
: "r0", "r30", "r31" \
); \
__result; \
}))
#define __ELPM_dword_enhanced__(addr) \
(__extension__({ \
uint32_t __addr32 = (uint32_t)(addr); \
uint32_t __result; \
__asm__ \
( \
"out %2, %C1" "\n\t" \
"movw r30, %1" "\n\t" \
"elpm %A0, Z+" "\n\t" \
"elpm %B0, Z+" "\n\t" \
"elpm %C0, Z+" "\n\t" \
"elpm %D0, Z" "\n\t" \
: "=r" (__result) \
: "r" (__addr32), \
"I" (_SFR_IO_ADDR(RAMPZ)) \
: "r30", "r31" \
); \
__result; \
}))
#define __ELPM_float_classic__(addr) \
(__extension__({ \
uint32_t __addr32 = (uint32_t)(addr); \
float __result; \
__asm__ \
( \
"out %2, %C1" "\n\t" \
"mov r31, %B1" "\n\t" \
"mov r30, %A1" "\n\t" \
"elpm" "\n\t" \
"mov %A0, r0" "\n\t" \
"in r0, %2" "\n\t" \
"adiw r30, 1" "\n\t" \
"adc r0, __zero_reg__" "\n\t" \
"out %2, r0" "\n\t" \
"elpm" "\n\t" \
"mov %B0, r0" "\n\t" \
"in r0, %2" "\n\t" \
"adiw r30, 1" "\n\t" \
"adc r0, __zero_reg__" "\n\t" \
"out %2, r0" "\n\t" \
"elpm" "\n\t" \
"mov %C0, r0" "\n\t" \
"in r0, %2" "\n\t" \
"adiw r30, 1" "\n\t" \
"adc r0, __zero_reg__" "\n\t" \
"out %2, r0" "\n\t" \
"elpm" "\n\t" \
"mov %D0, r0" "\n\t" \
: "=r" (__result) \
: "r" (__addr32), \
"I" (_SFR_IO_ADDR(RAMPZ)) \
: "r0", "r30", "r31" \
); \
__result; \
}))
#define __ELPM_float_enhanced__(addr) \
(__extension__({ \
uint32_t __addr32 = (uint32_t)(addr); \
float __result; \
__asm__ \
( \
"out %2, %C1" "\n\t" \
"movw r30, %1" "\n\t" \
"elpm %A0, Z+" "\n\t" \
"elpm %B0, Z+" "\n\t" \
"elpm %C0, Z+" "\n\t" \
"elpm %D0, Z" "\n\t" \
: "=r" (__result) \
: "r" (__addr32), \
"I" (_SFR_IO_ADDR(RAMPZ)) \
: "r30", "r31" \
); \
__result; \
}))
#if defined (__AVR_HAVE_LPMX__)
#define __ELPM(addr) __ELPM_enhanced__(addr)
#define __ELPM_word(addr) __ELPM_word_enhanced__(addr)
#define __ELPM_dword(addr) __ELPM_dword_enhanced__(addr)
#define __ELPM_float(addr) __ELPM_float_enhanced__(addr)
#else
#define __ELPM(addr) __ELPM_classic__(addr)
#define __ELPM_word(addr) __ELPM_word_classic__(addr)
#define __ELPM_dword(addr) __ELPM_dword_classic__(addr)
#define __ELPM_float(addr) __ELPM_float_classic__(addr)
#endif
/** \ingroup avr_pgmspace
\def pgm_read_byte_far(address_long)
Read a byte from the program space with a 32-bit (far) address.
\note The address is a byte address.
The address is in the program space. */
#define pgm_read_byte_far(address_long) __ELPM((uint32_t)(address_long))
/** \ingroup avr_pgmspace
\def pgm_read_word_far(address_long)
Read a word from the program space with a 32-bit (far) address.
\note The address is a byte address.
The address is in the program space. */
#define pgm_read_word_far(address_long) __ELPM_word((uint32_t)(address_long))
/** \ingroup avr_pgmspace
\def pgm_read_dword_far(address_long)
Read a double word from the program space with a 32-bit (far) address.
\note The address is a byte address.
The address is in the program space. */
#define pgm_read_dword_far(address_long) __ELPM_dword((uint32_t)(address_long))
/** \ingroup avr_pgmspace
\def pgm_read_float_far(address_long)
Read a float from the program space with a 32-bit (far) address.
\note The address is a byte address.
The address is in the program space. */
#define pgm_read_float_far(address_long) __ELPM_float((uint32_t)(address_long))
#endif /* RAMPZ or __DOXYGEN__ */
/** \ingroup avr_pgmspace
\def pgm_read_byte(address_short)
Read a byte from the program space with a 16-bit (near) address.
\note The address is a byte address.
The address is in the program space. */
#define pgm_read_byte(address_short) pgm_read_byte_near(address_short)
/** \ingroup avr_pgmspace
\def pgm_read_word(address_short)
Read a word from the program space with a 16-bit (near) address.
\note The address is a byte address.
The address is in the program space. */
#define pgm_read_word(address_short) pgm_read_word_near(address_short)
/** \ingroup avr_pgmspace
\def pgm_read_dword(address_short)
Read a double word from the program space with a 16-bit (near) address.
\note The address is a byte address.
The address is in the program space. */
#define pgm_read_dword(address_short) pgm_read_dword_near(address_short)
/** \ingroup avr_pgmspace
\def pgm_read_float(address_short)
Read a float from the program space with a 16-bit (near) address.
\note The address is a byte address.
The address is in the program space. */
#define pgm_read_float(address_short) pgm_read_float_near(address_short)
/** \ingroup avr_pgmspace
\def PGM_P
Used to declare a variable that is a pointer to a string in program
space. */
#ifndef PGM_P
#define PGM_P const prog_char *
#endif
/** \ingroup avr_pgmspace
\def PGM_VOID_P
Used to declare a generic pointer to an object in program space. */
#ifndef PGM_VOID_P
#define PGM_VOID_P const prog_void *
#endif
extern PGM_VOID_P memchr_P(PGM_VOID_P, int __val, size_t __len) __ATTR_CONST__;
extern int memcmp_P(const void *, PGM_VOID_P, size_t) __ATTR_PURE__;
extern void *memcpy_P(void *, PGM_VOID_P, size_t);
extern void *memmem_P(const void *, size_t, PGM_VOID_P, size_t) __ATTR_PURE__;
extern PGM_VOID_P memrchr_P(PGM_VOID_P, int __val, size_t __len) __ATTR_CONST__;
extern char *strcat_P(char *, PGM_P);
extern PGM_P strchr_P(PGM_P, int __val) __ATTR_CONST__;
extern PGM_P strchrnul_P(PGM_P, int __val) __ATTR_CONST__;
extern int strcmp_P(const char *, PGM_P) __ATTR_PURE__;
extern char *strcpy_P(char *, PGM_P);
extern int strcasecmp_P(const char *, PGM_P) __ATTR_PURE__;
extern char *strcasestr_P(const char *, PGM_P) __ATTR_PURE__;
extern size_t strcspn_P(const char *__s, PGM_P __reject) __ATTR_PURE__;
extern size_t strlcat_P (char *, PGM_P, size_t );
extern size_t strlcpy_P (char *, PGM_P, size_t );
extern size_t strlen_P(PGM_P) __ATTR_CONST__; /* program memory can't change */
extern size_t strnlen_P(PGM_P, size_t) __ATTR_CONST__; /* program memory can't change */
extern int strncmp_P(const char *, PGM_P, size_t) __ATTR_PURE__;
extern int strncasecmp_P(const char *, PGM_P, size_t) __ATTR_PURE__;
extern char *strncat_P(char *, PGM_P, size_t);
extern char *strncpy_P(char *, PGM_P, size_t);
extern char *strpbrk_P(const char *__s, PGM_P __accept) __ATTR_PURE__;
extern PGM_P strrchr_P(PGM_P, int __val) __ATTR_CONST__;
extern char *strsep_P(char **__sp, PGM_P __delim);
extern size_t strspn_P(const char *__s, PGM_P __accept) __ATTR_PURE__;
extern char *strstr_P(const char *, PGM_P) __ATTR_PURE__;
#ifdef __cplusplus
}
#endif
#endif /* __PGMSPACE_H_ */
Kod: Markera allt
#ifndef WProgram_h
#define WProgram_h
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <avr/interrupt.h>
#include "wiring.h"
#ifdef __cplusplus
#include "HardwareSerial.h"
uint16_t makeWord(uint16_t w);
uint16_t makeWord(byte h, byte l);
#define word(...) makeWord(__VA_ARGS__)
unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L);
void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0);
void noTone(uint8_t _pin);
// WMath prototypes
long random(long);
long random(long, long);
void randomSeed(unsigned int);
long map(long, long, long, long, long);
#endif
#endif
Re: Återkommande fel i Arduino-koden.
> ...dom är färdiga exempel, bara att öppna.
Finns dom på någon speciell länk/websida ?
Finns dom på någon speciell länk/websida ?
Re: Återkommande fel i Arduino-koden.
Allt är inte samlat på ett ställe, men det kan vara lämpligt att börja här:
http://arduino.cc/en/Main/Software
Sen finns det massa att läsa och hämta om man går till Arduinos Forum och Playground.
Jag startade med att hämta hem Arduino 0018 osv.
Man måste inte ha en Arduino för att se om det funkar.
Det går bra att compilera (Verify) ändå, utan att överföra till kortet.
http://arduino.cc/en/Main/Software
Sen finns det massa att läsa och hämta om man går till Arduinos Forum och Playground.
Jag startade med att hämta hem Arduino 0018 osv.
Man måste inte ha en Arduino för att se om det funkar.
Det går bra att compilera (Verify) ändå, utan att överföra till kortet.
Re: Återkommande fel i Arduino-koden.
Aha, OK. Det jag menade var att det ofta kan finns instruktioner tillsammans med
exempelkod om det är något speciellt man måste gör innan man "bygger" t.ex...
exempelkod om det är något speciellt man måste gör innan man "bygger" t.ex...
Re: Återkommande fel i Arduino-koden.
Och det finns ingen "get" i det lib. testa därför att ta bort ".get" i källkoden och se vad som händer.
Re: Återkommande fel i Arduino-koden.
Det är C++ dvs inte helt enkelt att börja med, snurrigt som fan rent ut sagt. I alla fall om man inte hållit på med objektorienterat tidigare.
Skulle nog rekommendera att hålla sig till C, det är lite mer raka puckar.
Skulle nog rekommendera att hålla sig till C, det är lite mer raka puckar.