老大,写了要给分哦!!!!!重点啊
stack segment para stack 'stack' ;堆栈段
db 64 dup('stack...')
stack ends
*******************************************************************
dseg segment para 'data' ;数据段
mus_freq dw 262,294,330,262,262,294,330,262 频率
dw 330,349,392,330,349,392,392,440
dw 392,349,330,262,392,440,392,349
dw 330,262,294,196,262,294,196,262,-1
mus_time dw 25,25,25,25,25,25,25,25,25,25演奏时间
dw 50,25,25,50,12,12,12,12,25,25
dw 12,12,12,12,25,25,25,25,50,25,25,50
dseg ends
*******************************************************************
cseg segment para 'code'代码段
assume cs:cseg,ss:stack,ds:dseg;关联
-------------------------------------------------------------------
music proc far;远过程
mov ax,dseg
mov ds,ax将数据段基址非DS
lea si,mus_freq;将mus_freg的偏移地址非si
lea bp,ds:mus_time;将mus_time的偏移地址给bp
freq:
mov di,[si] ;读取数据段mus_freq的第一个值给di
cmp di,-1 ;是否为-1
je end_mus;为1则结束
mov bx,ds:[bp];不相等则将数据段mus_time的第一个值给bx
call soundf;调用soundf
add si,2 ;si加一
add bp,2;bp加一
jmp freq ;循环啦
end_mus: ;退出exit
mov ax,4c00h
int 21h
music endp
******************************************************
soundf proc near
push ax
push bx;压栈保存ax,bx,cx,dx。di
push cx
push dx
push di
mov al,0b6h ;写控制字
out 43h,al ;43h应该为控制字端口
mov dx,12h
mov ax,348ch ;这应该是原始时钟
div di ;除mus_freq的值得到输出频率
out 42h,al ;将获得频率分两次给42h端口
mov al,ah
out 42h,al
in al,61h ;读取61h状态
mov ah,al 给ah
or al,3 将其与3相加
out 61h,al ;在将其输出到61h端口
wait1:
mov cx,6630 ;延时吧?cx控制延时长度
call waitf
dec bx ,bx为演奏的时间吧
jnz wait1 演奏完了,下一个
mov al,ah
out 61h,al
pop di
pop dx
pop cx
pop bx
pop ax
ret
soundf endp
******************************************************
waitf proc near
push ax
waitf1:
in al,61h 读取61h状态
and al,10h与10h与
cmp al,ahal是否和ah相等
je waitf1相等则继续等待
mov ah,al 不相等则将al给ah
loop waitf1 cx减一,循环
pop ax
ret返回
waitf endp
******************************************************
cseg ends
******************************************************
end music
令 T1 定时,到时,对输出端,取反即可。ORG 0000H
JMP START
ORG 001BH
CPL P1.7
JNB F0, F2
MOV TH1, #0FEH
MOV TL1, #34H
RETI
F2:
MOV TH1, #0FEH
MOV TL1, #98H
RETI
START:
MOV TMOD, #10H
SETB TR1
MOV IE, #88H
LOOP:
MOV R5, #5
DJNZ R7, $
DJNZ R6, $ - 2
DJNZ R5, $ - 4
CPL F0
SJMP LOOP
END
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)