Music Box developed by single chip microcomputer (Happy birthday)

Source: Internet
Author: User

 

 

Seven speakers-Happy Birthday.

Org 0000 h
Ajmp main
Org 000bh
JMP tim0
Org 0030 H
 
; Main program
Main: mov tmod, #01 H; set the time mode
MoV IE, #82 h; on interrupt
Start0: mov 30 h, #00 h;
Next: mov A, 30 h
MoV dptr, # Table
Movc A, @ A + dptr; look up the table to take the tone and beat
MoV R2,
JZ end0; 0, not processed.
Anl a, # 0fh
MoV R5, A; store the beats to R5
MoV A, r2
Swap
Anl a, # 0fh
Jnz sing; determines whether to play based on the tone.
CLR tr0
JMP d1
Sing: Dec
MoV 22 h, A; Save the tone to 22 h.
RL
MoV dptr, # Table1
Movc A, @ A + dptr; determine the initial timer value based on the tone.
MoV th0, A; put th0
MoV 21 h,
MoV A, 22 h
RL
INC
Movc A, @ A + dptr
MoV tl0, A; put in tl0
MoV 20 h,
SETB tr0; Start Time
D1: Call Delay
INC 30 h
JMP next
End0: CLR tr0
JMP start0

; The timer interrupts the service program.
Tim0: Push ACC
Push psw
MoV tl0, 20 h; re-assigned initial value.
MoV th0, 21 h
Cpl limit 7
Pop psw
Pop ACC
RETI

Delay: mov R7, #02 h; latency subroutine
D2: mov R4, #187
D3: mov R3, #248
Djnz R3, $
Djnz R4, D3
Djnz R7, D2
Djnz R5, delay
RET

Determine the initial value of the tone.
Table1: DW 64260,64400, 64524,64580
DW 64684,64777, 64820,64898
DW 64968,30,58,65110
DW 65157,65178, 65217

The table that determines the tone and the beat. Different songs are only different in this table.

Table: DB 82 H, 01 H, 81 h, 94 H, 84 h, 0b4h, 0a4h, 04 H, 82 H, 01 H, 81 h, 94 H, 84 h, 0c4h, 0b4h, 04 H; 1
DB 82 H, 01 H, 81 h, 0f4h, 0d4h, 0b4h, 0a4h, 94 H, 0e2h, 01 H, 0e1h, 0d4h, 0b4h, 0c4h, 0b4h, 04 H; 2
DB 82 H, 01 H, 81 h, 94 H, 84 h, 0b4h, 0a4h, 04 H, 82 H, 01 H, 81 h, 94 H, 84 h, 0c4h, 0b4h, 04 H; 3
DB 82 H, 01 H, 81 h, 0f4h, 0d4h, 0b4h, 0a4h, 94 H, 0e2h, 01 H, 0e1h, 0d4h, 0b4h, 0c4h, 0b4h, 04 H, 00; 4
End

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.