单片机设计音乐播放器程序和仿真图(用汇编语言)?急求~谢谢!!!

单片机设计音乐播放器程序和仿真图(用汇编语言)?急求~谢谢!!!,第1张

NUM EQU 30H

UP EQU P3.6

DN EQU P3.7

ORG     0000H

AJMP    START           Fosc=12MHz

ORG     000BH           T0 中断入口地址

AJMP    INT_T0

ORG     001BH           T1 中断入口地址

AJMP    INT_T1

START:

MOV  SP, #60H

MOV TMOD, #11H

MOV IE, #8AH 

MOV IP, #08H          T1中断优先于T0中断

MOV TH1, #3CH

MOV TL1, #0BH        以上为系统初始化,T=60ms

W1: MOV P2, #01110001B    等待提示"F" ,01110001

LCALL GETKEY

CJNE  A, #0FFH, W1  

MOV  A, B

CJNE    A, #0AH, W2

LCALL   KEY_A            输入键是'A',转KEY_A

SJMP W1

W2: CJNE A, #0BH, W3

LCALL   KEY_B           输入键是'B',转KEY_B

W3: CJNE A, #0CH, W4

LCALL   KEY_C           输入键是'C',转KEY_C

W4: CJNE A, #0DH, W5

LCALL   KEY_D

    SJMP W1                输入键是'D',转KEY_D

W5: CJNE A,#0EH,W6 下一首

INC NUM

MOV A,NUM

CJNE A,#4,W51

W51:

JC W52

MOV NUM,#0

W52:

MOV A,NUM

SJMP D0

W6: CJNE A,#0FH,W7 上一首

MOV A,NUM

JNZ W61

MOV NUM,#4

W61:

DEC NUM

MOV A,NUM

SJMP D0

W7:

SJMP W1

KEY_A:                        从1~4按顺序播放

LCALL MUSIC1      乐曲《我和你》

LCALL MUSIC2       乐曲《万水千山总是情》

LCALL MUSIC3               乐曲《送别》

LCALL MUSIC4               乐曲《北京欢迎您》

RET

KEY_B:                         从1~4循环播放

T11: LCALL KEY_A

SJMP T11

RET

KEY_C:                        循环播放某一乐曲

T3: LCALL GETWORD

CJNE A, #0FFH, T3

MOV A, B

D0:

JNZ D1

SJMP E0

D1: DEC A

JNZ D2

SJMP E1

D2: DEC A

JNZ E3

SJMP E2

E0: LCALL MUSIC1            乐曲《我和你》

SJMP E0

E1: LCALL MUSIC2           乐曲《万水千山总是情》

SJMP E1

E2: LCALL MUSIC3           乐曲《送别》

SJMP E2

E3: LCALL MUSIC4           乐曲《北京欢迎您》

SJMP E3

RET

KEY_D:                      从某一乐曲开始播放,播放完后停止

T2: LCALL GETWORD

CJNE A, #0FFH, T2

MOV A, B

CJNE A, #00H, B1

SJMP C0

B1: CJNE A, #01H, B2

SJMP C1

B2: CJNE A, #02H, C3

SJMP C2

C0: LCALL MUSIC1               乐曲《我和你》

C1: LCALL MUSIC2               乐曲  《万水千山总是情》 

C2: LCALL MUSIC3               乐曲《送别》

C3: LCALL MUSIC4               乐曲《北京欢迎您》

RET

MUSIC1:                         第一首《我和你》

MOV  P2, #00000110B  显示1,00000110

MOV  R5, #11111001B

MOV  52H, #HIGH TABLE10

    MOV  53H, #LOW TABLE10

MOV NUM,#0

LCALL  music

RET

MUSIC2:     第二首《万水千山总是情》

MOV P2, #01011011B           显示2,01011011

MOV R5, #10100100B

MOV  52H, #HIGH TABLE20

    MOV  53H, #LOW TABLE20 

MOV NUM,#1

    LCALL  music

RET

MUSIC3:                   第三首《送别》

MOV P2, #01001111B   显示3,01001111

MOV R5, #10110000B

MOV  52H, #HIGH TABLE30

    MOV  53H, #LOW TABLE30 

MOV NUM,#2

    LCALL  music

RET

