精品国产人成在线_亚洲高清无码在线观看_国产在线视频国产永久2021_国产AV综合第一页一个的一区免费影院黑人_最近中文字幕MV高清在线视频

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學習在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會員中心
創(chuàng)作中心

完善資料讓更多小伙伴認識你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

基于AT89C2051做的音樂門鈴 附程序

454398 ? 作者:工程師吳畏 ? 2018-09-21 09:12 ? 次閱讀

家里門鈴壞了一個多月了,一直沒有時間去搞,過年前幾天剛好有點時間,拆出來看看發(fā)現(xiàn)由于電池漏液造成了電路板多處被腐蝕,修也是麻煩了,所以索性就自己重新設(shè)計一個出來。這個門鈴從電路設(shè)計,程序設(shè)計,調(diào)試及焊接都是我自己一手一腳完成,前后一共大概用了2天半時間。做出來的效果還是不錯的。大家有興趣可以試一下。

為了使門鈴更有個性化,我采用的是單片機,用單片機來產(chǎn)生所需要的響聲。其電路原理是控制單片機的IO口產(chǎn)生適當頻率的方波,經(jīng)過三極管放大后驅(qū)動自藕變壓器的一次測,這時在變壓器的二次測會產(chǎn)生相同頻率的高壓方波從而使壓電陶瓷片發(fā)生形變,發(fā)出較大的門鈴聲。電源使用的是4節(jié)干電池,共6V,單片機電源是6V電源通過二極管降壓0.7V后提供。

程序的原理就是通過控制單片機的計時器T1和T2來產(chǎn)生不同頻率的PWM波,然后通過定義一個歌曲的數(shù)組,來控制不同音調(diào),音高,音長,音高,音長。以下是曲譜的儲存格式:

曲譜存貯格式 unsigned char code MusicName{音高,音長,音高,音長。..。, 0,0}; 末尾:0,0 表示結(jié)束(Important)

音高由三位數(shù)字組成:

個位是表示 1~7 這七個音符

十位是表示音符所在的音區(qū):1-低音,2-中音,3-高音;

百位表示這個音符是否要升半音: 0-不升,1-升半音。

音長最多由三位數(shù)字組成:

個位表示音符的時值,其對應(yīng)關(guān)系是:

|數(shù)值(n): |0 |1 |2 |3 | 4 | 5 | 6

|幾分音符: |1 |2 |4 |8 |16 |32 |64 音符=2^n

十位表示音符的演奏效果(0-2): 0-普通,1-連音,2-頓音

百位是符點位: 0-無符點,1-有符點

調(diào)用演奏子程序的格式

Play(樂曲名,調(diào)號,升降八度,演奏速度);

|樂曲名 : 要播放的樂曲指針,結(jié)尾以(0,0)結(jié)束;

|調(diào)號(0-11) : 是指樂曲升多少個半音演奏;

|升降八度(1-3) : 1:降八度, 2:不升不降, 3:升八度;

|演奏速度(1-12000): 值越大速度越快;

由于門鈴在沒有按下時候CPU是沒有工作任務(wù)的,所以在沒有按下門鈴時,我令CPU進入休眠狀態(tài),這樣能夠省下不少的電,使電池的工作壽命延長。當有人按下門鈴時,就會產(chǎn)生外部中斷INT0,使CPU退出休眠狀態(tài),進入全速運行狀態(tài),當歌曲演奏完畢,重新自動進入休眠狀態(tài)。下面是主程序和中斷服務(wù)程序

void main()

{

IT0=1; //外中斷跳變產(chǎn)生中斷

EX0=1;

EA=1; //打開總中斷

InitialSound();

PCON |= 0x01;

while(1)

{

if(Play_music==1)

{

P1_7=0;

Play(Music_happynewyear,0,3,360);

P1_7=1;

Delay1ms(1500);

P1_7=0;

Play(Music_yingchun,0,3,360);

P1_7=1;

Play_music=0;

PCON |= 0x01;

}

}

}

void int0() interrupt 0 using 1

{

PCON &=~ 0x00;

Play_music=1;

}

電路原理圖

由于當時快要過年了,所以我編了一首“新年好”和“迎春花”應(yīng)一下節(jié),其實所有歌都可以寫,只要有樂譜就可以,這樣你就可以把自己喜歡的歌編成程序燒入芯片,打造個性化的音樂門鈴。下面我給出一些歌的編碼,由于2051里面的flash容量有限,通常只能裝下2首歌,所以如果想換歌時又要自己重新把代碼替換燒入芯片。

//新年好

