找下问题
时间:10-02
整理:3721RD
点击:
include <string.h>
#include <macros.h>
#include <stdio.h>
#include <iom128v.h>
#include <delay.h>
#pragma interrupt_handler TIMER0_ISR:iv_TIM0_OVF
#pragma interrupt_handler TIMER1_ISR:iv_TIM1_COMPA
const unsigned int music_data[][2]=
{
{440,600},{494,200},{523,600},{440,200},
{523,400},{494,200},{440,200},{494,400},
{330,400},{494,600},{523,200},{578,600}
};
#pragma data:data
unsigned int delay=0;
void music_init()
{
MCUCR=0x00;
DDRC=0x01;
TCCR1A=0x00;
TCCR1B=0x09;
TCCR0=0x03;
TCNT0=0x19;
TIMSK=(1<<OCIE1A)|(1<<TOIE0);
}
void timer0()
{
delay++;
TCNT0=0x19;
}
void timer1()
{
PORTC^=0x01;
}
void sound(unsigned int x,unsigned int y)
{
SEI();
delay=0;
if(x!=0)
{
x=4000000/x;
OCR1A=x;
TCNT1=0x00;
TIMSK|=(1<<OCIE1A);
while(delay<y);
TIMSK&=~(1<<OCIE1A);
}
else
{
TIMSK&=~(1<<OCIE1A);
while(delay<y);
}
CLI();
}
void main()
{
unsigned char i=0;
music_init();
while(1)
{
while(music_data[1]!=0)
{
sound(music_data[0],music_data[1]);
i++;
}
i=0;
}
}
#include <macros.h>
#include <stdio.h>
#include <iom128v.h>
#include <delay.h>
#pragma interrupt_handler TIMER0_ISR:iv_TIM0_OVF
#pragma interrupt_handler TIMER1_ISR:iv_TIM1_COMPA
const unsigned int music_data[][2]=
{
{440,600},{494,200},{523,600},{440,200},
{523,400},{494,200},{440,200},{494,400},
{330,400},{494,600},{523,200},{578,600}
};
#pragma data:data
unsigned int delay=0;
void music_init()
{
MCUCR=0x00;
DDRC=0x01;
TCCR1A=0x00;
TCCR1B=0x09;
TCCR0=0x03;
TCNT0=0x19;
TIMSK=(1<<OCIE1A)|(1<<TOIE0);
}
void timer0()
{
delay++;
TCNT0=0x19;
}
void timer1()
{
PORTC^=0x01;
}
void sound(unsigned int x,unsigned int y)
{
SEI();
delay=0;
if(x!=0)
{
x=4000000/x;
OCR1A=x;
TCNT1=0x00;
TIMSK|=(1<<OCIE1A);
while(delay<y);
TIMSK&=~(1<<OCIE1A);
}
else
{
TIMSK&=~(1<<OCIE1A);
while(delay<y);
}
CLI();
}
void main()
{
unsigned char i=0;
music_init();
while(1)
{
while(music_data[1]!=0)
{
sound(music_data[0],music_data[1]);
i++;
}
i=0;
}
}
这是自己改改的程序。改用avr128的。用ICC编.....