MUSIC4:                         第四首《北京欢迎您》

MOV P2, #01100110B     显示4,01100110

MOV R5, #10011001B

MOV  52H, #HIGH TABLE40

    MOV  53H, #LOW TABLE40 

MOV NUM,#3

    LCALL  music

RET 

music: MOV R3,#00H           音乐解码器

NEXT20:

MOV A,P3

ORL A,#0C0H

MOV P3,A

MOV A,P3

CPL A

ANL A,#0C0H

JZ NEXT21

POP ACC

POP ACC

LJMP W1

RET

NEXT21:

     MOV   A, R3

 MOV  DPH, 52H

 MOV  DPL, 53H

 MOVC A, @A+DPTR

 MOV  R2, A

 JZ  STOP

 ANL  A, #0FH

 MOV  R1, A

 MOV  A, R2

 SWAP  A

 ANL  A, #0FH

 JNZ  SING

 CLR  TR0

 JMP  W11

----------------------------------------------------------

SING:

DEC  A

MOV  22H, A

RL   A

MOV  DPTR, #TABLE00

MOVC  A, @A+DPTR

MOV  TH0, A

MOV  21H, A

MOV  A, 22H

RL  A

INC  A

MOVC  A, @A+DPTR

MOV  TL0, A

MOV  20H, A

SETB  TR0

SETB   TR1

W11: 

LCALL  DELAY3

INC  R3

LJMP  NEXT20

-----------------------------------------------------------

STOP:

CLR  TR0

CLR  TR1

    RET

***************************************************

定时器0中断子程序

***************************************************

INT_T0: 

CLR  TR0

MOV  TL0, 20H

MOV  TH0, 21H

CPL  P3.0

SETB TR0

RETI

***************************************************

定时器1中断子程序

***************************************************

INT_T1: 

CLR  TR1

CLR  TR0

LCALL KEY_E

MOV  TH1, #3CH

  MOV  TL1, #0BH

DJNZ  60H, OUT

    MOV  60H, #20

OUT:

SETB TR1

RETI                      

KEY_E:

JB P3.1, L2              中断键盘检测

LCALL DELAY2           消除抖动

JB  P3.1, L2           如果是高电平就跳到L2

JNB   P3.1, $           如果仍然是低电平就执行中断程序

MOV P2, #0111100B        让LED显示E,01111001

L3: JB P3.1, $           检测低电平,直到低电平时才跳出该指令

LCALL DELAY2

JB P3.1, L3

JNB  P3.1, $           如果再来一个高电平才跳出中断

MOV P2,R5

L2: SETB  TR0

RET

GETKEY:                读A B C D键盘子程序 

SA: JB P1.0, SB            读A,是高电平表示没有按键,跳转到SB

LCALL DELAY2

JB P1.0, SA

JNB  P1.0, $

MOV P2, #01110111B     显示A,01110111

MOV R5, #10001000B

MOV A, #0FFH

MOV B, #0AH

RET

SB: JB P1.1, C11              读B,是高电平表示没有按键按下,跳转到C11

LCALL DELAY2

JB P1.1, SB

JNB P1.1, $

MOV P2, #01111100B        显示B,01111100

MOV R5, #10000011B

MOV A, #0FFH

MOV B, #0BH

RET

C11:JB P1.2, ED1        读C

LCALL DELAY2

JB  P1.2, C11

JNB  P1.2, $

MOV P2, #00111001B 显示C,00111001

MOV R5, #11000110B

MOV A, #0FFH

MOV B, #0CH

RET

ED1:

JB P1.3, L0             读D

LCALL DELAY2

JB  P1.3, ED1

JNB   P1.3, $

MOV P2, #01011110B   显示D,01011110

MOV R5, #10100001B

MOV A, #0FFH

MOV B,  #0DH

L0: JB UP,L01

LCALL DELAY2

JB UP,L01

JNB UP,$

MOV A,#0FFH

MOV B,#0EH

RET

L01:

JB DN,L02

LCALL DELAY2

JB DN,L02

JNB DN,$

MOV A,#0FFH

MOV B,#0FH

L02:

RET

GETWORD:                     读音乐序号子程序

S1: JB P1.4, S2         读1键

LCALL DELAY2

JB P1.4, S1

JNB P1.4, $

