當(dāng)前位置:首頁(yè) > 單片機(jī) > 單片機(jī)
[導(dǎo)讀]//music.h/*音階常數(shù)=65536-8000000/8/2/f*/ #defineDO64580//523 #defineRE64684//587 #defineMI64777//659 #defineFA64820//698 #defineSO64898//784 #defineLA64968//880 #defineTI65030//988 #defineDO_

//music.h

/*音階常數(shù)=65536-8000000/8/2/f*/
#defineDO64580//523
#defineRE64684//587
#defineMI64777//659
#defineFA64820//698
#defineSO64898//784
#defineLA64968//880
#defineTI65030//988
#defineDO_H65058//1046
#defineRE_H65110//1174
#defineMI_H65157//1318
#defineFA_H65178//1397
#defineSO_H65217//1568
#defineLA_H65252//1760
#defineTI_H65283//1976
#defineDO_HH65297//2093
/*位操作宏*/
#defineset_bit(x,y)(x|=(1<#defineclr_bit(x,y)(x&=~(1<#defineget_bit(x,y)(x&(1<


//music.c
/*目標(biāo)MCU:MEGA8晶振:外部(EXT)8MHZ*/
//使用說(shuō)明:音樂(lè)輸出端口:PORTC.0,音樂(lè)數(shù)據(jù)存放
//于ATMEGA8的EEPROM存貯器中,可以使用music.exe
//程序通過(guò)RS232通信口進(jìn)行修改。
//#include
//#include
//#include
#include
#include
#include
#include
#include
#include
#include

#include"music.h"

//externvoiduart_init(void);
//externvoidisp(void);

/*-------------------------------------------------------------------------------*/
#define__noinit____attribute__((section(".noinit")))//變量不初始化
#define__eeprom____attribute__((section(".eeprom")))//變量定義在eeprom中

#define__flash__PROGMEM//變量定義在flash中(寫(xiě)法1)
//#define__flash____attribute__((section(".progmem")))//變量定義在flash中(寫(xiě)法2)
//#define__flash____attribute__((progmem))//變量定義在flash中(寫(xiě)法3)
//prg_uchar等

#definepersistent__noinit__//變量不初始化,相當(dāng)于PICC的persistent
#definecodePROGMEM//同__flash__,變量定義在flash中,相當(dāng)于KeilC51的code
/*-------------------------------------------------------------------------------*/

/*音樂(lè)數(shù)據(jù)(卡秒莎)*/
/*四分之一拍為0x10,二分之一拍為0x20,一拍為0x40*/
/*低1-12-23-34-45-56-67-7*/
/*中1-82-93-A4-B5-C6-D7-E*/
/*高1-F*/
//#pragmadata:eeprom

/*
const__eeprom__unsignedcharsound[]={//正常節(jié)奏
//LATIDO_HLADO_HDO_HTILATIMI
0x66,0x27,0x68,0x26,0x28,0x28,0x27,0x26,0x47,0x43,
//TIDO_HRE_HTIRE_HRE_HDO_HTILALA
0x67,0x28,0x69,0x27,0x29,0x29,0x28,0x27,0x46,0x46,
0x4a,0x4d,0x4c,0x2d,0x2c,0x2b,0x2b,0x2a,0x29,0x4a,
0x46,0x20,0x4b,0x29,0x6a,0x28,0x27,0x23,0x28,0x27,
0x46,0x46,0x4a,0x4d,0x4c,0x2d,0x2c,0x2b,0x2b,0x2a,
0x29,0x4a,0x46,0x20,0x4b,0x29,0x6a,0x28,0x27,0x23,
0x28,0x27,0x46,0x46,0x00
};
*/

const__eeprom__unsignedcharsound[]={//全短音
//LATIDO_HLADO_HDO_HTILATIMI
0x26,0x27,0x28,0x26,0x28,0x28,0x27,0x26,0x27,0x23,
//TIDO_HRE_HTIRE_HRE_HDO_HTILALA
0x67,0x28,0x29,0x27,0x29,0x29,0x28,0x27,0x26,0x26,
0x2a,0x2d,0x2c,0x2d,0x2c,0x2b,0x2b,0x2a,0x29,0x2a,
0x26,0x20,0x2b,0x29,0x2a,0x28,0x27,0x23,0x28,0x27,
0x26,0x26,0x2a,0x2d,0x2c,0x2d,0x2c,0x2b,0x2b,0x2a,
0x29,0x2a,0x26,0x20,0x2b,0x29,0x2a,0x28,0x27,0x23,
0x28,0x27,0x26,0x26,0x00
};

