0一.实验名称:发声器二.功能及使用方法:设计一个电子琴发声程序,并在运行时通过实验箱上的扬声器发声,并且当按下数字1~14时,依次发出1,2,3,4,5,6,7的低音和1,2,3,4,5,6,7的中音。并在实验箱上的发声器上发声,这肯定需要有发声程序,驱动发声程序,还有键盘扫描程序,及为了能够听见清脆的字符音还得对程序进行必要的延时。利用8254芯片所提供转化后的频率送到发声单元进行发声及8255芯片送提供的输入输出功能,来完成从键盘的输入到发声装置发声的控制。电子发声原理:一个音符对应一个频率,将对应一个音符频率的方波通到扬声器上,就可以发出这个音符的声音。将一段乐曲的音符对应频率的方波一次送到扬声器,就可以演奏出这段乐曲。利用8254的“方波发生器”,将相应的一种频率的计数初值写入计数器,就可以产生对应频率的方波。计数初值的计算如下:计数初值=输入时钟\输出频率例如输入时钟采用1MHZ,要得到800HZ的频率,计数初值即为1000000/800。音符与表的对照关系如上表所示。对于每一个音符的演奏时间,可以通过软件延时来处理。首先确定单位延时子程序(根据CPU的频率不同而有所变化)。然后确定每个音符演奏需要几个单位延时,将此值送入寄存器,再调用延时子程序即可。三.实验器件:通过实验箱上的扬声器发声,并且当按下数字1~14时,依次发出1,2,3,4,5,6,7的低音和1,2,3,4,5,6,7的中音。并在实验箱上的发声器上发声。选用器件:8254和8255芯片各一片,微机一台,TPC-H通用微机接口实验系统一台,扬声器和导线若干四.电路连接图:8254部分接线图8255部分接线图1五.各子程序功能1.为8255和8254所定义的端口地址:I0Y0EQU06C0HMY8254_COUNT0EQUI0Y0+00HMY8254_COUNT1EQUI0Y0+02HMY8254_COUNT2EQUI0Y0+04HMY8254_MODEEQUI0Y0+06HMY8255_AEQU0640HMY8255_BEQU0642HMY8255_CEQU0644HMY8255_MODEEQU0646H2..频率表及所对应的时间表:FREQ_LISTDW262H,294H,330H,349H,392H,440H,496HDW523H,587H,659H,698H,784H,880H,988HDTABLEDB3FH,06H,5BH,4FH,66H,6DH,7DH,07HDB7FH,6FH,77H,7CH,39H,5EH,79H,71H3.定义8255和8254的控制字MOVDX,MY8255_MODEMOVAL,81HOUTDX,ALMOVDX,MY8254_MODEMOVAL,36HOUTDX,AL4.CCSCAN子程序实现取出按键值并输入A口(清屏子程序)2CCSCAN:MOVAL,00HMOVDX,MY8255_AOUTDX,ALMOVDX,MY8255_CINAL,DXNOTALANDAL,0FHRET5.Play输出发音的子程序PLAYPROCMOVAH,0MOVSI,AXSHLSI,1MOVDX,0FHMOVAX,4240HDIVWORDPTR[SI]MOVDX,MY8254_COUNT0OUTDX,ALMOVAL,AHOUTDX,ALRETPLAYENDP6.延时子程序DALLYPROCD0:MOVCX,0010HD1:MOVAX,02HD2:DECAXJNZD2LOOPD1DECDLJNZD0RETDALLYENDP7.按键扫描功能COLUM:MOVAL,CHMOVDX,MY8255_AOUTDX,ALMOVDX,MY8255_CINAL,DX3L1:TESTAL,01HJNZL2MOVAL,00HJMPKCODEL2:TESTAL,02HJNZL3MOVAL,04HJMPKCODEL3:TESTAL,04HJNZL4MOVAL,08HJMPKCODEL4:TESTAL,08HJNZNEXTMOVAL,0CHKCODE:ADDAL,CLCALLPLAYPUSHAXKON:CALLDALLYCALLCCSCANJNZKONPOPAXJMPBEGIN1六.源程序清单I0Y0EQU06C0HMY8254_COUNT0EQUI0Y0+00HMY8254_COUNT1EQUI0Y0+02HMY8254_COUNT2EQUI0Y0+04HMY8254_MODEEQUI0Y0+06HMY8255_AEQU0640HMY8255_BEQU0642HMY8255_CEQU0644HMY8255_MODEEQU0646HSTACK1SEGMENTSTACKDW256DUP(?)STACK1ENDSDATASEGMENTFREQ_LISTDW262H,294H,330H,349H,392H,440H,496HDW523H,587H,659H,698H,784H,880H,988HDTABLEDB3FH,06H,5BH,4FH,66H,6DH,7DH,07HDB7FH,6FH,77H,7CH,39H,5EH,79H,71H4DATAENDSCODESEGMENTASSUMECS:CODE,DS:DATASTART:MOVAX,DATAMOVDS,AXMOVDX,MY8255_MODEMOVAL,81HOUTDX,ALMOVDX,MY8254_MODEMOVAL,36HOUTDX,ALBEGIN1:CALLCCSCANJNZINK1JMPBEGIN1INK1:CALLCCSCANJNZINK2JMPBEGIN1INK2:MOVCH,0FEHMOVCL,00HCOLUM:MOVAL,CHMOVDX,MY8255_AOUTDX,ALMOVDX,MY8255_CINAL,DXL1:TESTAL,01HJNZL2MOVAL,00HJMPKCODEL2:TESTAL,02HJNZL3MOVAL,04HJMPKCODEL3:TESTAL,04HJNZL4MOVAL,08HJMPKCODEL4:TESTAL,08HJNZNEXTMOVAL,0CH5KCODE:ADDAL,CLCALLPLAYPUSHAXKON:CALLDALLYCALLCCSCANJNZKONPOPAXJMPBEGIN1NEXT:INCCLMOVAL,CHTESTAL,08HJZKERRROLAL,1MOVCH,ALJMPCOLUMKERR:JMPBEGIN1CCSCAN:MOVAL,00HMOVDX,MY8255_AOUTDX,ALMOVDX,MY8255_CINAL,DXNOTALANDAL,0FHRETPLAYPROCMOVAH,0MOVSI,AXSHLSI,1MOVDX,0FHMOVAX,4240HDIVWORDPTR[SI]MOVDX,MY8254_COUNT0OUTDX,ALMOVAL,AHOUTDX,ALRETPLAYENDPDALLYPROCD0:MOVCX,0010HD1:MOVAX,02HD2:DECAX6JNZD2LOOPD1DECDLJNZD0RETDALLYENDPCODEENDSENDSTART