導航:首頁 > 編程語言 > 單片機生日快樂代碼

單片機生日快樂代碼

發布時間:2024-10-29 03:01:39

『壹』 求: 用51單片機c語言操作使蜂鳴器奏出「祝你生日快樂」音樂的全部程序

參考一下:
http://hi..com/%D7%F6%B6%F8%C2%DB%B5%C0/blog/item/88bfff323ec42ef21b4cff09.html
-------------------
;生日快樂歌的程序
ORG 0000H
SJMP START
ORG 000BH
LJMP TIM0
;-------------------------------------------
START:
MOV TMOD, #01H
MOV IE, #82H
;-------------------------------------------
START0:
MOV 30H, #0
;-------------------------------------------
GET_TONE:
MOV A, 30H
MOV DPTR, #TAB
MOVC A, @A+DPTR //假設取到82H
MOV R2, A //譜碼82H存到R2
JZ END0 //是否取到結束碼00H?
ANL A, #0FH //取(低四位)節拍碼2
MOV R5, A //節拍碼存於R5=2
MOV A, R2
SWAP A
ANL A, #0FH //取(高四位)音符碼8
JNZ SING //取到的音符碼是否為0
CLR TR0 //是,不發音
D1:
CALL DELAY
INC 30H
JMP GET_TONE
;-------------------------------------------
SING:
DEC A
MOV 22H, A //22H=07H
RL A //A=2*07H
MOV DPTR, #TAB1
MOVC A, @A+DPTR
MOV TH0, A
MOV 21H, A //21h=64898
MOV A, 22H
RL A
INC A
MOVC A, @A+DPTR
MOV TL0, A
MOV 20H, A //20h=64968
SETB TR0
SJMP D1
;-------------------------------------------
END0: CLR TR0
JMP START0
;-------------------------------------------
TIM0:
MOV TL0, 20H
MOV TH0, 21H
CPL P3.7 ;外接揚聲器 發音
RETI
;-------------------------------------------
DELAY: MOV R7, #02
D2: MOV R4, #125
D3: MOV R3, #248
DJNZ R3, $
DJNZ R4, D3
DJNZ R7, D2
DJNZ R5, DELAY
RET

TAB1: DW 64260,64400,64524,64580,64684,64777,64820
DW 64898,64968,65030,65058,65110,65157,65178,65217
TAB:
DB 82H,01H,81H,94H,84H,0B4H,0A4H,04H
DB 82H,01H,81H,94H,84H,0C4H,0B4H,04H
DB 82H,01H,81H,0F4H,0D4H,0B4H,0A4H,94H
DB 0E2H,01H,0E1H,0D4H,0B4H,0C4H,0B4H,04H
DB 82H,01H,81H,94H,84H,0B4H,0A4H,04H
DB 82H,01H,81H,94H,84H,0C4H,0B4H,04H
DB 82H,01H,81H,0F4H,0D4H,0B4H,0A4H,94H
DB 0E2H,01H,0E1H,0D4H,0B4H,0C4H,0B4H,04H
DB 00H
END

『貳』 怎麼把歌曲用單片機C語言程序進行播放,急急急急~~~~~~

#include <reg51.h> //包括一個51標准內核的頭文件
#define uchar unsigned char //定義一下方便使用
#define uint unsigned int

sbit BEEP=P3^6; //喇叭輸出腳
uchar th0_f; //在中斷中裝載的T0的值高8位
uchar tl0_f; //在中斷中裝載的T0的值低8位

/***************** 延時 1ms *******************/
void delay_1ms(unsigned int t)
{
unsigned char i,j;
for(t;t>0;t--)
{
for(i=34;i>0;i--)
for(j=13;j>0;j--);
}
}

