4000是十进制数,转化为十六进制为0FA0H
计数初值为4000按二进制计数的意思是写命令时按二进制写
程序为:
MOV AL,10110110B
OUT 43H,AL
MOV AL,A0H
OUT 42H,AL
MOV AL,0FH
OUT 42H,AL
如果说按BCD码计数,则命令字为10100111,程序改为:
MOV AL,10100111B
OUT 43H,AL
MOV AL,40H
OUT 42H,AL
设定8253的2#通道工作方式为方式0,用于事件计数,当计数值为5 时,发出中断请求信号,显示“M”。STACK1 SEGMENT STACK
DW 64 DUP(?)
STACK1 ENDS
CODE SEGMENT
ASSUME CS:CODE
START: MOV AX,OFFSET IRQ7 ; 修改8259 中断7 中断矢量
MOV SI,003CH
MOV [SI],AX
MOV AX,CS
MOV SI,003EH
MOV [SI],AX
IN AL,21H ;修改IMR,使IRQ7 中断允许
AND AL,7FH
OUT 21H,AL
MOV AL,90H ;8253 初始化
OUT 43H,AL
A1: MOV AL,05H ;赋8253 2 号计数器初值
OUT 42H,AL
HLT ;停机,等待中断
STI
JMP A1
;IRQ7 中断服务程序
IRQ7: MOV AX,014DH ;显示“M”
INT 10H
MOV AX,0120H ;显示空格
INT 10H
MOV AL,20H ;普通EOI 命令
OUT 20H,AL
IRET ;中断返回
CODE ENDS
END START
系统的OPCLK(1.1625MHz)作为音乐节拍,由表格查出每个音符对应的时间常数送给计数器2(工作在方式3:方波频率发生器),以确定音调,驱动扬声器产生音乐。
STACK1 SEGMENT STACK
DW 64 DUP(?)
STACK1 ENDS
DATA SEGMENT
TABLE DB 33H,33H,3DH,33H,26H,26H, 26H, 26H, 2DH, 2DH, 26H, 2DH, 33H
DB 33H,33H,33H,33H, 33H, 4DH, 45H, 3DH, 3DH, 3DH, 45H, 4DH, 45H
DB 45H,45H,45H,45H,45H, 45H, 45H, 33H, 33H, 3DH, 33H, 26H, 26H
DB 26H,28H,2DH,2DH,26H, 26H, 33H, 33H, 33H, 33H, 45H, 3DH, 39H
DB 39H,39H,52H,4DH,4DH, 4DH, 4DH, 4DH, 4DH, 4DH, 4DH, 2DH, 2DH
DB 26H,26H,26H,26H,26H, 26H, 28H, 28H, 2DH, 28H, 26H, 26H, 26H
DB 26H,2DH,28H,26H,2DH, 2DH, 33H, 3DH, 4DH, 45H, 45H, 45H, 45H
DB 45H,45H,45H,45H,33H, 33H, 3DH, 33H, 26H, 26H, 26H, 28H, 2DH
DB 2DH,26H,2DH,33H,33H, 33H, 33H, 33H, 33H, 45H, 3DH, 39H, 39H
DB 39H,52H,4DH,4DH,4DH, 4DH, 4DH, 4DH, 4DH, 4DH, 00H
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
MOV BX,OFFSET TABLE
MOV AL,[BX]
MOV AH,00H
A1: MOV DL,25H
MUL DL
PUSH AX
MOV AL,0B7H
OUT 43H,AL
POP AX
OUT 42H,AL
MOV AL,AH
OUT 42H,AL
INC BX
MOV AH,00H
MOV AL,[BX]
TEST AL,0FFH
JZ A3
MOV CX,77FFH
A2: PUSH AX
POP AX
LOOP A2
JMP A1
A3: MOV BX,OFFSET TABLE
MOV AL,[BX]
MOV AH,00H
JMP A1
CODE ENDS
END START
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)