MOV P2, #00000110B    显示1

MOV R5, #11111001B

MOV A, #0FFH

MOV B, #00H

RET

S2: JB P1.5, S3            读2键

LCALL DELAY2

JB P1.5, S2

JNB P1.5, $

MOV P2, #01011011B    显示2

MOV R5, #10100100B

MOV A, #0FFH

MOV B, #01H

RET

S3: JB P1.6,S4           读3键

LCALL DELAY2

JB P1.6,S3

JNB P1.6,$

MOV P2,#01001111B    显示3

MOV R5,#10110000B

MOV A,#0FFH

MOV B,#02H

RET

S4: JB P1.7, L1           读4键

LCALL DELAY2

JB P1.7, S1

JNB P1.7, $

MOV P2, #01100110B 显示4

MOV R5, #10011001B

MOV A, #0FFH

MOV B, #03H

L1: RET

DELAY:                          延时子程序

        PUSH    0               保存现场

        PUSH    1

        MOV     0, #0H

DELAY1: MOV     1, #0H

        DJNZ    1, $

        DJNZ    0, DELAY1

        POP     1               恢复现场

        POP     0

        RET

DELAY2: MOV 41H, #100        延时子程序2

F1: MOV 42H, #250

DJNZ 42H, $

DJNZ 41H, F1

RET

DELAY3:           延时子程序3 

MOV  R7, #2

W22: MOV  R4, #125

W33: MOV  R0, 248

DJNZ  R0, $

DJNZ  R4, W33

DJNZ  R7, W22

DJNZ  R1, DELAY3

RET

TABLE00:                       频率表

DW 64260,64400,64524,64580          简码值 低音5, 低音6, 低音7,1

DW 64684,64777,64820,64898           简码值 2,3,4,5

DW 64968,65030,65058,65110           简码值 6,7,高音1,高音

        DW 65157,65178,65217            简码值 高音3,高音4,高音5

--------------------------------------------------------------------

第一首《我和你》

--------------------------------------------------------------------

TABLE10: DB 64H,82H,42H,48H

DB 54H,64H,18H

DB 44H,54H,64H,84H

DB 5CH

DB 64H,84H,44H,04H,42H

DB 54H,64H,28H

DB 54H,14H,54H,64H

DB 4CH

DB 98H,88H

DB 98H,48H

DB 64H,24H,64H,84H

DB 5CH

DB 64H,82H,42H,48H

DB 54H,64H, 28H

DB 54H,14H,54H,34H

DB 4CH

DB 00H

--------------------------------------------------------------------

第二首《万水千山总是情》

--------------------------------------------------------------------

TABLE20: DB 64H,74H,84H,04H,82H,94H,84H,6CH

DB 54H,44H,04H,62H,54H,44H,2CH

DB 24H,18H, 44H,54H,64H,84H,94H,64H,5CH

DB 64H,74H,84H,04H,82H,94H,84H,6CH

DB 54H,44H,04H,62H,54H,44H,2CH

DB 24H,18H, 44H,64H,54H,04H,42H,24H,44H,4CH

DB 64H,84H,9CH,0A4H,94H,74H,84H,04H,92H,8CH,64H,88H

DB 64H,84H,9CH,0A4H,0A4H,94H,84H,64H,5CH

DB 64H,74H, 84H,04H,82H,94H,84H,6CH

DB 54H,44H,04H,62H,54H,44H,2CH

DB 24H,18H,44H,64H,54H,42H,24,44H,4CH

DB 00H

--------------------------------------------------------------------

第三首《送别》

--------------------------------------------------------------------

TABLE30:   DB 84H,62H,82H,0B8H

DB 94H,0B2H,92H,88H

DB 84H,42H,52H,64H,52H,44H

        DB 5CH

        DB 84H,62H,82H,0B4H,04H,82H

DB 94H,0B4H, 88H

DB 84H,52H,62H,74H,04H,32H

DB 4CH

DB 94H,0B4H,0B8H

DB 0A4H,92H,0A2H,0B8H

DB 92H,0A2H,0B2H,92H,92H,82H,62H,42H

DB 5CH

DB 84H,62H,82H,0B4H,04H,0A2H

DB 94H,0B4H,88H

DB 84H,52H,62H,74H,04H,32H