//T0的值,及輸出頻率對照表
static code freq[36][2] = {
0xA9,0xEF, //00220HZ ,1 //0
0x93,0xF0, //00233HZ ,1# //1
0x73,0xF1, //00247HZ ,2 //2
0x49,0xF2, //00262HZ ,2# //3
0x07,0xF3, //00277HZ ,3 //4
0xC8,0xF3, //00294HZ ,4 //5
0x73,0xF4, //00311HZ ,4# //6
0x1E,0xF5, //00330HZ ,5 //7
0xB6,0xF5, //00349HZ ,5# //8
0x4C,0xF6, //00370HZ ,6 //9
0xD7,0xF6, //00392HZ ,6# //10
0x5A,0xF7, //00415HZ ,7 //11
0xD8,0xF7, //00440HZ 1 //12
0x4D,0xF8, //00466HZ 1# //13
0xBD,0xF8, //00494HZ 2 //14
0x24,0xF9, //00523HZ 2# //15
0x87,0xF9, //00554HZ 3 //16
0xE4,0xF9, //00587HZ 4 //17
0x3D,0xFA, //00622HZ 4# //18
0x90,0xFA, //00659HZ 5 //19
0xDE,0xFA, //00698HZ 5# //20
0x29,0xFB, //00740HZ 6 //21
0x6F,0xFB, //00784HZ 6# //22
0xB1,0xFB, //00831HZ 7 //23
0xEF,0xFB, //00880HZ `1 //24
0x2A,0xFC, //00932HZ `1# //25
0x62,0xFC, //00988HZ `2 //26
0x95,0xFC, //01046HZ `2# //27
0xC7,0xFC, //01109HZ `3 //28
0xF6,0xFC, //01175HZ `4 //29
0x22,0xFD, //01244HZ `4# //30
0x4B,0xFD, //01318HZ `5 //31
0x73,0xFD, //01397HZ `5# //32
0x98,0xFD, //01480HZ `6 //33
0xBB,0xFD, //01568HZ `6# //34
0xDC,0xFD, //01661HZ `7 //35
};

static code music1[464] = { // 《隱形的翅膀》
36,36,36,36,36,36,36,36,36,36,36,36,8,8,12,12, //每一
16,16,16,16,16,16,19,19,16,16,16,16,14,14,12,12, //次都在徘徊
12,12,12,12,12,12,9,9,8,8,8,36,9,9,12,12, //孤單中堅強 每一
16,16,16,16,16,16,19,19,19,19,19,19,21,21,19,19, //次就算很受傷
19,19,16,16,14,14,12,12,14,14,14,36,21,21,19,19, //也不閃淚光 我知
16,16,16,16,16,16,19,19,19,19,19,19,21,21,19,19, //道我一直有雙
16,16,14,14,12,12,14,14,9,9,9,36,8,8,9,9, //隱形的翅膀 帶我
12,12,12,12,12,12,16,16,14,14,14,14,16,14,14,14, //飛 飛過絕
12,12,12,12,12,12,12,12,12,12,12,36,8,8,12,12, //望 不去
16,16,16,16,16,16,19,19,16,16,16,16,14,14,12,12, //想他們擁有
12,12,12,12,12,12,9,9,8,8,8,36,8,8,12,12, //美麗的太陽 我看
16,16,16,16,16,16,19,19,19,19,19,19,21,21,19,19, //見每天的夕陽
19,19,16,16,14,14,12,12,14,14,14,36,21,21,19,19, //也會有變化 我知
16,16,16,16,16,16,19,19,19,19,19,19,21,21,19,19, //道我一直有雙
16,16,14,14,12,12,14,14,9,9,9,36,8,8,9,9, //隱形的翅膀 帶我
12,12,12,12,12,12,14,16,14,14,14,14,16,16,12,12, //飛 給我希
12,12,12,12,12,12,12,12,12,12,12,36,16,16,19,19, //望 我終
24,24,24,24,24,36,24,24,24,24,24,24,21,21,19,19, //於看到所有
21,21,24,24,16,16,14,14,12,12,12,36,12,12,12,12, //夢想都開花 追逐
12,12,24,24,24,24,21,21,19,19,16,16,14,14,12,12, //的年輕歌聲多嘹
14,14,14,14,14,14,14,14,14,14,14,36,16,16,19,19, //亮 我終
24,24,24,24,24,36,24,24,24,24,24,24,21,21,19,19, //於翱翔用心
21,21,24,24,16,16,14,14,12,12,12,36,12,12,12,12, //凝望不害怕 哪裡
12,12,24,24,24,24,21,21,19,19,16,16,14,14,12,12, //會有風就飛多遠
12,12,12,12,12,12,12,12,12,12,36,36,16,16,19,19, //吧 隱形
24,24,24,24,24,36,24,24,23,23,23,23,21,21,19,19, //的翅膀讓夢
21,21,24,24,16,16,14,14,12,12,12,36,12,12,12,12, //恆久比天長 留一
12,12,24,24,24,24,21,21,19,19,16,16,14,14,14,14, //個願望讓自己
14,14,14,14,12,12,12,12,12,12,12,12,12,12,12,36, //想像... ...
};

