找下问题

2019-07-15 23:15发布

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;
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。