datasheet

89c51六首歌曲的音乐门铃程序

2018-01-12 21:05:38来源: eefocus 关键字:89c51  音乐门铃

buzzer        equ        p2.4 
KEY        EQU        P3.7

            org         00h                  ;主程序起始地址 
            jmp          start                ;跳动主程序 
            org          0bh                  ;timer0中断起始地址 
            jmp          tim0                 ;跳至timer0在mode1 
start:       MOV           tmod,#00000001b      ;设timer0在mode1 
             MOV           ie,#10000010b        ;中断使能 
            jb           KEY,$               ;第一次按to? 
            call         delay1               ;消除抖动 
            jnb          KEY,$               ;to放开? 
             MOV           31h,#00              ;按to次数计数指针初值为00h 
start0:              
             MOV           30h,#low song        ;取简谱码指针(第1首) 
next:        MOV           a,30h 
             MOV           dptr,#table 
             MOV c         a,@a+dptr            ;至相关页码,高4位为音符的高低 
             MOV           r2,a                 ;低4位为音符的节拍 
            jz           end0                 ;检查简谱码是否已结束(有无00?) 
            anl          a,#0fh               ;取节拍(低4位)  
             MOV           r5,a                 ;存入r5,节拍的时间 
             MOV           a,r2 
            swap         a  
            anl          a,#0fh               ;取音频值(高4位) 
            jnz          sing                 ;是否为0,是0则不发音 
            clr          tr0 
            jmp          d1 
sing:       dec          a                    ;因0不列入 
             MOV           22h,a                ;存入(22h) 
            rl           a                    ;乘2 
             MOV           dptr,#table 
             MOV c         a,@a+dptr            ;至table取码,取t的值 
             MOV           th0,a                ;取到的高位字节存入th0 
             MOV           21h,a                ;取到的高位字节存入(21h) 
             MOV           a,22h                ;再载入取到的音符码 
            rl           a                    ;乘2 
            inc          a                    ;加1 
             MOV c         a,@a+dptr            ;至table取相对的低位字节计数值 
             MOV           tl0,a                ;取到的低位字节存入tl0 
             MOV           20h,a                ;取到的低位字节存入(20h) 
            setb         tr0                  ;启动timer0 
d1:         call         delay 
            inc          30h                  ;取简谱码指针加1 
            jmp          next 
end0:       clr          tr0                  ;停止计数器 
             MOV           a,31h                ;载入计次指针 
            xrl          a,#00h               ;是否按第1次? 
            jnz          end1                 ;不是则跳至end1 
            jb           KEY,$               ;按第2次? 
            call         delay1               ;消除抖动 
            jnb          KEY,$               ;放开否? 
            inc          31h                  ;计次地址(31h)加1 
             MOV           30h,#low song1       ;第2首歌指针 
            jmp          next 
end1:        
             MOV           a,31h                ;载入计次指针 
            xrl          a,#01h               ;是否按第2次? 
            jnz          end2                 ;不是则跳至end2 
            jb           KEY,$               ;按第3次? 
            call         delay1               ;消除抖动 
            jnb          KEY,$               ;放开否? 
            inc          31h                  ;计次地址(31h)加1 
             MOV           30h,#low song2       ;第3首歌指针 
            jmp          next 
end2:        
             MOV           a,31h                ;载入计次指针 
            xrl          a,#02h               ;是否按第3次? 
            jnz          end3                ;不是则跳至end3 
            jb           KEY,$               ;按第4次? 
            call         delay1               ;消除抖动 
            jnb          KEY,$               ;放开否? 
            inc          31h                  ;计次地址(31h)加1 
             MOV           30h,#low song3       ;第4首歌指针 
            jmp          next 
end3:        
             MOV           a,31h                ;载入计次指针 
            xrl          a,#03h               ;是否按第4次? 
            jnz          end4                 ;不是则跳至end4 
            jb           KEY,$               ;按第5次? 
            call         delay1               ;消除抖动 
            jnb          KEY,$               ;放开否? 
            inc          31h                  ;计次地址(31h)加1 
             MOV           30h,#low song4      ;第5首歌指针 
            jmp          next 
end4:        
             MOV           a,31h                ;载入计次指针 
            xrl          a,#01h               ;是否按第5次? 
            jnz          end5                 ;不是则跳至end2 
            jb           KEY,$               ;按第6次? 
            call         delay1               ;消除抖动 
            jnb          KEY,$               ;放开否? 
            inc          31h                  ;计次地址(31h)加1 
             MOV           30h,#low song5       ;第6首歌指针 
            jmp          next 
end5: 
            jmp          start                ;回到第1次位置 
tim0:       push         aCC                  ;将a的值暂存于堆栈 
            push         psw                  ;将psw的值暂存于堆栈 
            setb         rs0                  ;设工作寄存器库1,rs0=1,rs1=0 
            clr          rs1                   
             MOV           tl0,20h              ;重设计数值 
             MOV           th0,21h               
            cpl          buzzer               ;将p10位反相 
        clr        rs0 
            pop          psw                  ;至堆栈取回psw的值 
            pop          acc                  ;至堆栈取回a的值 
            reti                              ;返回主程序 
