单片机
返回首页

跑马灯及音乐盒的汇编程序

2012-10-20 来源:21IC

;蜂鸣器就使用哪种小的无源的有源的5v蜂鸣器都可以,经过试验发现用无源的效果更好,接在p1.2口,最好用一个三极管放大一下电流,晶振用12兆的.
ORG 0000H
LJMP START
ORG 000BH
INC 20H ;中断服务,中断计数器加1
MOV TH0,#0D8H
MOV TL0,#0EFH ;12M晶振,形成10毫秒中断
RETI
START:
MOV SP,#50H
MOV TH0,#0D8H
MOV TL0,#0EFH
MOV TMOD,#01H
MOV IE,#82H
Mu: 
Mov  p3,#0ffh
SETB P1.2
lcall   key
MUSIC0:
NOP
 MOV 20H,#00H ;中断计数器清0
MOV B,#00H ;表序号清0
MUSIC1:
NOP
CLR A
MOVC A,@A+DPTR ;查表取代码
MOV  P3,A
JZ  MU
JZ END0 ;是00H,则结束
CJNE A,#0FFH,MUSIC5
LJMP MUSIC3
MUSIC5:
NOP
MOV R6,A
INC DPTR
MOV A,B
MOVC A,@A+DPTR ;取节拍代码送R7
MOV R7,A
SETB TR0 ;启动计数
MUSIC2:
NOP
CPL P1.2
MOV A,R6
MOV R3,A
LCALL DEL
MOV A,R7
CJNE A,20H,MUSIC2 ;中断计数器(20H)=R7否?
;不等,则继续循环
MOV 20H,#00H ;等于,则取下一代码
INC DPTR
; INC B
LJMP MUSIC1
MUSIC3:
NOP
CLR TR0 ;休止100毫秒
MOV R2,#0DH
MUSIC4:
NOP
MOV R3,#0FFH
LCALL DEL
DJNZ R2,MUSIC4
INC DPTR
LJMP MUSIC1
END0:
NOP
MOV R2,#64H ;歌曲结束,延时1秒后继续
MUSIC6:
MOV R3,#00H
LCALL DEL
DJNZ R2,MUSIC6
LJMP  mu
DEL:
NOP
DEL3: 
MOV R4,#02H
DEL4: 
NOP
DJNZ R4,DEL4
NOP
DJNZ R3,DEL3
RET
Key:
Key1:
Mov  a,P2
Mov  P0,a
Cjne  a,#0feh,key2
Mov  dptr,#mu_tab1;;表头地址送DPTR
Ljmp  MUSIC0
Key2:
Mov  a,P2
Mov  P0,a
Cjne  a,#0fdh,key3
Mov  dptr,#mu_tab2 ;;表头地址送DPTR
Ljmp  MUSIC0
Key3:
Sjmp  key
 