DB 4CH

DB 00H

--------------------------------------------------------------------

第四首《北京欢迎您》

--------------------------------------------------------------------

TABLE40:    DB 62H,82H,62H,52H,12H

DB 62H,52H,12H,64H

DB 62H,52H,22H,42H 

DB 62H,54H

DB 52H,42H,22H,42H

DB 52H,62H,82H,52H

DB 62H,92H,82H,12H

DB 52H,44H

DB 52H,42H,22H,42H

DB 52H,62H,82H,52H

DB 62H,92H,82H,82H

DB 68H

DB 52H,62H,52H,42H

DB 82H,92H,64H

DB 22H,62H,64H

DB 54H,64H

DB 64H,84H

DB 0B2H,82H,94H

DB 02H,92H,82H,62H

DB 62H, 82H,88H

DB 00H

END

DW只是定位数据的一个伪指令,本身是无法实现单击按钮播放歌曲的,只能将一些播放歌曲的相关数据比如频率、节奏、旋律等定义出来,举例如下:

NUM EQU 30H

UP EQU P3.6

DN EQU P3.7

ORG     0000H

AJMP    START           Fosc=12MHz

ORG     000BH           T0 中断入口地址

AJMP    INT_T0

ORG     001BH           T1 中断入口地址

AJMP    INT_T1

START:

MOV  SP, #60H

MOV TMOD, #11H

MOV IE, #8AH

MOV IP, #08H          T1中断优先于T0中断

MOV TH1, #3CH

MOV TL1, #0BH        以上为系统初始化,T=60ms

W1:                         第一首《我和你》

MOV  P2, #00000110B  显示1,00000110

MOV  R5, #11111001B

MOV  52H, #HIGH TABLE10

MOV  53H, #LOW TABLE10

MOV NUM,#0

music: MOV R3,#00H           音乐解码器

NEXT20:

MOV A,P3

ORL A,#0C0H

MOV P3,A

MOV A,P3

CPL A

ANL A,#0C0H

JZ NEXT21

LJMP W1

NEXT21:

MOV   A, R3

MOV  DPH, 52H

MOV  DPL, 53H

MOVC A, @A+DPTR

MOV  R2, A

JZ  STOP

ANL  A, #0FH

MOV  R1, A

MOV  A, R2

SWAP  A

ANL  A, #0FH

JNZ  SING

CLR  TR0

JMP  W11

----------------------------------------------------------

SING:

DEC  A

MOV  22H, A

RL   A

MOV  DPTR, #TABLE00

MOVC  A, @A+DPTR

MOV  TH0, A

MOV  21H, A

MOV  A, 22H

RL  A

INC  A

MOVC  A, @A+DPTR

MOV  TL0, A

MOV  20H, A

SETB  TR0

SETB   TR1

W11:

LCALL  DELAY3

INC  R3

LJMP  NEXT20

-----------------------------------------------------------

STOP:

CLR  TR0

CLR  TR1

ljmp start

***************************************************

定时器0中断子程序

***************************************************

INT_T0:

CLR  TR0

MOV  TL0, 20H

MOV  TH0, 21H

CPL  P3.0

SETB TR0

RETI

***************************************************

定时器1中断子程序

***************************************************

INT_T1:

CLR  TR1

CLR  TR0

LCALL KEY_E

MOV  TH1, #3CH

MOV  TL1, #0BH

DJNZ  60H, OUT

MOV  60H, #20

OUT:

SETB TR1

RETI

KEY_E:

JB P3.1, L2              中断键盘检测

LCALL DELAY2           消除抖动

JB  P3.1, L2           如果是高电平就跳到L2

JNB   P3.1, $           如果仍然是低电平就执行中断程序

MOV P2, #0111100B        让LED显示E,01111001

L3: JB P3.1, $           检测低电平,直到低电平时才跳出该指令

LCALL DELAY2

JB P3.1, L3

JNB  P3.1, $           如果再来一个高电平才跳出中断

MOV P2,R5

L2: SETB  TR0

RET

GETKEY:                读A B C D键盘子程序

SA: JB P1.0, SB            读A,是高电平表示没有按键,跳转到SB

LCALL DELAY2

JB P1.0, SA

JNB  P1.0, $