static code music2[336] = { // 《北京歡迎你》
16,16,19,19,16,16,14,14,16,16,14,14,16,16,16,36, //迎接另一個晨曦
16,16,14,14,9,9,12,12,16,16,14,14,14,14,14,36, //帶來全新空氣
14,14,12,12,9,9,12,12,14,14,16,16,19,19,14,14, //氣息改變情味不變
16,16,21,21,19,19,9,9,14,14,12,12,12,12,12,36, //茶香飄滿情誼
16,16,19,19,16,16,14,14,16,16,14,14,16,16,16,36, //我家大門常打開
16,16,14,14,9,9,12,12,16,16,14,14,14,14,14,36, //開放懷抱等你
14,14,12,12,9,9,12,12,14,14,16,16,19,19,14,14, //擁抱過就有了默契
16,16,21,21,19,19,9,9,14,14,12,12,12,12,12,36, //你會愛上這里
14,14,12,12,9,9,12,12,14,14,16,16,19,19,14,14, //不管遠近都是客人
16,16,21,21,19,19,19,19,16,16,16,16,16,16,16,36, //請不用客氣
14,14,16,16,14,14,12,12,19,19,21,21,14,14,14,36, //相約好了在一起
9,9,16,16,14,14,14,14,12,12,12,12,12,12,12,36, //我們歡迎你
36,36,36,36,36,36,36,36,16,16,16,16,19,19,19,19, //北京
24,24,19,19,21,21,21,21,36,36,21,21,19,19,16,16, //歡迎你 為你開
16,16,19,19,19,19,19,19,19,19,19,36,16,16,19,19, //天闢地 流動
21,21,24,24,26,26,24,24,19,19,16,16,14,14,19,19, //中的魅力充滿著朝
16,16,16,16,16,16,16,16,16,16,16,36,16,16,19,19, //氣 北京
24,24,19,19,21,21,21,21,36,36,24,24,26,26,24,24, //歡迎你 在太陽
19,19,16,16,19,19,23,23,21,21,21,21,36,36,16,16, //下分享呼吸 在
14,14,16,16,19,19,28,28,26,26,26,26,26,26,23,23, //黃土地刷新成
24,24,24,24,24,24,24,24,24,24,24,24,24,24,36,36, //績
};

