"Only Mother is Good in the World" 51 MCU Assembly Language Program

Publisher:丹青妙手Latest update time:2015-10-10 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
; "Only Mother Is Good in the World" 51 MCU Assembly Language Program

      ;2007-5-22     Author: Xu Xuejun
      ;Note that there is a 51 single-chip C language program corresponding to it
      ;This program has been debugged on the hardware
      ;The single-chip crystal oscillator of this program uses 11.0592MHz Z
SPK BIT P1.7
ORG 0000H
LJMP MAIN
ORG 000BH
LJMP TIMER0
MAIN:
MOV TMOD,#01H ;Set CT0 timing working mode 1
MOV IE,#82H     ;CPU opens interrupt, CT0 opens interrupt
       MOV R5,#0
PLAY:   
       MOV A,R5   
       MOV DPTR,#TABLE1
       MOVC A,@A+DPTR
       MOV     R6,A
       INC R5
       MOV A,R5
       MOVC A,@A+DPTR
       MOV     R7,A
        INC R5
       MOV A,R5
       MOVC A,@A+DPTR
       JNZ PLAY1
       MOV R5,#0
       LJMP PLAY
PLAY1:
       MOV B,#3
       MUL AB
       MOV R2,A
       MOV B,#7
       MOV A,R7
       MUL AB
       ADD A,R6
       DEC A
       MOV R6,A
       MOV DPTR,#FREQH
       MOVC A,@A+DPTR
       MOV R4,A
       MOV DPTR,#FREQL
       MOV A,R6
       MOVC A,@A+DPTR
       MOV R3,A
       LCALL SONG     ;Call the note player program
INC R5
SJMP PLAY     ;Move to the next note OV R3,A
  
SONG:
MOV TH0,R4
MOV TL0,R3
SETB TR0     ;Start CT0 (start singing a certain note)
DELAY:
MOV R1,#85H     ;Beat delay (how long a certain note is sung)
DEL1:
MOV R0,#0FFH
DEL0:
NOP
NOP
NOP
DJNZ R0,DEL0
DJNZ R1,DEL1
DJNZ R2,DELAY
CLR TR0     ; Disable CT0 (stop after a certain note is sung)
RET
TIMER0:       ; Timer interrupt program (used to determine how high a certain note is sung)
CPL SPK
MOV TH0,R4
MOV TL0,R3
RETI

     TABLE1:
      DB     6,2,3,     5,2,1,     3,2,2, 5,2,2, 1,3,2, 6,2,1, 5,2,1
      DB     6,2,4 ,     3,2,2,     5,2,1, 6,2,1, 5,2,2, 3,2,2, 1,2,1
      DB     6,1,1,     5,2,1,     3 ,2,1, 2,2,4, 2,2,3, 3,2,1, 5,2,2
      DB     5,2,1,     6,2,1,     3,2,2, 2,2 ,2, 1,2,4, 5,2,3, 3,2,1
      DB     2,2,1,     1,2,1,     6,1,1, 1,2,1, 5,1,6 , 0,0,0
    ; Scale frequency table
FREQH:
          DB        0F2H,0F3H,0F5H,0F5H,0F6H,0F7H,0F8H
          DB        0F9H,0F9H,0FAH,0FAH,0FBH,0FBH,0FCH, 0FCH;1,2,3,4,5,6,7, 8,i
          DB             0FCH,0FDH,0FDH,0FDH,0FDH,0FEH
          DB        0FEH,0FEH,0FEH,0FEH,0FEH,0FEH,0FFH
FREQL:
          DB        42H, 0C1H, 17H, 0B6H,0D0H,0D1H,0B6H
          DB        21H, 0E1H, 8CH, 0D8H,68H, 0E9H, 5BH,     8FH ;1,2,3,4,5,6,7,8,i
          DB             0EEH,44H,      6BH,0B4H,0F4H,2DH
          DB        47H, 77H,0A2H,0B6H,0DAH,0FAH,16H
          END

Reference address:"Only Mother is Good in the World" 51 MCU Assembly Language Program

Previous article:Music player program based on 51 single chip microcomputer
Next article:"Only Mother is Good in the World" 51 MCU C language program

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号