Single chip electronic piano circuit diagram and source code

Publisher:blq0681Latest update time:2015-11-02 Source: eefocusKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
[Reprint] Single-chip electronic piano circuit diagram and source code

Experimental simulation diagram

Source code: (The playing part of the code is temporarily removed, please forgive me, please leave a message if you need it, please indicate the source if you reprint it, thank you!)

   DUAN EQU 0c000H
   WEI EQU  0a000H 
   LED0 EQU 8000H
 ORG 0000H          ;Reset address   
    LJMP MAIN          ;Jump to main program
 ORG 0003H          ;External interrupt 0 entry address
 LJMP INT00    ;Jump to external interrupt 0 service program
 ORG 000BH          ;T0 interrupt entry
 LJMP TIM0          ;Jump to T0 interrupt service program
       
 
 ORG 0030H          ;Main program entry address   
MAIN:

MOV DPTR,#LED0
MOV A,#00H
MOVX @DPTR,A 
  
   
   MOV TMOD,#01H      ;Write T0 control word, 16-bit timing mode
 SETB IT0           ;External interrupt is falling edge trigger
 MOV  IE,#83H       ;Open interrupt
 MOV  30H,#00H      ;Get the musical notation code pointer
 MOV  R6,#0FFH       ;Select the number of cycles of music rhythm light
 CLR  23H           ;Function selection flag 00: keyboard 01: music

NEXT:   CLR  TR0
       JNB  23H,KEYPLAY   ; if the flag is 0, go to the keyboard program
       SETB P2.2
  MOV  A,30H         ; load the musical notation code pointer into A
       JNB P0.1,START1    ; otherwise check which song to play    
       JNB P0.2,START2
       JNB P0.3,START3
       LJMP NEXT

;Determine the base address of different songs
START1:

 MOV  DPTR,#TABLE   ; Get the musical notation code from TABLE
 MOV 60H,DPH
 MOV 61H,DPL
 MOV A,#00H
       LJMP NEXT1
START2:

 MOV  DPTR,#TABLE2  ; Get the musical notation code from TABLE2
  MOV 60H,DPH
 MOV 61H,DPL
  MOV A,#01H
       LJMP NEXT1
START3:

 MOV  DPTR,#TABLE3  ; Get the musical notation code from TABLE
  MOV 60H,DPH
 MOV 61H,DPL
  MOV A,#02H
       LJMP NEXT1

;Keyboard playing program entry
KEYPLAY:    ;Keyboard program entry
   SETB P2.1
 CLR P2.2
 JNB P0.4, LOWTONE     ;Query whether it is high note or other notes
 JNB P0.5, MIDDLETONE
 JNB P0.6, HIGHTONE
 LJMP NEXT           ;If high, medium and low notes are not selected, query again


; Determine the base address of high, medium and low frequencies
LOWTONE:
 MOV DPTR,#LOWTABLE   ; Assign base address value
 MOV 50H,DPH
 MOV 51H,DPL
 LJMP KEY      ; Jump to key query program

MIDDLETONE:
        MOV DPTR,#MIDDLETABLE
  MOV 50H,DPH
 MOV 51H,DPL
 LJMP KEY

HIGHTONE: 
  MOV DPTR,#HIGHTABLE
  MOV 50H,DPH
 MOV 51H,DPL
  LJMP KEY


;Song playing program
NEXT1: MOV DPTR,#SEG7
  MOVC A,@A+DPTR
 MOV DPTR,#DUAN
    MOVX @DPTR,A
    MOV DPTR,#WEI
 MOV A,#000BH
   MOVX @DPTR,A
   MOV DPH,60H
 MOV DPL,61H MOV
 A,30H
   MOVC A,@A+DPTR
 MOV  R2,A          ;The obtained musical notation code is temporarily stored in R2
 JZ   END0          ;Is the end code 00H obtained?
 ANL  A,#0FH        ;If not, get the beat code
 MOV  R5,A          ;The beat code is stored in R5
 MOV  A,R2          ;Load the musical notation code into A
 SWAP A             ;Exchange the high and low 4 bits
 ANL  A,#0FH        ;Get the note code
 JNZ  SING          ;Is the obtained note code 0?
 CLR  TR0           ;If yes, do not make a sound
 JMP  D1           ;Jump to D1

SING:   DEC             ; get the note code minus 1 (excluding 0)
 MOV  22H,A         ; store in 22H unit
 RL              ; multiply by 2
 MOV  DPTR,#TABLE1  ; get the relative high byte value from TABLE1
 MOVC A,@A+DPTR
 MOV  TH0,A         ; load the high byte obtained into TH0 and 21H unit
 MOV  21H,A
 MOV  A,22H         ; then load the note code
       Rl              ; multiply by 2
 INC             ; add 1
 MOVC A,@A+DPTR     ; get the relative low byte value from TABLE1
 MOV  TL0,A         ; load the high byte obtained into TL0 and 20H unit
 MOV  20H,A
 SETB TR0           ; start T0
D1:     LCALL DELAY        ; basic unit time 1/4 beat, delay 187 milliseconds
 INC  30H           ; get the simple musical notation code pointer plus 1
 LJMP NEXT          ; get the next code
END0:   CLR  TR0           ; stop T0
 CLR 30H            ; clear simple pointer
 LJMP NEXT          ; repeat the loop

[page]
;Key query program
KEY:                ;Judge which tone key is pressed
 JNB P1.0, M0        ;They are DO, RE, ME....
 JNB P1.1, M1
 JNB P1.2, M2
 JNB P1.3, M3
 JNB P1.4, M4
 JNB P1.5, M5
 JNB P1.6, M6
 LJMP NEXT          ;If no key is pressed, jump to loop query

