MOM

TITLE HEARING TEST

.MODEL SMALL .CODE ORG 100H

START:
JMP MAIN

;END FREQUENCY IS FFFF = 65536 = 5 DIGIT NUM DB '00079 HZ','$'

MSG DB 'The frequence is : ','$' ASK DB ' Can you hear it (its delay was 5 sec )( y/N )?' , '$'

;************* MAIN ******************* MAIN PROC

MOV     AL,0B6H     ;COUNTER 2,LSB MSB,BINARY
OUT     43H,AL

MOV     DX,80

NEXT:

MOV AX,DX       
CALL    NOTE_OUTER
MOV BL,10       ;DELAY = 5 SEC
CALL    SPEAKER


PUSH    DX      ;#  

;FOR MAKING FRQEUENCY IN ASCII FORM TO SHOW

LEA BX,NUM+4
LEA SI,NUM+4
MOV DH,31H

CLC

MOV AX,[SI]
ADC AL,DH
AAA
PUSHF
OR  AL,30H
POPF
MOV [BX],AL

PUSHF           ;*

DEC SI
DEC     BX
MOV     CX,4

POPF            ;*

L1: MOV AX,[SI] ADC AL,00 AAA

PUSHF
OR  AL,30H
POPF

MOV [BX],AL
DEC SI
DEC     BX      
LOOP    L1
MOV [BX],AH

;SHOWING FREQUENCY

MOV     AH,09
LEA DX,MSG
INT     21H

LEA DX,NUM
INT     21H

;SHOWING ASK QUESTION

LEA DX,ASK
INT     21H

L2: MOV AH,08 INT 21H

CMP AL,'Y'
JE  CONTINUE        
CMP AL,'N'
JE  CONTINUE
CMP AL,'y'
JE  CONTINUE        
CMP AL,'n'
JE  CONTINUE
JMP L2

CONTINUE:

MOV     AH,02
MOV DL,AL
INT     21H
MOV DL,0AH
INT     21H
MOV DL,0DH
INT 21H



POP DX      ;#

INC     DX
CMP DX,0FFFH
JNE NEXT    
INT 20H

MAIN ENDP

;************* NOTE-OUTER *************** NOTE_OUTER PROC ;ASSUME AX = NOTE

OUT 42H,AL
MOV     AL,AH
OUT     42H,AL

RET

NOTE_OUTER ENDP

;************** SPEAKER ***************** SPEAKER PROC

;ASSUME BL = NUMBER OF CALLING DELAY

IN  AL,61H      ;GET PORT B STATUS
MOV     AH,AL

OR  AL,00000011B    ;TURN THE SPEAKER ON
OUT     61H,AL

AGAIN: CALL DELAY DEC BL JNZ AGAIN

MOV     AL,AH       ;GET THE ORIGINAL SETTING OF PORT B
OUT     61H,AL      ;TURN THE SPEAKER OFF

CALL    DELAY_OFF

RET

SPEAKER ENDP

;************** DEALY ( 1/2 SEC ) ***************** DELAY PROC

MOV     CX,33144    ;33144 * 15.085 us = 1/2 SEC
PUSH    AX

L: IN AL,61H AND AL,10H CMP AL,AH JE L MOV AH,AL LOOP L

POP     AX
RET

DELAY ENDP

;************** DEALY_OFF ( 0.15 SEC ) ***************** DELAY_OFF PROC

MOV CX,10000    ;10000 * 15.08 us = 0.15 SEC
PUSH    AX

B: IN AL,61H AND AL,10H CMP AL,AH JE B MOV AH,AL LOOP B

POP     AX
RET

DELAY_OFF ENDP END START

;2006/02/06