单片机汇编语言求解释

2019-07-15 18:03发布

yfh equ 30h     ;音符高位
   yfl equ 31h     ;音符低位
   jp equ 32h     ;节拍
   yyd equ 33h     ;
   yf equ 34h ;

   org 0000h
   ajmp main

;--------------定时中断程序
   org 000bh
   cpl p2.1
   mov th0,yfh
   mov tl0,yfl
   reti
;--------------主程序  
   org 0030h
main: setb p2.1
   mov yyd, #00h
   mov tmod,#11h
   setb EA
   setb ET0
   setb TR1
   setb TR0
music:
   mov dptr,#table2 ;取出音符,并存入yf单元
   mov a,yyd
   movc a,@a+dptr
   cjne a,#00h,music1;判断音乐是否结束,结束复位
   ajmp main
music1:
     dec a
   rl a
   mov yf,a
   mov a,yyd;指向节拍
   inc a
   mov yyd,a
   mov dptr,#table1 ;取出音符初值,并存入yfh,yfl单元
   mov a,yf
   movc a,@a+dptr
   mov yfh,a
   mov a,yf
   inc a
   movc a,@a+dptr
   mov yfl,a
   mov dptr,#table2
   mov a,yyd;取出音节,并存入jp
   movc a,@a+dptr
   mov jp,a
   mov th0,yfh;送入音符初值
   mov tl0,yfl
   mov a,yyd ;指向下一音符
   inc a
   mov yyd,a
   lcall delay
   nop
   ljmp music
delay:
   mov r2,jp
del4: mov r1,#3
del3:
   mov th1,#3ch
   mov tl1,#0b0h
del1:
   jbc tf1,del2      ;查询定时时间是否到
   ajmp del1
del2:
   djnz r1,del3
   djnz r2,del4
   ret

table1:
   db 0f8h,8ch,0f9h,5ch,0fah,14h,0fah,67h,0fbh,04h,0fbh,90h,0fch,0ch
    DB 0fch,44h,0fch,0b6h,0fdh,09h,0fdh,34h,0fdh,82h,0fdh,0c8h,0feh,06h
    DB 0feh,22h,0feh,56h,0feh,8ch,0feh,9ah,0feh,0c1h,0feh,0e4h,0ffh,03h
table2:         ;歌曲---音节表
       /*db 01h,04h,02h,04h,03h,04h,04h,04h,05h,04h,06h,04h,07h,04h   ;歌曲表
   db 08h,04h,09h,04h,0ah,04h,0bh,04h,0ch,04h,0dh,04h,0eh,04h
   db 0fh,04h,10h,04h,11h,04h,12h,04h,13h,04h,14h,04h,15h,06h
   db 00h*/

              /*乐曲---心太软
                db 0ch,02h,0ch,02h,0ah,02h,0dh,04h,0ch,02h,0ah,06h,0ah,04h,09h,02h,08h,02h,08h,04h,08h,02h
                db 0fh,02h,0fh,02h,0fh,02h,0fh,02h,0dh,02h,0ch,04h,0ah,02h,0dh,02h,0ch,06h*/

              ;乐曲---老鼠爱大米
               /*db 0ah,02h,09h,01h,08h,01h,08h,04h,0ah,02h,09h,01h,08h,01h,08h,04h,0ah,02h,09h,02h
               db 0ah,02h,01h,02h,0ah,02h,0dh,01h,0ch,01h,0ch,04h,0ah,01h,0ch,01h,0dh,02h,0dh,01h,0ch,01h,0ch,02h
               db 0dh,01h,0ch,01h,0ch,04h,0ah,01h,09h,01h,08h,02h,09h,02h,09h,01h,0ah,01h,09h,02h,08h,01h,09h,01h,09h,04h */
   ;乐曲---国歌
   db 05h,02h,08h,06h,08h,02h,08h,02h,08h,02h,05h,02h,06h,01h,07h,01h,08h,04h,08h,04h
   db 0ah,02h,08h,02h,09h,01h,0ah,01h,0ch,04h,0ch,04h,0ah,02h,0ah,01h,08h,02h,0ah,02h
   db 0ch,02h,0ah,01h,09h,04h,09h,08h,0dh,04h,0ch,04h,09h,04h,0ah,04h,0ch,02h,0ah,02h
   db 0ch,02h,0ah,02h,09h,01h,0ah,01h,08h,04h,0ah,04h,05h,02h,0dh,01h,08h,02h,08h,02h
   db 0ah,02h,0ah,01h,0ch,02h,0ch,02h,09h,02h,09h,01h,09h,01h,06h,04h,09h,04h,05h,02h
   db 08h,04h,08h,02h,0ah,04h,0ah,02h,0ch,08h,08h,02h,0ah,01h,0ch,02h,0ch,02h,0dh,04h
   db 0ch,04h,0ah,02h,08h,01h,0ch,02h,0ch,01h,0ch,01h,0ah,03h,08h,03h,05h,04h,08h,04h
   db 0ah,02h,08h,01h,0ch,02h,0ch,01h,0ch,01h,0ah,03h,08h,03h,05h,04h,08h,04h,05h,04h
   db 08h,04h,05h,04h,08h,04h,08h,04h
   end

友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。