/*
const__eeprom__unsignedcharsound[]={//全長(zhǎng)音
//LATIDO_HLADO_HDO_HTILATIMI
0x66,0x67,0x68,0x66,0x68,0x68,0x67,0x66,0x67,0x63,
//TIDO_HRE_HTIRE_HRE_HDO_HTILALA
0x67,0x68,0x69,0x67,0x69,0x69,0x68,0x67,0x66,0x66,
0x6a,0x6d,0x6c,0x6d,0x6c,0x6b,0x6b,0x6a,0x69,0x6a,
0x66,0x60,0x6b,0x69,0x6a,0x68,0x67,0x63,0x68,0x67,
0x66,0x66,0x6a,0x6d,0x6c,0x6d,0x6c,0x6b,0x6b,0x6a,
0x69,0x6a,0x66,0x60,0x6b,0x69,0x6a,0x68,0x67,0x63,
0x68,0x67,0x66,0x66,0x00
};
*/
/*
const__eeprom__unsignedcharsound[]={//全低音
//LATIDO_HLADO_HDO_HTILATIMI
0x66,0x27,0x61,0x26,0x21,0x21,0x27,0x26,0x47,0x43,
//TIDO_HRE_HTIRE_HRE_HDO_HTILALA
0x67,0x21,0x62,0x27,0x22,0x22,0x21,0x27,0x46,0x46,
0x43,0x46,0x45,0x26,0x25,0x24,0x24,0x23,0x22,0x43,
0x46,0x20,0x44,0x22,0x63,0x21,0x27,0x23,0x21,0x27,
0x46,0x46,0x43,0x46,0x45,0x26,0x25,0x24,0x24,0x23,
0x22,0x41,0x46,0x20,0x44,0x22,0x63,0x21,0x27,0x23,
0x21,0x27,0x46,0x46,0x00
};
*/