unsigned char code Music_happynewyear[]={ 0x15,0x03, 0x15,0x03, 0x15,0x02, 0x0F,0x02, 0x17,0x03,0x17,0x03, 0x17,0x02, 0x15,0x02, 0x15,0x03, 0x17,0x03,0x19,0x02,0x19,0x02, 0x18,0x03,0x17,0x03,0x16,0x01,0x16,0x03,0x17,0x03,0x18,0x02,0x18,0x02,0x17,0x03,0x16,0x03, 0x17,0x02, 0x15,0x02, 0x15,0x03, 0x17,0x03, 0x16,0x02, 0x0F,0x02, 0x11,0x03, 0x16,0x03, 0x15,0x01, 0x00,0x00 };

//迎春花

unsigned char code Music_yingchun[]={ 0x1F,0x03, 0x1F,0x04, 0x1A,0x04, 0x20,0x04, 0x1F,0x04, 0x1A,0x03, 0x19,0x03, 0x19,0x04, 0x17,0x04, 0x1A,0x04, 0x19,0x04, 0x17,0x03, 0x20,0x04, 0x1F,0x04, 0x1B,0x04, 0x1A,0x04, 0x19,0x04, 0x18,0x04, 0x17,0x04, 0x16,0x04,

0x15,0x03, 0x17,0x04, 0x19,0x04, 0x1A,0x04, 0x1A,0x04,0x1A,0x04, 0x1A,0x04, 0x1A,0x03, 0x19,0x03, 0x1A,0x03,0x19,0x03, 0x1A,0x03, 0x1F,0x03, 0x1A,0x03, 0x19,0x03, 0x19,0x03, 0x17,0x02, 0x16,0x03, 0x17,0x01, 0x17,0x67, 0x19,0x04, 0x1A,0x03, 0x1F,0x03, 0x19,0x02, 0x19,0x03, 0x17,0x03, 0x16,0x67, 0x17,0x04, 0x16,0x03, 0x15,0x03,0x15,0x03, 0x10,0x02, 0x0F,0x03,0x10,0x01,0x10,0x01,0x17,0x03,0x19,0x03,0x17,0x67,0x16,0x04,0x17,0x03,0x19,0x03, 0x17,0x67, 0x16,0x04, 0x17,0x03, 0x19,0x03,0x19,0x03, 0x10,0x03, 0x15,0x01, 0x17,0x03, 0x1F,0x03, 0x1A,0x67, 0x19,0x04, 0x17,0x03, 0x1F,0x03, 0x1A,0x67, 0x19,0x04, 0x1F,0x67, 0x1F,0x04, 0x20,0x04, 0x1F,0x04, 0x1A,0x03, 0x19,0x01, 0x19,0x03, 0x1A,0x03, 0x19,0x03, 0x17,0x04, 0x16,0x04, 0x19,0x03, 0x10,0x03, 0x15,0x17, 0x1F,0x03, 0x1F,0x02, 0x1A,0x04, 0x19,0x04, 0x1A,0x03, 0x1F,0x03, 0x17,0x17, 0x17,0x67, 0x19,0x04, 0x1A,0x03,0x1F,0x03, 0x19,0x02, 0x19,0x67, 0x17,0x04, 0x16,0x67,0x17,0x04, 0x16,0x03, 0x15,0x03, 0x15,0x03, 0x10,0x02, 0x0F,0x03, 0x10,0x01, 0x00,0x00 };

//揮著翅膀的女孩

