声控程序

  • 格式:doc
  • 大小:35.00 KB
  • 文档页数:3

;*------------------------------------------------------*/
;* SoundL.asm(声-光报警器接口实验) */
;*------------------------------------------------------*/
stack1 segment
dw200dup (?)
stack1 ends
data segment para public 'data'
message db 'press SW3 to start !',0ah,0dh;系统提示
db 'if you want to quit, please hit Any Key!',0ah,0dh,'$'
t dw0;初始化延时变量为0 num dw0;初始化数字变量为0
data7 db81h,42h,24h,18h,81h,42h,24h,18h
data ends
code segment para public 'code'
assume ss:stack1,cs:code,ds:data
sl proc far
start: mov ax,stack1
mov ss,ax
mov ax,data
mov ds,ax
mov ah,09h;显示系统提示
mov dx,seg message
mov ds,dx
mov dx,offset message
int21h
mov dx,303h;初始化8255
mov al, 81h
out dx,al
mov dx,300h;LED全灭
mov al,00h
out dx,al
mov dx,303h;关闭SPK
mov al,0ch
out dx,al
w ait1: mov dx,302h;查SW3按下?
in al,dx;(PC2=0?)
and al,04h
jnz wait1 ;未按下,等待
begin: call ledflash ;已按下,调用LED发光子程
mov bx,200
mov t,0ffffh
hison: call outspk ;调用喇叭发声子程(高频)
dec bx
jnz hison
mov dx,300h;LED全灭
mov al,00h
out dx,al
mov bx,200
mov t,0afh
loson: call outspk ;调用喇叭发声子程(低频)dec bx
jnz loson
call delay2
mov ah,0bh;查任意键按下?
int21h
cmp al,0ffh
je quit ;有任意键按下,退出
jmp begin ;无任意键按下,继续quit: mov dx,300h;LED全灭
mov al,00h
out dx,al
mov dx,303h;关闭SPK
mov al,0ch
out dx,al
mov ah,4ch
int21h;返回DOS
sl endp
delay1 proc;延时子程1
push bx
mov bx,t
dl1: dec bx
jnz dl1
pop bx
ret
delay1 endp
delay2 proc;延时子程2
push cx
push bx
mov cx,04ffh
dl4: mov bx,0ffffh
dl3: dec bx
jnz dl3
dec cx
jnz dl4
pop bx
pop cx
ret
delay2 endp
outspk proc;喇叭发声子程
mov dx,303h;从PC6输出方波
mov al,0dh;置PC6=1;
out dx,al
call delay1
mov dx,303h
mov al,0ch;置PC6=0;
out dx,al
call delay1
ret
outspk endp
ledflash proc;LED发光子程序
mov si,offset data7 ;LED的点亮代码
add si,num
mov al,[si]
mov dx,300h;从8255的A口输出LED点亮代码
out dx,al
inc num
cmp num,08h
jne next
mov num,00h
next: ret
ledflash endp
code ends
end start。