//#pragmadata:data
/*音階表*/
constunsignedintTONETABLE[15]={DO,RE,MI,FA,SO,LA,TI,DO_H,
RE_H,MI_H,FA_H,SO_H,LA_H,TI_H,DO_HH};
/*音階重裝常數(shù)*/
unsignedinttoneconst;
/*微秒級(jí)延時(shí)程序*/
voiddelay_us(inttime)
{
do
{
time--;
}
while(time>1);
}
/*毫秒級(jí)延時(shí)程序*/
voiddelay_ms(unsignedinttime)
{
while(time!=0)
{
delay_us(1000);
time--;
}
}
//#pragmainterrupt_handlertimer1_ovf_isr:iv_TIMER1_OVF
//voidtimer1_ovf_isr(void)
SIGNAL(SIG_OVERFLOW1)
{
TCNT1=toneconst;
//PORTC^=1;
PORTC^=(1<}
voidmusic(void)
{
unsignedchartemp,temp1;
unsignedintsound_add=0;
TCCR1A=0x00;
TCCR1B=(1<//temp1=EEPROMread((int)&sound[sound_add]);
//temp1=eeprom_read_byte(sound[sound_add]);
temp1=eeprom_read_byte(sound+sound_add);
while(temp1!=0)//0為音樂(lè)結(jié)尾符
{
temp=temp1;
temp&=0x0f;//取低四位選擇音調(diào)頻率
if(temp!=0)
{
TIMSK|=(1<temp--;
toneconst=TONETABLE[temp];//取選擇音調(diào)頻率
TCNT1=toneconst;//發(fā)聲定時(shí)開(kāi)始
}
temp=temp1;
temp>>=4;//取高四位
//temp&=0x0f;//廢話!!!
//delay_ms(temp*129);//根據(jù)SOUNDTABLE中數(shù)據(jù)的高四位*5后,為音調(diào)持續(xù)時(shí)間(等待)
delay_ms(temp*138);//根據(jù)SOUNDTABLE中數(shù)據(jù)的高四位*5后,為音調(diào)持續(xù)時(shí)間(等待138mS較好些)
TIMSK&=~(1<sound_add++;//樂(lè)譜音符指針+1
//temp1=EEPROMread((int)&sound[sound_add]);
//temp1=eeprom_read_byte(sound[sound_add]);
temp1=eeprom_read_byte(sound+sound_add);//取一個(gè)音符或結(jié)尾符
}
delay_ms(1000);
}
/*主程序*/
voidmain(void)
{
DDRC=0x01;
PORTC=0xff;
//uart_init();
sei();
while(1)
{
music();
}
}

本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請(qǐng)聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請(qǐng)及時(shí)聯(lián)系本站刪除。
換一批
延伸閱讀

9月2日消息,不造車(chē)的華為或?qū)⒋呱龈蟮莫?dú)角獸公司,隨著阿維塔和賽力斯的入局,華為引望愈發(fā)顯得引人矚目。

關(guān)鍵字: 阿維塔 塞力斯 華為

倫敦2024年8月29日 /美通社/ -- 英國(guó)汽車(chē)技術(shù)公司SODA.Auto推出其旗艦產(chǎn)品SODA V,這是全球首款涵蓋汽車(chē)工程師從創(chuàng)意到認(rèn)證的所有需求的工具,可用于創(chuàng)建軟件定義汽車(chē)。 SODA V工具的開(kāi)發(fā)耗時(shí)1.5...

關(guān)鍵字: 汽車(chē) 人工智能 智能驅(qū)動(dòng) BSP

北京2024年8月28日 /美通社/ -- 越來(lái)越多用戶希望企業(yè)業(yè)務(wù)能7×24不間斷運(yùn)行,同時(shí)企業(yè)卻面臨越來(lái)越多業(yè)務(wù)中斷的風(fēng)險(xiǎn),如企業(yè)系統(tǒng)復(fù)雜性的增加,頻繁的功能更新和發(fā)布等。如何確保業(yè)務(wù)連續(xù)性,提升韌性,成...

關(guān)鍵字: 亞馬遜 解密 控制平面 BSP

8月30日消息,據(jù)媒體報(bào)道,騰訊和網(wǎng)易近期正在縮減他們對(duì)日本游戲市場(chǎng)的投資。

關(guān)鍵字: 騰訊 編碼器 CPU

8月28日消息,今天上午,2024中國(guó)國(guó)際大數(shù)據(jù)產(chǎn)業(yè)博覽會(huì)開(kāi)幕式在貴陽(yáng)舉行,華為董事、質(zhì)量流程IT總裁陶景文發(fā)表了演講。

關(guān)鍵字: 華為 12nm EDA 半導(dǎo)體

8月28日消息,在2024中國(guó)國(guó)際大數(shù)據(jù)產(chǎn)業(yè)博覽會(huì)上,華為常務(wù)董事、華為云CEO張平安發(fā)表演講稱,數(shù)字世界的話語(yǔ)權(quán)最終是由生態(tài)的繁榮決定的。

關(guān)鍵字: 華為 12nm 手機(jī) 衛(wèi)星通信

要點(diǎn): 有效應(yīng)對(duì)環(huán)境變化,經(jīng)營(yíng)業(yè)績(jī)穩(wěn)中有升 落實(shí)提質(zhì)增效舉措,毛利潤(rùn)率延續(xù)升勢(shì) 戰(zhàn)略布局成效顯著,戰(zhàn)新業(yè)務(wù)引領(lǐng)增長(zhǎng) 以科技創(chuàng)新為引領(lǐng),提升企業(yè)核心競(jìng)爭(zhēng)力 堅(jiān)持高質(zhì)量發(fā)展策略,塑強(qiáng)核心競(jìng)爭(zhēng)優(yōu)勢(shì)...

關(guān)鍵字: 通信 BSP 電信運(yùn)營(yíng)商 數(shù)字經(jīng)濟(jì)

北京2024年8月27日 /美通社/ -- 8月21日,由中央廣播電視總臺(tái)與中國(guó)電影電視技術(shù)學(xué)會(huì)聯(lián)合牽頭組建的NVI技術(shù)創(chuàng)新聯(lián)盟在BIRTV2024超高清全產(chǎn)業(yè)鏈發(fā)展研討會(huì)上宣布正式成立。 活動(dòng)現(xiàn)場(chǎng) NVI技術(shù)創(chuàng)新聯(lián)...

關(guān)鍵字: VI 傳輸協(xié)議 音頻 BSP

北京2024年8月27日 /美通社/ -- 在8月23日舉辦的2024年長(zhǎng)三角生態(tài)綠色一體化發(fā)展示范區(qū)聯(lián)合招商會(huì)上,軟通動(dòng)力信息技術(shù)(集團(tuán))股份有限公司(以下簡(jiǎn)稱"軟通動(dòng)力")與長(zhǎng)三角投資(上海)有限...

關(guān)鍵字: BSP 信息技術(shù)
關(guān)閉
關(guān)閉