heißt glaub ich:
#include <avr/delay.h>
Schau doch einfach mal im Ordner nach. Musst aber noch nen par berechnungen machen, schau mal hier:
http://www.mikrocontroller.net/artic...R-GCC-Tutorial
(such nach delay)
Hallo zusammen,
ich hab ne Frage voll oft taucht in Quelltexten dieser Abschnitt auf
jetzt geht es mir um das _delay_ms(10); in welcher Lib ist die Funktion? Ich hab zuerst an die delay.h gedacht aber da ist sie nicht! Ich poste mal die delay.h weil jemand gesagt hat darin wäre sie!Code:void warte(uint16_t wert){ for (uint16_t zeit=0;zeit<wert;zeit++) { _delay_ms(10); } }
ist diese lib bei euch genauso oder wo gibt es die Funktion _delay_ms(); ?Code:/* Copyright (c) 2002, 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. 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: delay.h,v 1.2.2.2 2004/02/13 21:43:37 joerg_wunsch Exp $ */ /* avr/delay.h - loops for small accurate delays */ #ifndef _AVR_DELAY_H_ #define _AVR_DELAY_H_ 1 #include <inttypes.h> /* 8-bit count, 3 cycles/loop */ static __inline__ void _delay_loop_1(uint8_t __count) { asm volatile ( "1: dec %0" "\n\t" "brne 1b" : "=r" (__count) : "0" (__count) ); } /* 16-bit count, 4 cycles/loop */ static __inline__ void _delay_loop_2(uint16_t __count) { asm volatile ( "1: sbiw %0,1" "\n\t" "brne 1b" : "=w" (__count) : "0" (__count) ); } /* TODO: macros to allow specifying delays directly in microseconds (with MCU clock frequency defined by the user). With constant delays, all floating point math would be done at compile time. */ #endif /* _AVR_DELAY_H_ */
Gruß Michi
heißt glaub ich:
#include <avr/delay.h>
Schau doch einfach mal im Ordner nach. Musst aber noch nen par berechnungen machen, schau mal hier:
http://www.mikrocontroller.net/artic...R-GCC-Tutorial
(such nach delay)
MFG Moritz
www.free-webspace.biz/update
in der delay.h gibt es diese Funktion nicht! Hab ihr diese umgeändert oder woher bekommt ihr die _delay_ms();
Gruß Michi
ich glaube ich meinen Fehler gefunden!
ch hab die avr-lib version 1.0.4 und im AVR-GCC Tutorial steht die Funktion _delay_ms(); gibt es erst ab der Version 1.2.0 !
Ich lad mir mal die neue runter.
Gruß Michi
Hättest du dir mal die Mikrocontroller-Seite angesehen:
#include <avr/delay.h> /* definiert _delay_ms() ab avr-libc Version 1.2.0 */![]()
Ich hab die Funktion auch schon öfter benutzt, es könnte gut sein, dass du noch sowas wie F_CPU definieren musst.
MFG Moritz
www.free-webspace.biz/update
hallo RCO,
ich hab mir die neue Version von WinAVR gedownloadet da gibts die _delay_ms(); Funktion!
Gruß Michi
ich habe in der make die f_cpu und trotzdem stimmt die zeit der _delay nicht, woran liegt das.
bei meiner selbsterstellten srf04-routine müssen us gewartet werden. mit asm-routinen und for geht es, aber mit der_delay nicht.
mfg pebisoftCode:#include <inttypes.h> #include <avr/io.h> #include <avr/interrupt.h> #include <avr/signal.h> #include <string.h> #include <stdint.h> #include <avr/delay.h> #define READ 1 #define WRITE 2 #define USART_BAUD_RATE 19200 #define USART_BAUD_SELECT (F_CPU/(USART_BAUD_RATE*16l)-1) #define MESS_PORT PORTB #define MESS_PORT_RICHTUNG DDRB #define MESS_PIN PINB #define MESS_BIT PB1 // Echo-Trigger Eingang oder einfach Messeingang #define US_PORT PORTB #define US_PORT_RICHTUNG DDRB #define US_BIT PB0 // Der Pin kommt zum Trigger-Puls Eingang void usart_init(int Enable, int Interupts) { if (Enable & READ) UCSRB = (1<<RXEN); if (Enable & WRITE) UCSRB |= (1<<TXEN); if (Interupts & READ) UCSRB |= (1<<RXCIE); if (Interupts & WRITE) UCSRB |= (1<<TXCIE); UBRRL = (unsigned char) USART_BAUD_SELECT; } void usart_writeChar(unsigned char c) { while (!(UCSRA & (1<<UDRE))) {} UDR = c; while(!(UCSRA & (1<<TXC))) {} } void usart_writeString(unsigned char *string) { while (!(UCSRA & (1<<UDRE))) {} while ( *string) usart_writeChar(*string++); } uint16_t start_messung(void) { volatile uint16_t wert,i; wert=0; US_PORT_RICHTUNG|=(1<<US_BIT); // US_PIN auf Ausgang US_PORT|=(1<<US_BIT); // Trigger-Puls auf high for (i=0; i<10; i++) asm volatile("nop"); US_PORT&=~(1<<US_BIT); // Trigger-Puls Eingang wieder auf low for (i=0; i<200; i++) asm volatile("nop"); TCNT1=0; // Timerregister auf 0 TCCR1B|= (1<<CS11); // Timer starten while (MESS_PIN & (1<<MESS_BIT)) // Warten bis Echo/Mess Eingang auf low wert=TCNT1; TCCR1B&= ~(1<<CS11); // Timer wieder aus return wert; } int main (void) { char s[10]; uint16_t wert_1; usart_init( (READ + WRITE) , READ); for (;;) { wert_1=start_messung(); itoa( wert_1, s, 10); usart_writeString(s); usart_writeString("\r"); } }
das mit der Delay stimmt bei mir auch nicht! Ich meine zeitlich!
Wenn ich in meinem Code
_delay_ms(1000); eingebe müsste es doch eine Sekunde warten macht es aber nicht denn es wartet kürzer!
Gruß Michi
Es könnte sicher nicht schaden, bei so einem Problem mal einen kurzen Blick in die Dokumentation zu werfen.Zitat von michealb
Zu _delay_ms gibt es nämlich eine wichtige Anmerkung.
dann raus damit......
ich habe keine vernüftige erklärung dafür gefunden, weil die routine ja aufruf-fertig serviert wird, in _ms und _us.
mfg pebisoft
Lesezeichen