MOV P2, #01110111B     显示A,01110111

MOV R5, #10001000B

MOV A, #0FFH

MOV B, #0AH

RET

SB: JB P1.1, C11              读B,是高电平表示没有按键按下,跳转到C11

LCALL DELAY2

JB P1.1, SB

JNB P1.1, $

MOV P2, #01111100B        显示B,01111100

MOV R5, #10000011B

MOV A, #0FFH

MOV B, #0BH

RET

C11:JB P1.2, ED1        读C

LCALL DELAY2

JB  P1.2, C11

JNB  P1.2, $

MOV P2, #00111001B 显示C,00111001

MOV R5, #11000110B

MOV A, #0FFH

MOV B, #0CH

RET

ED1:

JB P1.3, L0             读D

LCALL DELAY2

JB  P1.3, ED1

JNB   P1.3, $

MOV P2, #01011110B   显示D,01011110

MOV R5, #10100001B

MOV A, #0FFH

MOV B,  #0DH

L0: JB UP,L01

LCALL DELAY2

JB UP,L01

JNB UP,$

MOV A,#0FFH

MOV B,#0EH

RET

L01:

JB DN,L02

LCALL DELAY2

JB DN,L02

JNB DN,$

MOV A,#0FFH

MOV B,#0FH

L02:

RET

GETWORD:                     读音乐序号子程序

S1: JB P1.4, S2         读1键

LCALL DELAY2

JB P1.4, S1

JNB P1.4, $

MOV P2, #00000110B    显示1

MOV R5, #11111001B

MOV A, #0FFH

MOV B, #00H

RET

S2: JB P1.5, S3            读2键

LCALL DELAY2

JB P1.5, S2

JNB P1.5, $

MOV P2, #01011011B    显示2

MOV R5, #10100100B

MOV A, #0FFH

MOV B, #01H

RET

S3: JB P1.6,S4           读3键

LCALL DELAY2

JB P1.6,S3

JNB P1.6,$

MOV P2,#01001111B    显示3

MOV R5,#10110000B

MOV A,#0FFH

MOV B,#02H

RET

S4: JB P1.7, L1           读4键

LCALL DELAY2

JB P1.7, S1

JNB P1.7, $

MOV P2, #01100110B 显示4

MOV R5, #10011001B

MOV A, #0FFH

MOV B, #03H

L1: RET

DELAY:                          延时子程序

PUSH    0               保存现场

PUSH    1

MOV     0, #0H

DELAY1: MOV     1, #0H

DJNZ    1, $

DJNZ    0, DELAY1

POP     1               恢复现场

POP     0

RET

DELAY2: MOV 41H, #100        延时子程序2

F1: MOV 42H, #250

DJNZ 42H, $

DJNZ 41H, F1

RET

DELAY3:           延时子程序3

MOV  R7, #2

W22: MOV  R4, #125

W33: MOV  R0, 248

DJNZ  R0, $

DJNZ  R4, W33

DJNZ  R7, W22

DJNZ  R1, DELAY3

RET

TABLE00:                       频率表

DW 64260,64400,64524,64580          简码值 低音5, 低音6, 低音7,1

DW 64684,64777,64820,64898           简码值 2,3,4,5

DW 64968,65030,65058,65110           简码值 6,7,高音1,高音

DW 65157,65178,65217            简码值 高音3,高音4,高音5

第一首《我和你》

TABLE10: DB 64H,82H,42H,48H

DB 54H,64H,18H

DB 44H,54H,64H,84H

DB 5CH

DB 64H,84H,44H,04H,42H

DB 54H,64H,28H

DB 54H,14H,54H,64H

DB 4CH

DB 98H,88H

DB 98H,48H

DB 64H,24H,64H,84H

DB 5CH

DB 64H,82H,42H,48H

DB 54H,64H, 28H

DB 54H,14H,54H,34H

DB 4CH

DB 00H

END

NUM EQU 30H

UP EQU P3.6

DN EQU P3.7

ORG 0000H

AJMPSTART Fosc=12MHz

ORG 000BH T0 中断入口地址

AJMPINT_T0

ORG 001BH T1 中断入口地址

AJMPINT_T1

START:

MOV SP, #60H

MOV TMOD, #11H

MOV IE, #8AH