static code music3[444] = { // 《仙劍奇俠傳》
28,28,26,26,28,28,28,28,28,28,21,21,
26,26,26,26,24,24,23,23,21,21,21,23,21,21,19,19,
28,28,28,28,16,16,19,19,24,24,24,24,16,16,19,19,
26,26,26,26,24,24,23,23,21,21,21,21,21,21,21,21,
21,21,21,21,28,28,26,26,36,36,36,36,28,28,26,26,
21,21,21,21,24,24,26,26,28,28,28,28,28,28,28,28,
28,28,31,31,28,28,24,24,26,26,26,26,26,26,26,26,
21,21,21,21,24,24,28,28,26,26,26,26,24,24,24,24,
21,21,21,21,21,21,21,21,21,21,21,21,36,36,36,36,
28,28,26,26,28,28,28,28,28,28,21,21,
26,26,26,26,24,24,23,23,21,21,21,23,21,21,19,19,
28,28,28,28,16,16,19,19,24,24,24,24,16,16,19,19,
26,26,26,26,28,24,23,23,21,21,21,21,21,21,21,21,
21,21,21,21,28,28,26,26,36,36,36,36,28,28,26,26,
28,28,28,28,28,28,21,21,
26,26,26,26,24,24,23,23,21,21,21,23,21,21,19,19,
16,16,16,16,16,16,19,19,24,24,24,24,16,16,19,19,
26,26,26,26,28,24,23,23,21,21,21,21,21,21,21,21,
21,21,21,21,23,23,23,23,23,23,23,23,23,23,23,23,
21,21,21,21,24,24,26,26,28,28,28,28,28,28,28,28,
31,33,31,31,28,28,24,24,26,26,26,26,26,26,26,26,
21,21,21,21,24,24,28,28,26,26,26,26,24,24,24,24,
21,21,21,21,21,21,21,21,21,21,21,21,36,36,36,36,
28,28,26,26,28,28,28,28,28,28,21,21,
26,26,26,26,24,24,23,23,21,21,21,23,21,21,19,19,
28,28,28,28,16,16,19,19,24,24,24,24,16,16,19,19,
26,26,26,26,28,24,23,23,21,21,21,21,21,21,21,21,
23,23,23,23,23,23,23,23,23,23,23,23,21,21,19,19,
21,21,21,21,21,21,21,21,36,36,36,36,36,36,36,36,
};

static code music4[448] = { // 《笑傲江湖》
16,16,16,16,21,21,21,16,19,19,19,19,19,19,16,16,
14,14,16,16,19,19,21,21,16,16,16,16,16,16,16,36,
16,16,16,16,21,21,21,16,19,19,19,19,19,19,16,16,
14,14,16,16,19,19,21,19,16,16,16,16,36,16,16,14,
12,12,12,12,14,14,16,16,14,14,14,14,14,14,14,12,
9,9,9,12,14,14,16,16,19,19,19,21,19,19,16,14,
12,12,12,14,14,14,16,16,14,14,14,14,14,12,12,12,
9,9,9,12,14,16,16,19,21,21,21,21,21,21,21,36,
16,16,16,16,21,21,21,16,19,19,19,19,19,19,16,16,
14,14,16,16,19,19,21,19,16,16,16,16,16,16,16,36,
16,16,16,16,21,21,21,16,19,19,19,19,19,19,16,16,
14,14,14,16,19,19,21,19,16,16,16,16,36,16,16,14,
12,12,12,12,14,14,16,16,14,14,14,14,14,14,14,12,
9,9,9,12,14,14,16,16,19,19,19,21,19,19,16,14,
12,12,12,14,14,14,16,16,14,14,14,14,14,12,12,12,
9,9,9,12,14,16,16,19,21,21,21,21,21,21,21,36,
14,14,14,14,14,16,16,14,12,12,12,12,12,9,9,12,
14,14,14,14,14,16,16,14,12,12,9,9,36,12,9,12,
14,14,14,14,14,16,16,14,12,12,12,12,36,12,9,12,
14,14,14,14,14,19,19,16,16,16,16,16,16,16,16,36,
9,9,9,9,36,9,9,9,14,14,14,14,14,14,16,14,
12,12,12,12,36,12,12,14,9,9,9,9,9,9,7,7,
9,9,9,9,36,9,7,7,4,4,4,4,36,4,7,7,
2,2,2,2,36,2,2,2,4,4,4,4,4,4,4,36,
9,9,9,9,9,9,9,9,14,14,14,14,14,14,16,16,
12,12,12,12,12,12,14,14,9,9,9,9,12,9,
7,7,7,7,7,7,9,9,4,4,4,2,4,4,7,7,
9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,
};

//定時中斷0,用於產生唱歌頻率
timer0() interrupt 1
{
TL0=tl0_f;TH0=th0_f; //調入預定時值
BEEP=~BEEP; //取反音樂輸出IO
P2=~P2;
}

