用8253做的音乐彩灯 里面的一句话不明白 求指点
DATA SEGMENT
BAK DB ?
TMP DB ?
MUSIC1 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
MUSIC2 DB 2DH, 26H, 2DH, 33H, 33H, 33H, 33H, 33H, 33H, 45H, 3DH, 39H, 39H
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 45H, 45H, 45H, 45H, 33H, 33H, 3DH, 33H, 26H, 26H, 26H, 28H, 2DH
DB 45H, 45H, 45H, 45H, 33H, 33H, 3DH, 33H, 26H, 26H, 26H, 28H, 2DH
DB 45H, 45H, 45H, 45H, 45H, 45H, 45H, 33H, 33H, 3DH, 33H, 26H, 26H
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
;8255_init a:output b:input c:output
MOV AL,82H
OUT 63H,AL
;8253_init 设置计数器2工作在方式3 cplck---1.1625mhz
MOV AL,0B7H
OUT 43H,AL
GET_KEY:
IN AL,60H ;读按键的值 确定要播放的歌曲
CMP AL,0
JZ GET_KEY
CMP AL,01H
JZ A1 ;第一首
JMP A2 ;第二首
A1:
MOV BX,OFFSET MUSIC1
MOV TMP,1
MOV AL,[BX]
MOV AH,00H
JMP DO
A2:
MOV BX,OFFSET MUSIC2
MOV TMP,2
MOV AL,[BX]
MOV AH,00H
JMP DO
DO:
CMP AL,33H
JNE RE
MOV BAK,AL
MOV AL,0AH
OUT 60H,AL
A3:
MOV AL,BAK
MOV DL,25H ;设置CLK
MUL DL
OUT 42H,AL
MOV AL,AH
OUT 42H,AL
INC BX
MOV AH,00H
MOV AL,[BX]
TEST AL,0FFH ;逻辑乘 不保留结果 判断00H
JZ A4 ; 如果结束 重新开始
PUSH AX
CALL DALLY
POP AX
JMP A1
A4: CMP TMP,1
JZ A5
MOV BX,OFFSET MUSIC1
MOV AL,[BX]
MOV AH,00H
JMP A1
A5: MOV BX,OFFSET MUSIC2
MOV AL,[BX]
MOV AH,00H
JMP A1
RE: CMP AL,3DH
JNE MI
MOV BAK,AL
MOV AL,15H
OUT 60,AL
JMP A3
MI: CMP AL,26H
JNE FA
MOV BAK,AL
MOV AL,29H
OUT 60,AL
JMP A3
FA: CMP AL,2DH
JNE SO
MOV BAK,AL
MOV AL,36H
OUT 60,AL
JMP A3
SO: CMP AL,4DH
JNE LA
MOV BAK,AL
MOV AL,4CH
OUT 60,AL
JMP A3
LA: CMP AL,45H
JNE XI
MOV BAK,AL
MOV AL,53H
OUT 60,AL
JMP A3
XI: MOV BAK,AL
MOV AL,6BH
OUT 60,AL
JMP A3
DALLY: MOV CX,77FFH
D1: MOV AX,0C00H
D2: DEC AX
JNZ D2
LOOP D1
RET
CODE ENDS
END START
A3那里, MOV DL,25H MUL DL 这两句什么意思???是设置clk吗??为什么这么写??求指教。
[解决办法]
PC中的8253A地址分配:
43H: 控制字
40~42H: 对应了3个计数器(PA, PB和PC)
3个端口可以按照不同的模式独立工作,在PC中的作用也不一样.
计数器2作为扬声器音频发生器, 故要根据不同的数值(其实就是声音频率)来设置42H了.
而Delay则是音长了,这里每个数值后面的延时都是一样的,故为了演奏一个比较长的音就连续写了好多一样的数值(比如最后一行)。