delay:       MOV           r7,#02               ;125秒 
d2:          MOV           r4,#125 
d3:          MOV           r3,#248 
            djnz         r3,$ 
            djnz         r4,d3 
            djnz         r7,d2 
            djnz         r5,delay             ;决定节拍 
            ret  
delay1:      MOV           r4,#20 
d4:          MOV           r3,#248 
            djnz         r3,$ 
            djnz         r4,d4 
            ret 

            org          300h                    
table:        
            dw           64260,64400,64524,64580  
            dw           64684,64777,64820,64898  
            dw           64968,65030,65058,65110  
            dw           65157,65178,65217 
song:       ;第一首歌  哈 巴 狗 
            ;1 
            db           42h,42h,42h,52h,62h,04h 
            db           62h,62h,62h,72h,84h,04h 
            db           92h,92h,82h,72h,64h,04h 
            db           82h,82h,52h,62h,44h,04h 
            ;2 
            db           42h,42h,42h,52h,62h,04h 
            db           62h,62h,62h,72h,84h,04h 
            db           92h,92h,82h,72h,64h,04h 
            db           82h,82h,52h,62h,44h,04h 
            db           00h 
song1:      ;第2首歌    生 日 快 乐 
            ;1 
            db           82h,01h,81h,94h,84h 
            db           0b4h,0a4h,04h 
            db           82h,01h,81h,94h,84h 
            db           0c4h,0b4h,04h 
            ;2 
            db           82h,01h,81h,0f4h,0d4h 
            db           0b4h,0a4h,94h 
            db           0e2h,01h,0e1h,0d4h,0b4h 
            db           0c4h,0b4h,04h 
            db           00h 
song2:      ;第3首歌     不 倒 翁 
            ;1 
            db           84h,94h,88h 
            db           64h,54h,68h 
            db           84h,64h,54h,44h 
            db           52h,42h,52h,62h,48h 
      
            ;2 
            db           84h,94h,88h 
            db           64h,54h,68h 
            db           84h,64h,54h,44h 
            db           52h,42h,52h,62h,48h 
            db           00h 
song3:      ;第4首歌       妹妹背着洋娃娃 
            ;1 
            db           84h,02h,82h,64h,54h 
            db           64h,54h,48h 
            db           64h,02h,52h,44h,24h 
            db           14h,24h,18h 
            ;2 
            db           24h,02h,22h,42h,24h 
            db           44h,54h,68h 
            db           54h,02h,52h,84h,84h 
            db           54h,64h,48h 
            db           00h 
song4:      ;第5首歌   两只老虎 
            ;1 
            db           44h,54h,64h,44h 
            db           44h,54h,64h,44h 
            db           64h,74h,88h 
            db           64h,74h,88h 
            ;2 
            db           82h,92h,82h,72h,64h,44h 
            db           82h,92h,82h,72h,64h,44h 
            db           44h,84h,48h 
            db           44h,14h,48h,00H 
song5:      ;第6首歌   三只小猫 
            ;1 
            db           62h,82h,82h,62h,98h 
            db           92h,0b2h,0b2h,82h,98h 
            db           62h,82h,82h,52h,68h 
            db           92h,0b2h,0b2h,82h,98h 
            ;2 
            db           62h,82h,82h,62h,92h,92h,94h 
            db           92h,0b2h,0b2h,92h,84h,94h 
            db           0b8h,0b4h,04h 
            db           00h 
            end            

[1] [2]

关键字:89c51  音乐门铃

编辑:什么鱼 引用地址:http://www.eeworld.com.cn/mcu/article_2018011237332.html
本网站转载的所有的文章、图片、音频视频文件等资料的版权归版权所有人所有,本站采用的非本站原创文章及图片等内容无法一一联系确认版权者。如果本网所选内容的文章作者及编辑认为其作品不宜公开自由传播,或不应无偿使用,请及时通过电子邮件或电话通知我们,以迅速采取适当措施,避免给双方造成不必要的经济损失。

上一篇:TIMER0在MODE0下延时时间程序
下一篇:最后一页

关注eeworld公众号 快捷获取更多信息
关注eeworld公众号
快捷获取更多信息
关注eeworld服务号 享受更多官方福利
关注eeworld服务号
享受更多官方福利
推荐阅读
全部
89c51
音乐门铃

小广播

独家专题更多

东芝在线展会——芯科技智社会创未来
东芝在线展会——芯科技智社会创未来
2017东芝PCIM在线展会
2017东芝PCIM在线展会
TI车载信息娱乐系统的音视频解决方案
TI车载信息娱乐系统的音视频解决方案
汇总了TI汽车信息娱乐系统方案、优质音频解决方案、汽车娱乐系统和仪表盘参考设计相关的文档、视频等资源

何立民专栏

单片机及嵌入式宝典

北京航空航天大学教授,20余年来致力于单片机与嵌入式系统推广工作。

电子工程世界版权所有 京ICP证060456号 京ICP备10001474号 电信业务审批[2006]字第258号函 京公海网安备110108001534 Copyright © 2005-2017 EEWORLD.com.cn, Inc. All rights reserved