//音階聲音自動輸出試驗
void main(void) // 主程序
{
uint i;
TMOD = 0x01; //使用定時器0的16位工作模式
TR0 = 1;
ET0 = 1;
EA = 1;
while(1)
{
for(i=0;i<336;i++) //播放音樂
{
if(music2[i] == 36) //空音
{
TR0 = 0;
delay_1ms(190);
TR0 = 1;
}
else
{
tl0_f=freq[music2[i]][0]; //置一個音符的值
th0_f=freq[music2[i]][1];
delay_1ms(190);
}
}
TR0 = 0;
delay_1ms(3000);
TR0 = 1;
}
}

『叄』 單片機高手來,AT89S52的音樂發生器程序,這個是生日快樂歌的程序,會的幫我加下注釋,一點過要詳細

其中一個表格用來存儲定時器初值 它能決定定時時間 也就能決定音樂的頻率 另一個表格用來存儲音符之間的的間隔時間

『肆』 求LCD1602顯示生日快樂四個漢字的程序,單片機用AT89S52的,謝啦~

/*LCD 1602生成兩行字,分別是:"Believe yourself!"和"Happybirthy to you!"並作向左循環移動!*/
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
uchar code table1[]="Believe yourself!";
uchar code table2[]="Happybirthy to you!";
sbit RS=P1^0;
sbit RW=P1^1;
sbit E=P1^2;
void delay(uint ms)
{
uint n;
for(;ms>0;ms--)
for(n=124;n>0;n--);
}
/*寫指令*/
void write_Instruction(uchar Instruction)
{
RS=0;
RW=0;
E=0;
P0=Instruction;
delay(5);
E=1;
delay(5);
E=0;
}
/*寫數據*/
void write_Data(uchar Data)
{
RS=1;
RW=0;
E=0;
P0=Data;
delay(5);
E=1;
delay(5);
E=0;
}
/*初始化*/
void Init()
{
delay(15);
write_Instruction(0x38);
delay(5);
write_Instruction(0x38);
delay(5);
write_Instruction(0x38);
delay(5);
write_Instruction(0x38);
write_Instruction(0x38);
write_Instruction(0x08);
write_Instruction(0x01);
write_Instruction(0x06);
write_Instruction(0x0c);
}
void left_move()
{
uchar i;
for(i=0;i<16;i++)
{
write_Instruction(0x18);
delay(3000);
}
}
void main()
{
uchar i;
Init();
while(1)
{
write_Instruction(0x80);

for(i=0;i<16;i++)
{
write_Data(table1[i]);
delay(1);
}

write_Instruction(0x80+0x40);
for(i=0;i<19;i++)
{
write_Data(table2[i]);
delay(1);
}
left_move();
}
}

閱讀全文

與單片機生日快樂代碼相關的資料

熱點內容
安裝三菱編程閃退怎麼回事 瀏覽:488
手機怎麼創建word文件格式 瀏覽:694
c語言連接資料庫 瀏覽:887
數據線粉色和白色哪個是正 瀏覽:775
vb編程應注意什麼 瀏覽:855
js循環添加控制項 瀏覽:615
學習計算機網路的作用 瀏覽:235
access資料庫最新內容怎麼調 瀏覽:203
上古世紀新版本跑商 瀏覽:267
iphone5國際漫遊設置 瀏覽:107
ipodwatch如何安裝app 瀏覽:114
誰有微信搶紅包的群號 瀏覽:872
word07頁碼從任意頁開始 瀏覽:791
js禁止滑動事件 瀏覽:800
蘋果查序號怎麼看不是 瀏覽:61
linux在txt文件 瀏覽:568
ps如何導入文件匹配 瀏覽:201
轉轉app怎麼把自己的賬號租出去 瀏覽:828
福昕閱讀器合並照片pdf文件 瀏覽:591
vhd文件有什麼用 瀏覽:482

友情鏈接