单片机电子琴电路图及源程序代码 第3页
JNB P2.0, NEXT
INC R0
JNB P2.1, NEXT
INC R0
JNB P2.2, NEXT
INC R0
JNB P2.3, NEXT
INC R0
JNB P2.4, NEXT
INC R0
JNB P2.5, NEXT
INC R0
JNB P2.6, NEXT
SJMP NOT
NEXT: MOV P0, R0 /显示是哪个键按下的/
DEC R0
MOV DPTR, #TABLE2
MOV A, R0
RL A
MOVC A, @A+DPTR
MOV R6, A / R6存放T值高字节/
MOV A, R0
RL A
INC A
MOVC A, @A+DPTR
MOV R7, A / R7存放T值低字节/
MOV TH0, R6
MOV TL0, R7
SETB TR0 /启动T0开始计时/
JXU: MOV A, P2
SMIAO: CJNE A,#0FFH,JXU/不相等表示键是一直按下/
MOV P0, #00H /对数码管清零/
SJMP NOT /相等表示按键已经松开/
NOT: RETI /返回中断,等待键下产生中断/
ITT0: PUSH ACC
PUSH PSW
MOV TH0, R6
MOV TL0, R7
CPL P1.0
POP PSW
POP ACC
RETI
INN1: MOV P2,#08H /数码管显示8/
MOV 40H, #00H
D3: MOV A, #40H
MOV DPTR, #TABLE0
MOVC A, @A+DPTR
MOV R1, A /R1存放音符码/
JZ END0 /是否取到00(结束码)/
MOV A, #40H
INC A
MOVC A, @A+DPTR
MOV R2, A /R2存放节拍码/
MOV A, R1
CJNE A, #0FFH,SIG /音符码是否为0FFH/
CLR TR0
SJMP DEL0
SIG: MOV DPTR, #TABLE1
MOV 41H, A
RL A
MOVC A,@A+DPTR
MOV R6, A /T值高字节存入R6中/
MOV A, 41H
RL A
INC A
MOVC A, @A+DPTR
MOV R7, A /T值低字节存入R7中/
MOV TH0, 42H
MOV TL0, 43H
SETB TR0
DEL0: CALL DELAY
INC 40H
SJMP D3
END0: CLR TR0
SJMP INN1 /重复唱歌/
DELAY: MOV R3,#02
D0: MOV R4,#125
D1: MOV R5,#248
DJNZ R5, $
DJNZ R4, D1
DJNZ R3, D0
DJNZ R2, DELAY /R2 中存放节拍数/
RET
TABLE0: DW 63628,63731,63835,63928,64021,64103
DW 64185,64260,64331,64400,64463,64524
DW 64580,64633,64684,64732,64777,64820
DW 64860,64898,64934,64968,64994,65030
DW 65058,65085,65110,65134,65157,65178
DW 65198,65217,65235,65252,65268,65283
TABLE1: DB 09H,02H,10H,02H,10H,02H,10H,02H,
10H,04H,FFH,02H,07H,02H,05H,02H
0FH,02H,05H,02H,04H,02H,04H,08H
03H,02H,11H,02H,09H,02H,13H,02H
08H,02H,12H,02H,07H,02H,16H,02H
00H
TABLE2: DW 64580, 64684, 64777, 64820, 64898, 64968, 65030
END
参考文献:
[1]范逸之,陈立元. Visual Basic与RS232串行通讯控制. 中国青年出版社. 2002第2版
[2]候伯亨,顾新. VHDL硬件描述语言与数字逻辑电路设计. 西安电子科技大学出版社
[3]潘松等. VHDL实用教程. 电子科技大学出版社
[4]邹逢兴. 计算机硬件技术基础. 国防科技大学出版社
[5]丁元杰等. 单片微机原理及应用. 机械工业出版社.2001-06第2版
[6]何伟,张玲. 消除CPLD/FPGA器件设计中的毛刺. 重庆大学学报. 2002-12,