MOV IP, #08H T1中断优先于T0中断

MOV TH1, #3CH

MOV TL1, #0BH 以上为系统初始化,T=60ms

W1: MOV P2, #01110001B等待提示"F" ,01110001

LCALL GETKEY

CJNE A, #0FFH, W1

MOV A, B

CJNEA, #0AH, W2

LCALL KEY_A输入键是'A',转KEY_A

SJMP W1

W2: CJNE A, #0BH, W3

LCALL KEY_B 输入键是'B',转KEY_B

W3: CJNE A, #0CH, W4

LCALL KEY_C 输入键是'C',转KEY_C

W4: CJNE A, #0DH, W5

LCALL KEY_D

SJMP W1输入键是'D',转KEY_D

W5: CJNE A,#0EH,W6 下一首

INC NUM

MOV A,NUM

CJNE A,#4,W51

W51:

JC W52

MOV NUM,#0

W52:

MOV A,NUM

SJMP D0

W6: CJNE A,#0FH,W7 上一首

MOV A,NUM

JNZ W61

MOV NUM,#4

W61:

DEC NUM

MOV A,NUM

SJMP D0

W7:

SJMP W1

KEY_A:从1~4按顺序播放

LCALL MUSIC1 乐曲《我和你》

LCALL MUSIC2 乐曲《万水千山总是情》

LCALL MUSIC3 乐曲《送别》

LCALL MUSIC4 乐曲《北京欢迎您》

RET

KEY_B: 从1~4循环播放

T11: LCALL KEY_A

SJMP T11

RET

KEY_C:循环播放某一乐曲

T3: LCALL GETWORD

CJNE A, #0FFH, T3

MOV A, B

D0:

JNZ D1

SJMP E0

D1: DEC A

JNZ D2

SJMP E1

D2: DEC A

JNZ E3

SJMP E2

E0: LCALL MUSIC1乐曲《我和你》

SJMP E0

E1: LCALL MUSIC2 乐曲《万水千山总是情》

SJMP E1

E2: LCALL MUSIC3 乐曲《送别》

SJMP E2

E3: LCALL MUSIC4 乐曲《北京欢迎您》

SJMP E3

RET

KEY_D: 从某一乐曲开始播放,播放完后停止

T2: LCALL GETWORD

CJNE A, #0FFH, T2

MOV A, B

CJNE A, #00H, B1

SJMP C0

B1: CJNE A, #01H, B2

SJMP C1

B2: CJNE A, #02H, C3

SJMP C2

C0: LCALL MUSIC1 乐曲《我和你》

C1: LCALL MUSIC2 乐曲 《万水千山总是情》

C2: LCALL MUSIC3 乐曲《送别》

C3: LCALL MUSIC4 乐曲《北京欢迎您》

RET

MUSIC1: 第一首《我和你》

MOV P2, #00000110B显示1,00000110

MOV R5, #11111001B

MOV 52H, #HIGH TABLE10

MOV 53H, #LOW TABLE10

MOV NUM,#0

LCALL music

RET

MUSIC2: 第二首《万水千山总是情》

MOV P2, #01011011B 显示2,01011011

MOV R5, #10100100B

MOV 52H, #HIGH TABLE20

MOV 53H, #LOW TABLE20

MOV NUM,#1

LCALL music

RET

MUSIC3:第三首《送别》

MOV P2, #01001111B显示3,01001111

MOV R5, #10110000B

MOV 52H, #HIGH TABLE30

MOV 53H, #LOW TABLE30

MOV NUM,#2

LCALL music

RET

MUSIC4: 第四首《北京欢迎您》

MOV P2, #01100110B 显示4,01100110

MOV R5, #10011001B

MOV 52H, #HIGH TABLE40

MOV 53H, #LOW TABLE40

MOV NUM,#3

LCALL music

RET

music: MOV R3,#00H音乐解码器

NEXT20:

MOV A,P3

ORL A,#0C0H

MOV P3,A

MOV A,P3

CPL A

ANL A,#0C0H

JZ NEXT21

POP ACC

POP ACC

LJMP W1

RET

NEXT21:

MOV A, R3

MOV DPH, 52H

MOV DPL, 53H

MOVC A, @A+DPTR

MOV R2, A