;Key software anti-shake program
M0:     
 LCALL DELAY1       ;Delay for a period of time to determine whether the key is still pressed. If so, jump to the offset determination program
 JNB P1.0,M00
 SJMP  KEY
M1:     
 LCALL DELAY1
 JNB P1.1,M11
 SJMP  KEY
M2:     
 LCALL DELAY1
 JNB P1.2,M22
 SJMP  KEY
M3:     
 LCALL DELAY1
 JNB P1.3,M33
 SJMP  KEY
M4:  LCALL    
 DELAY1
 JNB P1.4,M44
 SJMP  KEY
M5:     
 LCALL DELAY1
 JNB P1.5,M55
 SJMP  KEY
M6:     
 LCALL DELAY1
 JNB P1.6,M66
 SJMP  KEY


; Determine the offset address of the key program
M00:
 MOV A,#00H
 LJMP PLAY
M11:
 MOV A,#01H
 LJMP  PLAY
M22:
 MOV A,#02H
 LJMP  PLAY
M33:
 MOV A,#03H
 LJMP  PLAY
M44:
 MOV A,#04H
 LJMP  PLAY 
M55:
 MOV A,#05H
 LJMP  PLAY
M66:
 MOV A,#06H
 LJMP  PLAY
       

;Key tone playing program

 


;Note corresponding timer initial value table:    
TABLE1:
DW 64580,64684,64777,64820
DW 64898,64968,65030,64260
DW 64400,64524,65058,63835,64021

LOWTABLE:
DW 63628,63835,64021,64103,64260,64400,64524
MIDDLETABLE:
DW 64580 ,64684,64777,64820,64898,64968,65030
HIGHTABLE:
DW 65058,65110,65157,65178,65217,65252,65283
SEG7:
DB 06H, 5BH, 4FH,66H, 6DH, 7DH,07H

;音符节拍表:   
TABLE: 
DB 02H,82H
DB 16H,32H,54H,02H,52H
DB 0A6H,32H,54H,02H,52H
DB 64H,74H,0B6H,64H
DB 52H,5CH,32H,22H
DB 16H,12H,14H,32H,22H
DB 16H,12H,14H,22H,32H
DB 26H,12H,94H,22H,32H
DB 2CH
DB 32H,52H
DB 36H,22H,14H,54H
DB 0ACH,92H,0A2H
DB 96H,0A2H,96H,82H
DB 3CH,54H
DB 36H,22H,14H,54H
DB 0ACH,92H,0A2H
DB 16H,12H,14H,22H,32H
DB 2CH,02H,82H
DB 16H,32H,56H,12H
DB 0A6H,32H,56H,52H
DB 66H,72H,0B6H,62H
DB 62H,52H,58H,32H,22H
DB 16H,12H,14H,32H,22H
DB 16H,12H,14H,22H,32H
DB 26H,92H,0A4H,12H,22H
DB 1CH
DB 00
TABLE2:
DB 88h,14h,24h,36H,42H,34H,14H,28H,14H,94H
DB 1fH,88H,14H,24H,34H,32H,42H,54H,14H
DB 46H,32H,54H,22H,32H,32H,22H,2CH,38H,54H,74H
DB 76H,62H,68H,54H,52H,62H,74H,62H,52H,3fH
DB 46H,42H,54H,64H,54H,42H,32H,28H,0a4H,0a2H
DB 92H,84H,94H,1fH,0b8H,68H,46H,52H,68H
DB 74H,72H,72H,74H,62H,52H,3fH,0b8H,68H
DB 46H,52H,68H,64H,62H,62H,64H,42H,32H,2fH
DB 58H,14H,24H,36H,42H,34H,12H,12H,26H,22H,24H,22H,12H
DB 94H,9cH,0a8H,0a6H,92H,84H,64H,54H,22H,22H,46H,42H,44H,32H,22H,5fH
DB 00
TABLE3:
DB 82H,92H,12H,14H,12H,14H,92H,82H,12H,14H,22H,14H,92H,12H,22H,24H
DB 22H,24H,12H,92H,22H,24H,32H,24H,32H,52H,62H,54H,52H,64H,52H,32H
DB 22H,32H,22H,12H,94H,82H,92H,12H,14H,12H,14H,94H,1cH
DB 82H,92H,12H,14H,12H,14H,92H,82H,12H,14H,22H,14H,92H,12H,22H,24H
DB 22H,24H,12H,92H,22H,24H,32H,24H,32H,52H,62H,54H,52H,64H,52H,32H
DB 22H,32H,22H,12H,94H,82H,92H,12H,14H,12H,14H,22H,12H,1cH,32H,52H
DB 62H,64H,62H,64H,0b2H,62H,52H,54H,62H,54H,32H,22H
DB 12H,14H,12H,14H,24H,3cH,32H,22H,12H,14H,12H,14H,0b2H,62H,52H,54H,62H,54H,32H,52H
DB 66H,0b2H,0b4H,62H,52H,5cH,32H,52H,62H,64H,62H,64H,0b2H,62H,52H,54H
DB 62H,54H,32H,22H,12H,14H,12H,14H,54H,3cH,32H,22H,12H,14H,12H,14H,22H,32H
DB 52H,54H,32H,54H,32H,52H,6fH,04H,02H,92H,32H,24H,12H,1fH
DB 00


END

Keywords:MCU Reference address:Single chip electronic piano circuit diagram and source code

Previous article:Some keywords in 51 single chip microcomputer (continuously updated)
Next article:Programming an 8-way Color Light Control System Using Assembly Language

Latest Microcontroller Articles
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号