NOP
Mu_tab1:
db 26h,20h,20h,20h,20h,20h,26h,10h,20h,10h,20h,80h,26h,20h,30h,20h
db 30h,20h,39h,10h,30h,10h,30h,80h,26h,20h,20h,20h,20h,20h,1ch,20h
db 20h,80h,2bh,20h,26h,20h,20h,20h,2bh,10h,26h,10h,2bh,80h,26h,20h
db 30h,20h,30h,20h,39h,10h,26h,10h,26h,60h,40h,10h,39h,10h,26h,20h
db 30h,20h,30h,20h,39h,10h,26h,10h,26h,80h,26h,20h,2bh,10h,2bh,10h
db 2bh,20h,30h,10h,39h,10h,26h,10h,2bh,10h,2bh,20h,2bh,40h,40h,20h
db 20h,10h,20h,10h,2bh,10h,26h,30h,30h,80h,18h,20h,18h,20h,26h,20h
db 20h,20h,20h,40h,26h,20h,2bh,20h,30h,20h,30h,20h,1ch,20h,20h,20h
db 20h,80h,1ch,20h,1ch,20h,1ch,20h,30h,20h,30h,60h,39h,10h,30h,10h
db 20h,20h,2bh,10h,26h,10h,2bh,10h,26h,10h,26h,10h,2bh,10h,2bh,80h
db 18h,20h,18h,20h,26h,20h,20h,20h,20h,60h,26h,10h,2bh,20h,30h,20h
db 30h,20h,1ch,20h,20h,20h,20h,80h,26h,20h,30h,10h,30h,10h,30h,20h
db 39h,20h,26h,10h,2bh,10h,2bh,20h,2bh,40h,40h,10h,40h,10h,20h,10h
db 20h,10h,2bh,10h,26h,30h,30h,80h,00H
mu_tab2:
DB      18H,     30H,     1CH,     10H
        DB      20H,     40H,     1CH,     10H     
        DB      18H,     10H,     20H,     10H
        DB      1CH,     10H,     18H,     40H
        DB      1CH,     20H,     20H,     20H
        DB      1CH,     20H,     18H,     20H     
        DB      20H,     80H,     0FFH,    20H
        DB      30H,     1CH,     10H  ,   18H
        DB      20H,     15H,     20H ,    1CH
        DB      20H,     20H,     20H ,    26H
        DB      40H,     20H ,    20H ,    2BH
        DB      20H,     26H,     20H ,    20H     
        DB      20H,     30H ,    80H ,    0FFH
        DB      20H,     20H,     1CH ,    10H
        DB      18H,     10H,     20H ,    20H
        DB      26H,     20H ,    2BH ,    20H
        DB      30H,     20H ,    2BH ,    40H
        DB      20H,     20H  ,   1CH  ,   10H
        DB      18H,     10H,     20H,     20H
        DB      26H,     20H ,    2BH,     20H
        DB      30H,     20H,     2BH ,    40H
        DB      20H,     30H,     1CH ,    10H
        DB      18H,     20H ,    15H ,    20H
        DB      1CH,     20H ,    20H ,    20H
        DB      26H,     40H,     20H ,    20H     
        DB      2BH,     20H,     26H ,    20H     
        DB      20H,     20H,     30H ,    80H
        DB      20H,     30H,     1CH ,    10H
        DB      20H,     10H,     1CH ,    10H
        DB      20H,     20H,     26H  ,   20H
        DB      2BH,     20H,     30H  ,   20H
        DB      2BH,     40H,     20H   ,  15H
        DB      1FH,     05H,     20H    , 10H
        DB      1CH,     10H,     20H ,    20H
        DB      26H,     20H,     2BH ,    20H
        DB      30H,     20H,     2BH ,    40H
        DB      20H,     30H,     1CH  ,   10H
        DB      18H,     20H ,    15H  ,   20H
        DB      1CH,     20H ,    20H  ,   20H
        DB      26H,     40H,     20H  ,   20H
        DB      2BH,     20H,     26H   ,  20H
        DB      20H,     20H,     30H,     30H      
        DB      20H,     30H,     1CH,     10H
        DB      18H,     40H,     1CH,     20H
        DB      20H,     20H,     26H,     40H
        DB      13H,     60H,     18H ,    20H
        DB      15H,     40H,     13H ,    40H
        DB      18H,     80H,     00H
END
进入单片机查看更多内容>>
相关视频
  • RISC-V嵌入式系统开发

  • SOC系统级芯片设计实验

  • 云龙51单片机实训视频教程(王云,字幕版)

  • 2022 Digi-Key KOL 系列: 你见过1GHz主频的单片机吗?Teensy 4.1开发板介绍

  • TI 新一代 C2000™ 微控制器:全方位助力伺服及马达驱动应用

  • MSP430电容触摸技术 - 防水Demo演示

精选电路图
  • 简洁的过零调功器电路设计与分析

  • IGBT模块通过控制门极阻断过电流

  • CCFL的工作原理及电子驱动电路解析

  • 比较常见的功率整流器和滤波电路

  • 基于M66T旋律发​​生器的电路图解析

  • 基于TDA1554的立体声放大器电路

    相关电子头条文章