unsigned char code Music_Girl[]={ 0x17,0x02, 0x17,0x03, 0x18,0x03, 0x19,0x02, 0x15,0x03,

0x16,0x03, 0x17,0x03, 0x17,0x03, 0x17,0x03, 0x18,0x03,0x19,0x02, 0x16,0x03, 0x17,0x03, 0x18,0x02, 0x18,0x03, 0x17,0x03, 0x15,0x02, 0x18,0x03, 0x17,0x03, 0x18,0x02,0x10,0x03, 0x15,0x03, 0x16,0x02, 0x15,0x03, 0x16,0x03,0x17,0x02, 0x17,0x03, 0x18,0x03, 0x19,0x02, 0x1A,0x03, 0x1B,0x03, 0x1F,0x03, 0x1F,0x03, 0x17,0x03, 0x18,0x03,0x19,0x02, 0x16,0x03, 0x17,0x03, 0x18,0x03, 0x17,0x03, 0x18,0x03, 0x1F,0x03, 0x1F,0x02, 0x16,0x03, 0x17,0x03, 0x18,0x03, 0x17,0x03, 0x18,0x03, 0x20,0x03, 0x20,0x02, 0x1F,0x03, 0x1B,0x03, 0x1F,0x66, 0x20,0x03, 0x21,0x03, 0x20,0x03, 0x1F,0x03, 0x1B,0x03, 0x1F,0x66, 0x1F,0x03, 0x1B,0x03, 0x19,0x03, 0x19,0x03, 0x15,0x03, 0x1A,0x66, 0x1A,0x03, 0x19,0x03, 0x15,0x03, 0x15,0x03, 0x17,0x03, 0x16,0x66, 0x17,0x04, 0x18,0x04, 0x18,0x03, 0x19,0x03,0x1F,0x03, 0x1B,0x03, 0x1F,0x66,0x20,0x03,0x21,0x03,0x20,0x03,0x1F,0x03,0x1B,0x03,0x1F,0x66,0x1F,0x03,0x1B,0x03, 0x19,0x03, 0x19,0x03, 0x15,0x03, 0x1A,0x66,0x1A,0x03, 0x19,0x03, 0x19,0x03, 0x1F,0x03, 0x1B,0x03, 0x1F,0x00, 0x1A,0x03, 0x1A,0x03, 0x1A,0x03, 0x1B,0x03,0x1B,0x03, 0x1A,0x03, 0x19,0x03, 0x19,0x02, 0x17,0x03,0x15,0x17, 0x15,0x03, 0x16,0x03, 0x17,0x03, 0x18,0x03,

0x17,0x04, 0x18,0x0E, 0x18,0x03, 0x17,0x04, 0x18,0x0E,0x18,0x66, 0x17,0x03, 0x18,0x03, 0x17,0x03, 0x18,0x03, 0x20,0x03, 0x20,0x02, 0x1F,0x03, 0x1B,0x03, 0x1F,0x66,0x20,0x03, 0x21,0x03, 0x20,0x03, 0x1F,0x03, 0x1B,0x03,0x1F,0x66, 0x1F,0x04, 0x1B,0x0E, 0x1B,0x03, 0x19,0x03,0x19,0x03, 0x15,0x03, 0x1A,0x66, 0x1A,0x03, 0x19,0x03, 0x15,0x03, 0x15,0x03, 0x17,0x03,0x16,0x66,0x17,0x04,0x18,0x04,0x18,0x03,0x19,0x03,0x1F,0x03,0x1B,0x03,0x1F,0x66, 0x20,0x03, 0x21,0x03, 0x20,0x03, 0x1F,0x03, 0x1B,0x03, 0x1F,0x66, 0x1F,0x03, 0x1B,0x03, 0x19,0x03, 0x19,0x03, 0x15,0x03, 0x1A,0x66, 0x1A,0x03, 0x19,0x03, 0x19,0x03, 0x1F,0x03, 0x1B,0x03, 0x1F,0x00, 0x18,0x02, 0x18,0x03, 0x1A,0x03, 0x19,0x0D, 0x15,0x03, 0x15,0x02,0x18,0x66, 0x16,0x02, 0x17,0x02, 0x15,0x00, 0x00,0x00};

//同一首歌

unsigned char code Music_Same[]={ 0x0F,0x01, 0x15,0x02, 0x16,0x02, 0x17,0x66, 0x18,0x03,

0x17,0x02, 0x15,0x02, 0x16,0x01, 0x15,0x02, 0x10,0x02,0x15,0x00, 0x0F,0x01, 0x15,0x02, 0x16,0x02, 0x17,0x02, 0x17,0x03, 0x18,0x03, 0x19,0x02, 0x15,0x02, 0x18,0x66, 0x17,0x03, 0x19,0x02, 0x16,0x03, 0x17,0x03, 0x16,0x00, 0x17,0x01, 0x19,0x02, 0x1B,0x02, 0x1B,0x70, 0x1A,0x03, 0x1A,0x01, 0x19,0x02, 0x19,0x03, 0x1A,0x03, 0x1B,0x02, 0x1A,0x0D, 0x19,0x03, 0x17,0x00,0x18,0x66,0x18,0x03,0x19,0x02,0x1A,0x02,0x19,0x0C,0x18,0x0D,0x17,0x03,0x16,0x01, 0x11,0x02, 0x11,0x03, 0x10,0x03, 0x0F,0x0C,0x10,0x02, 0x15,0x00, 0x1F,0x01, 0x1A,0x01, 0x18,0x66, 0x19,0x03, 0x1A,0x01, 0x1B,0x02, 0x1B,0x03, 0x1B,0x03,0x1B,0x0C, 0x1A,0x0D, 0x19,0x03,0x17,0x00,0x1F,0x01,0x1A,0x01,0x18,0x66,0x19,0x03,0x1A,0x01,0x10,0x02,0x10,0x03, 0x10,0x03, 0x1A,0x0C, 0x18,0x0D, 0x17,0x03,0x16,0x00, 0x0F,0x01, 0x15,0x02, 0x16,0x02, 0x17,0x70, 0x18,0x03, 0x17,0x02, 0x15,0x03, 0x15,0x03, 0x16,0x66, 0x16,0x03, 0x16,0x02, 0x16,0x03, 0x15,0x03, 0x10,0x02, 0x10,0x01, 0x11,0x01, 0x11,0x66, 0x10,0x03, 0x0F,0x0C, 0x1A,0x02, 0x19,0x02, 0x16,0x03, 0x16,0x03, 0x18,0x66,0x18,0x03, 0x18,0x02, 0x17,0x03, 0x16,0x03, 0x19,0x00, 0x00,0x00 };

