标题:
51单片机蜂鸣器播放歌曲汇编源码和仿真
[打印本页]
作者:
yqqing
时间:
2017-11-22 23:01
标题:
51单片机蜂鸣器播放歌曲汇编源码和仿真
一个用51单片机播放歌曲的小程序
0.png
(6.51 KB, 下载次数: 74)
下载附件
2017-11-23 03:22 上传
单片机汇编语言源程序如下:
org 0000H
sjmp start
org 0040H
start: mov R3,#-1;
loop4:
jb p1.0,stopzero ; the first step: see if button1 on. it is 0 jump to stopzero (2us)
inc R3 ;R3=0 at first (1us)
sjmp mod1;butoon=1 jump to paly the song (2us)
stopzero: ;(5us)
jb p1.1,stopone ;see if button2 is on. it's 0 jump to stoptone(2us)
inc R3 ; R3=0 at first (1us)
sjmp mod1 ; jump to paly the song (2us)
stopone:; (5us)
jb p1.3,loop4 ;see if button3 is on. it's 0 jump to stoptwo(2us)
inc R3
sjmp mod1 ; jump to paly the song (2us)
mod1: mov a,R3 ;(1us)
chec1: jb p1.0,chec2 ;(2us)find which song we are playing (2us)
sjmp b1 ;(2us)
chec2: jb p1.1,chec3
sjmp b2
chec3: jb p1.3,chec1
sjmp b3
b1: mov b,#11 ;(1us) b=first song's notes number
sjmp di ;(2us)
b2: mov b,#30 ;b=second song's notes number
sjmp di
b3: mov b,#30 ;b= third song's notes number
sjmp di
di: div ab ;divide a by b ,remainder is in b (4us)
mov a,b ; put remainder in a (1us)
mov R3,b ;put remainder in R3(which will be divided later (1us)
check1: jb p1.0,check2 ;to find which song is playing and get the duration table (
sjmp songdu1
check2: jb p1.1,check3
sjmp songdu2
check3: jb p1.3,check1
sjmp songdu3
songdu1: mov dptr,#durationone ;get duration table (2us)
sjmp get
songdu2: mov dptr,#durationtwo ;get duration table
sjmp get
songdu3: mov dptr,#durationthree ;get duration table
sjmp get
get: movc a,@a+dptr ;get the data in duration table one by one(2us)
mov R2,a; put a in R2 (1us)
;loop3(24+3+notes's half period)
loop3: mov a,b ;give reminder to a agian to get notes table(1us)
che1: jb p1.0,che2
sjmp songno1
che2: jb p1.1,che3
sjmp songno2
che3: jb p1.3,che1
sjmp songno3
songno1: mov dptr,#notesone ;get duration table (2us)
sjmp getn
songno2: mov dptr,#notestwo ;get duration table
sjmp getn
songno3: mov dptr,#notesthree ;get duration table
sjmp getn
getn: movc a,@a+dptr ; (2us)
mov R1,a ;put note now in R1 (1us)
loop2:mov R0,#10 ;the part of play every note:(2*R0+2+1)*R1
loop1: djnz R0,$
djnz R1,loop2
cpl p3.1
djnz R2, loop3 ;start make delay (2us) R2*(loop3+2us)
mov R1,255 ;make rest between two notes (1us)
delay2:mov R0,#255
delay1:djnz R0,$
djnz R1,delay2
acall loop4 ; get all steps again and agian
sjmp $
notesone: db 66,83,105,83,74,56,74,66,74,105,83 ; the delay time of the music score one by one
……………………
…………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
lab2-8051.rar
(65.72 KB, 下载次数: 40)
2017-11-22 23:00 上传
点击文件名下载附件
下载积分: 黑币 -5
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1