8253应用(键盘演奏音乐程序)PC机中,8253定时器2,工作于方式3(输出方波),输入频率fin、输出频率fout及计数初值之间的关系:foutfin初值(fin=1193200=1234F0H),(也可用533H*896H=123280H)例如:给定fout在DI寄存器中,DX和AX存放1.1932MHz的十六进制值1234F0H,则产生fout输出的计数初值的程序段:(初值存于AX中)MOVDX,12HMOVAX,34F0H;DX和AX存放finDIVDI;DI存放fout结果在AX中10ms秒软件延时程序:MOVCX,2801DELAY:LOOPDELAY要得到10ms秒的整数倍时间,可在BX寄存器中放入倍数控制外循环次数,如产生1秒的程序:MOVBX,100WAIT:MOVCX,2801DELAY:LOOPDELAYDECBXJNZWAIT频率表1234567262294330349392440494datasegmentfreqdw262,294,330,349,392l,440,494dataendscodesegmentassumeds:data,cs:codemainprocfarstart:pushdsmovax,0pushaxmovax,datamovds,axmoval,10110111h;8253定时器2初始化out43h,alinal,61h;读pb口oral,03hout61h,al;pb0,pb1=’1’,打开声音again:movah,1;dos功能调用,键盘输入并回显int21h;按键(键入的ascii码值在al中)cmpal,1bh;‘Esc’退出jzexitleasi,freqandax,0fh;ax中得到按键值1~7。shlax,1;双字节subax,2;地址从0000开始addsi,ax;si指向对应的频率值movdi,[si]movdx,12hmovax,34f0hdivdi;ax中得到对应频率的初值foutfin初值out42h,al;定器2的端口,写入初值低8位moval,ahout42h,al;写入初值,高8位即刻发出该频率的声音jmpagainexit:inal,61handal,0fchout61h,al;pb0,pb1=0,关闭声音retmainendpcodeendsendstart思考:如何编写音乐程序。