ich habe im formular die rubrik "dateianhang" wohl missverstanden -
deshalb hier die beiden programme:
melodie OHNE interupt
#include <avr\io.h>
#include <avr\interrupt.h>
int main()
{ DDRB = 0xFF; // B ist OutPut
void ton(int freq,int dauer)
{int t=0;int i;int a ;
for (i=0;i<dauer;i++)
{PORTB=t;t++;a=0;while (a<freq){a++;};};
}
while (2==2) {ton(500,1000);ton(250,1000);}
return 1;}
melodie MIT interrupt
#include <avr\io.h>
#include <avr\interrupt.h>
#include <avr/signal.h>
volatile int i=0;
SIGNAL (SIG_TIMER0_OVF){ i++;}
void ton(int freq,int dauer)
{int t=0;int k;
for (k=0;k<dauer;k++)
{PORTB=t;t++;i=0;while (i<freq){};}; }
int main()
{ DDRB = 0xFF; // B ist OutPut
TCCR0B |= (1 << CS02) | (1 << CS00); //Prescaler auf 1024 stellen
TIMSK |= (1 << TOIE0); // Timer 0 Overflow Interrupt
enable
sei(); // Interrupts einschalten
while (2==2) {ton(5,100);ton(2,100);}
return 1;}
bei 12MHz takt ist prescale 1024 ca 12khz, also müsste i auf mindestens
10 hochzählen, damit die pausen zwischen den lautsprecherticks an PORTB0
ungefähr 1200Hz entsprechen - das passt in realität aber nicht, statt
des lautsprechers angeschlossene led blinkt nur träge vor sich hin...
jürgen