1、一 实验名称:发声器二 功能及用法:设计一种电子琴发声程序,并在运营时通过实验箱上扬声器发声,并且当按下数字114时,依次发出1,2,3,4,5,6,7低音和1,2,3,4,5,6,7中音。并在实验箱上发声器上发声,这必定需要有发声程序,驱动发声程序,尚有键盘扫描程序,及为了可以听见清脆字符音还得对程序进行必要延时。运用8254芯片所提供转化后频率送到发声单元进行发声及8255芯片送提供输入输出功能,来完毕从键盘输入到发声装置发声控制。电子发声原理:一种音符相应一种频率,将相应一种音符频率方波通到扬声器上,就可以发出这个音符声音。将一段乐曲音符相应频率方波一次送到扬声器,就可以演奏出这段乐曲。
2、运用8254“方波发生器”,将相应一种频率计数初值写入计数器,就可以产生相应频率方波。计数初值计算如下:计数初值 = 输入时钟输出频率例如输入时钟采用1MHZ,要得到800HZ频率,计数初值即为1000000/800。音符与表对照关系如上表所示。对于每一种音符演奏时间,可以通过软件延时来解决。一方面拟定单位延时子程序(依照CPU频率不同而有所变化)。然后拟定每个音符演奏需要几种单位延时,将此值送入寄存器,再调用延时子程序即可。三实验器件:通过实验箱上扬声器发声,并且当按下数字114时,依次发出1,2,3,4,5,6,7低音和1,2,3,4,5,6,7中音。并在实验箱上发声器上发声。选用器件:8
3、254和8255芯片各一片,微机一台,TPC-H通用微机接口实验系统一台,扬声器和导线若干四电路连接图:8254某些接线图8255某些接线图五各子程序功能1.为8255和8254所定义端口地址:I0Y0 EQU 06C0HMY8254_COUNT0 EQU I0Y0+00HMY8254_COUNT1 EQU I0Y0+02HMY8254_COUNT2 EQU I0Y0+04HMY8254_MODE EQU I0Y0+06HMY8255_A EQU 0640HMY8255_B EQU 0642HMY8255_C EQU 0644HMY8255_MODE EQU 0646H2.频率表及所相应时间表
4、:FREQ_LIST DW 262H,294H,330H,349H,392H,440H,496H DW 523H,587H,659H,698H,784H,880H,988H DTABLE DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H DB 7FH,6FH,77H,7CH,39H,5EH,79H,71H3.定义8255和8254控制字 MOV DX,MY8255_MODE MOV AL,81H OUT DX,AL MOV DX,MY8254_MODE MOV AL,36H OUT DX,AL4.CCSCAN子程序实现取出按键值并输入A口(清屏子程序)CCSCAN:MOV
5、AL,00H MOV DX,MY8255_A OUT DX,AL MOV DX,MY8255_CIN AL,DXNOT ALAND AL,0FHRET5.Play输出发音子程序PLAY PROC MOV AH,0 MOV SI,AX SHL SI,1 MOV DX,0FH MOV AX,4240HDIV WORD PTR SIMOV DX,MY8254_COUNT0OUTDX,AL MOV AL,AH OUTDX,AL RETPLAY ENDP 6.延时子程序DALLY PROC D0:MOV CX,0010H D1:MOV AX,02H D2:DEC AX JNZ D2 LOOP D1 DE
6、C DL JNZ D0RET DALLY ENDP 7.按键扫描功能COLUM: MOV AL,CH MOV DX,MY8255_A OUT DX,AL MOV DX,MY8255_C IN AL,DXL1:TEST AL,01HJNZ L2MOV AL,00HJMP KCODEL2:TEST AL,02HJNZ L3MOV AL,04HJMP KCODE L3:TEST AL,04HJNZ L4MOV AL,08HJMP KCODEL4:TEST AL,08HJNZ NEXTMOV AL,0CHKCODE:ADD AL,CL CALL PLAY PUSH AXKON:CALL DALLYCA
7、LL CCSCANJNZ KONPOP AXJMP BEGIN1六源程序清单I0Y0 EQU 06C0HMY8254_COUNT0 EQU I0Y0+00HMY8254_COUNT1 EQU I0Y0+02HMY8254_COUNT2 EQU I0Y0+04HMY8254_MODE EQU I0Y0+06HMY8255_A EQU 0640HMY8255_B EQU 0642HMY8255_C EQU 0644HMY8255_MODE EQU 0646HSTACK1 SEGMENT STACKDW 256 DUP(?)STACK1 ENDSDATA SEGMENTFREQ_LIST DW 26
8、2H,294H,330H,349H,392H,440H,496H DW 523H,587H,659H,698H,784H,880H,988H DTABLE DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H DB 7FH,6FH,77H,7CH,39H,5EH,79H,71HDATA ENDSCODE SEGMENTASSUME CS:CODE,DS:DATASTART:MOV AX,DATA MOV DS,AX MOV DX,MY8255_MODE MOV AL,81H OUT DX,AL MOV DX,MY8254_MODE MOV AL,36H OUT DX,ALBEG
9、IN1: CALL CCSCAN JNZ INK1 JMP BEGIN1INK1: CALL CCSCAN JNZ INK2 JMP BEGIN1INK2:MOV CH,0FEH MOV CL,00HCOLUM: MOV AL,CH MOV DX,MY8255_A OUT DX,AL MOV DX,MY8255_C IN AL,DXL1:TEST AL,01HJNZ L2MOV AL,00HJMP KCODEL2:TEST AL,02HJNZ L3MOV AL,04HJMP KCODE L3:TEST AL,04HJNZ L4MOV AL,08HJMP KCODEL4:TEST AL,08HJ
10、NZ NEXTMOV AL,0CHKCODE:ADD AL,CL CALL PLAY PUSH AXKON:CALL DALLYCALL CCSCANJNZ KONPOP AXJMP BEGIN1NEXT:INC CL MOV AL,CHTEST AL,08HJZ KERRROL AL,1MOV CH,ALJMP COLUMKERR:JMP BEGIN1CCSCAN:MOV AL,00H MOV DX,MY8255_A OUT DX,AL MOV DX,MY8255_CIN AL,DXNOT ALAND AL,0FHRETPLAY PROC MOV AH,0 MOV SI,AX SHL SI,1 MOV DX,0FH MOV AX,4240HDIV WORD PTR SIMOV DX,MY8254_COUNT0OUTDX,AL MOV AL,AH OUTDX,AL RETPLAY ENDP DALLY PROC D0:MOV CX,0010H D1:MOV AX,02H D2:DEC AX JNZ D2 LOOP D1 DEC DL JNZ D0RET DALLY ENDP CODE ENDS END START