|
#include
#include
#define F_CPU 7372800 // 單片機(jī)主頻為7.3728MHz,用于延時(shí)子程序和計(jì)算定時(shí)器初始值
#include
#include
#include
#include //中斷信號(hào)頭文件
//***********************************************************************
// 定義變量區(qū)
//***********************************************************************
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
#define Data_IO PORTB //音頻輸出口
#define Data_DDR DDRB
uint t[9]={0,956,865,759,716,638,568,506,470};
uint d[9]={0,105,116,132,140,157,176,198,209};
uchar music[]={5,2,8,2,5,2,4,2,3,2,2,2,1,4,1,2,1,2,2,2,3,2,3,2,1,2,3,2,4,2,5,8};
uchar note_n;
uint int_n;
uint play_on;
//***********************************************************************
// 程序初始化
//***********************************************************************
void system_init()
{
Data_IO=0x20; //數(shù)據(jù)口為輸出
Data_DDR=0xFF;
}
//*************************************************************************
// 定時(shí)器1初始化子程序
//*************************************************************************
void timer1_init() //定時(shí)器初始化
{
TCCR1A=0x40; //定時(shí)器工作方式
TCCR1B=0x11;
TIFR=0x10; //清中斷標(biāo)志位
TIMSK=0x10; //使能定時(shí)器0溢出中斷
}
//*************************************************************************
// 定時(shí)器1中斷服務(wù)子程序
//*************************************************************************
ISR(SIG_OUTPUT_COMPARE1A) //中斷服務(wù)程序
{
if(!play_on) //是否播放完
{
note_n=0;
int_n=1;
play_on=1;
}
else
{
if(--int_n==0)
{
TCCR1B=0X10;
if(note_n<32)
{
ocr1a="t[music[note_n]];
" int_n="d[music[note_n]];
" note_n++;
int_n="int_n*music[note_n];
" note_n++;
tccr1b="0x11;
}
else
play_on=0;
} "
}
//*************************************************************************
// 主程序
//*************************************************************************
int main(void)
{
system_init(); //系統(tǒng)初始化
timer1_init(); //定時(shí)器0初始化,完成定時(shí)器相關(guān)配置
SREG|=0x80; //開啟全局中斷
while(1)
{
}
}
捕獲.png (57.33 KB, 下載次數(shù): 157)
下載附件
2012-10-22 09:36 上傳
|
|