关于用ARM的蜂鸣器播放音乐的功能实现
时间:10-02
整理:3721RD
点击:
最近初涉ARM,遇到一个问题,附上一小段代码如下
if (0x2000 + rBCDYEAR == rBCDYEAR2 && rBCDMON == rBCDMON2
&& rBCDDATE == rBCDDATE2 && rBCDHOUR == rBCDHOUR2 &&
rBCDMIN == rBCDMIN2 && rBCDSEC == rBCDSEC2)
{
//U16 freq = 800;
// Buzzer_Freq_Set(freq);
Temp11=SONG1[Addr++];
Temp21=SONG1[Addr++];
/* if (Temp1==0)
{
rGPBCON &= ~3; //set GPB0 as output
rGPBCON |= 1; //结束,跳出循环
rGPBDAT &= ~1;
break;
}*/
switch ( Temp1) {
case 01: freq=260; break;
case 02: freq=294; break;
case 03: freq=328; break;
case 04: freq=347; break;
case 05: freq=390; break;
case 06: freq=438; break;
case 07: freq=490; break;
case 11: freq=520; break;
case 12: freq=581; break;
case 13: freq=657; break;
case 14: freq=694; break;
case 15: freq=781; break;
case 16: freq=892; break;
case 17: freq=1000; break;
case 21: freq=1041; break;
case 22: freq=1190; break;
case 23: freq=1315; break;
case 24: freq=1388; break;
case 25: freq=1562; break;
case 26: freq=1785; break;
case 27: freq=1923; break;
default: freq='e';break;
//set GPB0 as output
//休止符关蜂鸣器
//这里用了goto,赶时间,没有大调整
}
Buzzer_Freq_Set( freq );
Uart_Printf("freq=%d,",freq);
Delay(192*Temp2);
if(Addr>187) { Addr=0;}//440,此为数字数据个数
} //闹钟检查2
其中rBCDYEAR2等变量是随时变化的(代表时间年-月-日 时-分-秒),当到达一个时间点时,播放音乐
但是现在的这段程序实现的是当到达指定时间点时只能播放第一个频率,不能循环下去播放其他的频率,因为时间是实时改变的,所以想请教一下我该怎么写循环才能播放完整的音乐【我试了while(1)和for(),没成功】
if (0x2000 + rBCDYEAR == rBCDYEAR2 && rBCDMON == rBCDMON2
&& rBCDDATE == rBCDDATE2 && rBCDHOUR == rBCDHOUR2 &&
rBCDMIN == rBCDMIN2 && rBCDSEC == rBCDSEC2)
{
//U16 freq = 800;
// Buzzer_Freq_Set(freq);
Temp11=SONG1[Addr++];
Temp21=SONG1[Addr++];
/* if (Temp1==0)
{
rGPBCON &= ~3; //set GPB0 as output
rGPBCON |= 1; //结束,跳出循环
rGPBDAT &= ~1;
break;
}*/
switch ( Temp1) {
case 01: freq=260; break;
case 02: freq=294; break;
case 03: freq=328; break;
case 04: freq=347; break;
case 05: freq=390; break;
case 06: freq=438; break;
case 07: freq=490; break;
case 11: freq=520; break;
case 12: freq=581; break;
case 13: freq=657; break;
case 14: freq=694; break;
case 15: freq=781; break;
case 16: freq=892; break;
case 17: freq=1000; break;
case 21: freq=1041; break;
case 22: freq=1190; break;
case 23: freq=1315; break;
case 24: freq=1388; break;
case 25: freq=1562; break;
case 26: freq=1785; break;
case 27: freq=1923; break;
default: freq='e';break;
//set GPB0 as output
//休止符关蜂鸣器
//这里用了goto,赶时间,没有大调整
}
Buzzer_Freq_Set( freq );
Uart_Printf("freq=%d,",freq);
Delay(192*Temp2);
if(Addr>187) { Addr=0;}//440,此为数字数据个数
} //闹钟检查2
其中rBCDYEAR2等变量是随时变化的(代表时间年-月-日 时-分-秒),当到达一个时间点时,播放音乐
但是现在的这段程序实现的是当到达指定时间点时只能播放第一个频率,不能循环下去播放其他的频率,因为时间是实时改变的,所以想请教一下我该怎么写循环才能播放完整的音乐【我试了while(1)和for(),没成功】
这是裸机程序,通过蜂鸣器发出声音
问题解决了,麻烦大家了,谢谢~~~