JZ STOP

ANL A, #0FH

MOV R1, A

MOV A, R2

SWAP A

ANL A, #0FH

JNZ SING

CLR TR0

JMP W11

----------------------------------------------------------

SING:

DEC A

MOV 22H, A

RL A

MOV DPTR, #TABLE00

MOVC A, @A+DPTR

MOV TH0, A

MOV 21H, A

MOV A, 22H

RL A

INC A

MOVC A, @A+DPTR

MOV TL0, A

MOV 20H, A

SETB TR0

SETB TR1

W11:

LCALL DELAY3

INC R3

LJMP NEXT20

-----------------------------------------------------------

STOP:

CLR TR0

CLR TR1

RET

***************************************************

定时器0中断子程序

***************************************************

INT_T0:

CLR TR0

MOV TL0, 20H

MOV TH0, 21H

CPL P3.0

SETB TR0

RETI

***************************************************

定时器1中断子程序

***************************************************

INT_T1:

CLR TR1

CLR TR0

LCALL KEY_E

MOV TH1, #3CH

MOV TL1, #0BH

DJNZ 60H, OUT

MOV 60H, #20

OUT:

SETB TR1

RETI

KEY_E:

JB P3.1, L2 中断键盘检测

LCALL DELAY2消除抖动

JB P3.1, L2如果是高电平就跳到L2

JNB P3.1, $如果仍然是低电平就执行中断程序

MOV P2, #0111100B让LED显示E,01111001

L3: JB P3.1, $检测低电平,直到低电平时才跳出该指令

LCALL DELAY2

JB P3.1, L3

JNB P3.1, $如果再来一个高电平才跳出中断

MOV P2,R5

L2: SETB TR0

RET

GETKEY: 读A B C D键盘子程序

SA: JB P1.0, SB 读A,是高电平表示没有按键,跳转到SB

LCALL DELAY2

JB P1.0, SA

JNB P1.0, $

MOV P2, #01110111B 显示A,01110111

MOV R5, #10001000B

MOV A, #0FFH

MOV B, #0AH

RET

SB: JB P1.1, C11 读B,是高电平表示没有按键按下,跳转到C11

LCALL DELAY2

JB P1.1, SB

JNB P1.1, $

MOV P2, #01111100B显示B,01111100

MOV R5, #10000011B

MOV A, #0FFH

MOV B, #0BH

RET

C11:JB P1.2, ED1 读C

LCALL DELAY2

JB P1.2, C11

JNB P1.2, $

MOV P2, #00111001B 显示C,00111001

MOV R5, #11000110B

MOV A, #0FFH

MOV B, #0CH

RET

ED1:

JB P1.3, L0 读D

LCALL DELAY2

JB P1.3, ED1

JNB P1.3, $

MOV P2, #01011110B显示D,01011110

MOV R5, #10100001B

MOV A, #0FFH

MOV B, #0DH

L0: JB UP,L01

LCALL DELAY2

JB UP,L01

JNB UP,$

MOV A,#0FFH

MOV B,#0EH

RET

L01:

JB DN,L02

LCALL DELAY2

JB DN,L02

JNB DN,$

MOV A,#0FFH

MOV B,#0FH

L02:

RET

GETWORD: 读音乐序号子程序

S1: JB P1.4, S2 读1键

LCALL DELAY2

JB P1.4, S1

JNB P1.4, $

MOV P2, #00000110B 显示1

MOV R5, #11111001B

MOV A, #0FFH

MOV B, #00H

RET

S2: JB P1.5, S3 读2键

LCALL DELAY2

JB P1.5, S2

JNB P1.5, $

MOV P2, #01011011B 显示2

MOV R5, #10100100B

MOV A, #0FFH

MOV B, #01H

RET

S3: JB P1.6,S4读3键

LCALL DELAY2

JB P1.6,S3

JNB P1.6,$

MOV P2,#01001111B 显示3

MOV R5,#10110000B

MOV A,#0FFH

MOV B,#02H

RET

S4: JB P1.7, L1读4键

LCALL DELAY2

JB P1.7, S1

JNB P1.7, $

MOV P2, #01100110B 显示4

MOV R5, #10011001B

MOV A, #0FFH

MOV B, #03H

L1: RET