//兩只蝴蝶

unsigned char code Music_Two[] ={ 0x17,0x03, 0x16,0x03, 0x17,0x01, 0x16,0x03, 0x17,0x03,

0x16,0x03, 0x15,0x01, 0x10,0x03, 0x15,0x03, 0x16,0x02, 0x16,0x0D, 0x17,0x03, 0x16,0x03, 0x15,0x03, 0x10,0x03, 0x10,0x0E, 0x15,0x04, 0x0F,0x01, 0x17,0x03, 0x16,0x03,0x17,0x01, 0x16,0x03, 0x17,0x03, 0x16,0x03, 0x15,0x01, 0x10,0x03, 0x15,0x03, 0x16,0x02, 0x16,0x0D, 0x17,0x03, 0x16,0x03, 0x15,0x03, 0x10,0x03, 0x15,0x03, 0x16,0x01, 0x17,0x03, 0x16,0x03, 0x17,0x01, 0x16,0x03, 0x17,0x03, 0x16,0x03, 0x15,0x01, 0x10,0x03, 0x15,0x03, 0x16,0x02, 0x16,0x0D, 0x17,0x03, 0x16,0x03, 0x15,0x03, 0x10,0x03, 0x10,0x0E, 0x15,0x04, 0x0F,0x01, 0x17,0x03, 0x19,0x03, 0x19,0x01, 0x19,0x03, 0x1A,0x03, 0x19,0x03, 0x17,0x01, 0x16,0x03, 0x16,0x03, 0x16,0x02, 0x16,0x0D, 0x17,0x03, 0x16,0x03, 0x15,0x03, 0x10,0x03, 0x10,0x0D, 0x15,0x00, 0x19,0x03, 0x19,0x03, 0x1A,0x03, 0x1F,0x03, 0x1B,0x03, 0x1B,0x03, 0x1A,0x03, 0x17,0x0D,0x16,0x03,0x16,0x03,0x16,0x0D,0x17,0x01,0x17,0x03,0x17,0x03,0x19,0x03,0x1A,0x02,0x1A,0x02,0x10,0x03, 0x17,0x0D, 0x16,0x03, 0x16,0x01, 0x17,0x03, 0x19,0x03, 0x19,0x03, 0x17,0x03, 0x19,0x02, 0x1F,0x02, 0x1B,0x03, 0x1A,0x03, 0x1A,0x0E, 0x1B,0x04, 0x17,0x02, 0x1A,0x03, 0x1A,0x03, 0x1A,0x0E, 0x1B,0x04, 0x1A,0x03, 0x19,0x03, 0x17,0x03, 0x16,0x03,

0x17,0x0D, 0x16,0x03, 0x17,0x03, 0x19,0x01, 0x19,0x03, 0x19,0x03, 0x1A,0x03, 0x1F,0x03, 0x1B,0x03, 0x1B,0x03, 0x1A,0x03, 0x17,0x0D, 0x16,0x03, 0x16,0x03, 0x16,0x03, 0x17,0x01, 0x17,0x03, 0x17,0x03, 0x19,0x03, 0x1A,0x02, 0x1A,0x02, 0x10,0x03, 0x17,0x0D, 0x16,0x03, 0x16,0x01, 0x17,0x03, 0x19,0x03, 0x19,0x03, 0x17,0x03, 0x19,0x03, 0x1F,0x02, 0x1B,0x03, 0x1A,0x03, 0x1A,0x0E, 0x1B,0x04, 0x17,0x02, 0x1A,0x03, 0x1A,0x03, 0x1A,0x0E, 0x1B,0x04,

0x17,0x16, 0x1A,0x03, 0x1A,0x03, 0x1A,0x0E, 0x1B,0x04, 0x1A,0x03, 0x19,0x03, 0x17,0x03, 0x16,0x03, 0x0F,0x02, 0x10,0x03, 0x15,0x00, 0x00,0x00 };

聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場。文章及其配圖僅供工程師學習之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請聯(lián)系本站處理。 舉報投訴
  • AT89C2051
    +關(guān)注

    關(guān)注

    7

    文章

    170

    瀏覽量

    66282
  • 音樂門鈴
    +關(guān)注

    關(guān)注

    0

    文章

    19

    瀏覽量

    17643
收藏 人收藏

    評論

    相關(guān)推薦

    at89c2051實用程序

    at89c2051實用程序集這個包中提供了一些有實際應(yīng)用價值的子程序供參考選用SUB1----X25045/43 看門狗/存儲器與 89C2051接口子
    發(fā)表于 10-14 17:04

    at89c2051 問題

    哪位知道 at89c2051在仿真器通過的程序為什么燒寫好后插如線路會出錯啊?
    發(fā)表于 10-27 16:39

    AT89C2051燒寫程序問題

    怎么用RF910燒寫AT89C2051啊,引腳怎么連,比如單片機1腳鏈燒寫器的那個腳啊
    發(fā)表于 09-14 09:09

    求下這個基于AT89C2051的仿真程序

    求下這個基于AT89C2051的仿真程序,大神
    發(fā)表于 12-11 12:33

    at89c2051程序

    at89c2051程序包中提供了一些有實際應(yīng)用價值的子程序供參考選用SUB6----AT89C2051與上位機RS232通訊接口子程序
    發(fā)表于 10-14 17:03 ?248次下載
    <b class='flag-5'>at89c2051</b><b class='flag-5'>程序</b>

    AT89C2051單片機節(jié)日彩燈控制電路程序

    AT89C2051單片機節(jié)日彩燈控制電路程序 ;***************************************************;*   
    發(fā)表于 10-14 17:17 ?125次下載

    AT89C2051驅(qū)動步進電機的電路和源碼

    AT89C2051驅(qū)
    發(fā)表于 01-09 15:17 ?8次下載

    AT89C2051單片機時鐘程序源代碼

    AT89C2051單片機時鐘程序源代碼:AT89C2051組成的時鐘電路原理圖
    發(fā)表于 03-06 10:14 ?204次下載

    AT89C2051單片機的比較器的應(yīng)用

    AT89C2051單片機的比較器的應(yīng)用 AT89C2051的一個特殊應(yīng)用,用它的比較器做一個光強調(diào)節(jié)器,應(yīng)用
    發(fā)表于 09-13 16:28 ?2608次閱讀

    AT89C2051設(shè)計的快速充電器電路

    AT89C2051設(shè)計的快速充電器電路
    發(fā)表于 05-23 18:10 ?1479次閱讀
    <b class='flag-5'>AT89C2051</b>設(shè)計的快速充電器電路

    AT89C2051實現(xiàn)對功放的自動控制

    AT89C2051實現(xiàn)對功放的自動控制
    發(fā)表于 01-08 14:14 ?7次下載

    基于AT89C2051單片機的GPS時鐘系統(tǒng)

    基于AT89C2051單片機的GPS時鐘系統(tǒng)
    發(fā)表于 02-07 16:14 ?34次下載

    基于AT89C2051單片機的無線門鈴報警器

    本章向網(wǎng)友介紹一款集無線門鈴和無線防盜報警器于一身的無線門鈴報警器的制作,由于采用了AT89C2051單片機作為中央處理芯片,使得該系統(tǒng)的功能擴展比較方便,對于整個系統(tǒng)如需改變某種設(shè)置,只要更改相應(yīng)的軟件即可。
    發(fā)表于 03-18 14:13 ?24次下載
    基于<b class='flag-5'>AT89C2051</b>單片機的無線<b class='flag-5'>門鈴</b>報警器

    AT89C2051中文數(shù)據(jù)資料

    AT89C2051中文數(shù)據(jù)資料分享。
    發(fā)表于 04-13 11:06 ?60次下載

    AT89C2051的數(shù)字時鐘

    電子發(fā)燒友網(wǎng)站提供《帶AT89C2051的數(shù)字時鐘.zip》資料免費下載
    發(fā)表于 08-05 11:57 ?10次下載
    帶<b class='flag-5'>AT89C2051</b>的數(shù)字時鐘