DELAY: 延时子程序

PUSH0 保存现场

PUSH1

MOV 0, #0H

DELAY1: MOV 1, #0H

DJNZ1, $

DJNZ0, DELAY1

POP 1 恢复现场

POP 0

RET

DELAY2: MOV 41H, #100延时子程序2

F1: MOV 42H, #250

DJNZ 42H, $

DJNZ 41H, F1

RET

DELAY3: 延时子程序3

MOV R7, #2

W22: MOV R4, #125

W33: MOV R0, 248

DJNZ R0, $

DJNZ R4, W33

DJNZ R7, W22

DJNZ R1, DELAY3

RET

TABLE00: 频率表

DW 64260,64400,64524,64580 简码值 低音5, 低音6, 低音7,1

DW 64684,64777,64820,64898 简码值 2,3,4,5

DW 64968,65030,65058,65110 简码值 6,7,高音1,高音

DW 65157,65178,65217简码值 高音3,高音4,高音5

--------------------------------------------------------------------

第一首《我和你》

--------------------------------------------------------------------

TABLE10: DB 64H,82H,42H,48H

DB 54H,64H,18H

DB 44H,54H,64H,84H

DB 5CH

DB 64H,84H,44H,04H,42H

DB 54H,64H,28H

DB 54H,14H,54H,64H

DB 4CH

DB 98H,88H

DB 98H,48H

DB 64H,24H,64H,84H

DB 5CH

DB 64H,82H,42H,48H

DB 54H,64H, 28H

DB 54H,14H,54H,34H

DB 4CH

DB 00H

--------------------------------------------------------------------

第二首《万水千山总是情》

--------------------------------------------------------------------

TABLE20: DB 64H,74H,84H,04H,82H,94H,84H,6CH

DB 54H,44H,04H,62H,54H,44H,2CH

DB 24H,18H, 44H,54H,64H,84H,94H,64H,5CH

DB 64H,74H,84H,04H,82H,94H,84H,6CH

DB 54H,44H,04H,62H,54H,44H,2CH

DB 24H,18H, 44H,64H,54H,04H,42H,24H,44H,4CH

DB 64H,84H,9CH,0A4H,94H,74H,84H,04H,92H,8CH,64H,88H

DB 64H,84H,9CH,0A4H,0A4H,94H,84H,64H,5CH

DB 64H,74H, 84H,04H,82H,94H,84H,6CH

DB 54H,44H,04H,62H,54H,44H,2CH

DB 24H,18H,44H,64H,54H,42H,24,44H,4CH

DB 00H

--------------------------------------------------------------------

第三首《送别》

--------------------------------------------------------------------

TABLE30: DB 84H,62H,82H,0B8H

DB 94H,0B2H,92H,88H

DB 84H,42H,52H,64H,52H,44H

DB 5CH

DB 84H,62H,82H,0B4H,04H,82H

DB 94H,0B4H, 88H

DB 84H,52H,62H,74H,04H,32H

DB 4CH

DB 94H,0B4H,0B8H

DB 0A4H,92H,0A2H,0B8H

DB 92H,0A2H,0B2H,92H,92H,82H,62H,42H

DB 5CH

DB 84H,62H,82H,0B4H,04H,0A2H

DB 94H,0B4H,88H

DB 84H,52H,62H,74H,04H,32H

DB 4CH

DB 00H

--------------------------------------------------------------------

第四首《北京欢迎您》

--------------------------------------------------------------------

TABLE40:DB 62H,82H,62H,52H,12H

DB 62H,52H,12H,64H

DB 62H,52H,22H,42H

DB 62H,54H

DB 52H,42H,22H,42H

DB 52H,62H,82H,52H

DB 62H,92H,82H,12H

DB 52H,44H

DB 52H,42H,22H,42H

DB 52H,62H,82H,52H

DB 62H,92H,82H,82H

DB 68H

DB 52H,62H,52H,42H

DB 82H,92H,64H

DB 22H,62H,64H

DB 54H,64H

DB 64H,84H

DB 0B2H,82H,94H

DB 02H,92H,82H,62H

DB 62H, 82H,88H

DB 00H

END


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/11284229.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-15
下一篇 2023-05-15

发表评论

登录后才能评论

评论列表(0条)

保存