8253定时器中断发脉冲求解!
小弟最近要用8253发脉冲,写了一段代码,可是发出的脉冲有问题!哪位大侠可以看看,帮我个忙啊!感激不尽!
代码如下:
DATA SEGMENT
TS DW 6000
DATA ENDS
ESTACK SEGMENT STACK
DB 1000 DUP(0)
ESTACK ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA, SS:ESTACK
MAIN PROC FAR
MOV DX, 301H ;步进电机加使能
MOV AL, 01H
OUT DX,AL
MOV CX,10000
CALL WAITF
PUBLIC INT00
PAGE
INT00 PROC NEAR ;保存旧的08H中断向量入口地址
PUSH DS
CLI
CLD
MOV AX,0000H
MOV DS,AX
MOV SI,0020H
LODSW
MOV BX,AX
LODSW
POP DS
PUSH AX
PUSH BX
PUSH ES
MOV AX,DATA ;设置新的08H中断向量入口地址
MOV DS,AX
MOV AX,0000H
MOV ES,AX
MOV DI,0020H
MOV AX,OFFSET TIMER0
STOSW
MOV AX,CS
STOSW
POP ES
MOV AL,36H ;写入中断控制字
OUT 43H,AL
MOV AX,TS ;初始化8253定时器
OUT 40H,AL
MOV AL,AH
OUT 40H,AL
IN AL,21H
PUSH AX
AND AL,0FCH
OUT 21H,AL
STI
;********************************************************************;***************************
*****************************************
CLI
CLD
POP AX
OUT 21H,AL
MOV AL,36H ;恢复旧的定时器初值
OUT 43H,AL ;恢复中断服务程序的入口地址
MOV AL,0
OUT 40H,AL
OUT 40H,AL
MOV AX,0
MOV ES,AX
MOV DI,4*8
POP AX
STOSW
POP AX
STOSW
STI
;close the 'x' enable
MOV DX,301H ;关闭步进电机使能
MOV AL,00H
OUT DX,AL
RET
INT00 ENDP
PUBLIC TIMER0 ;新的中断服务子程序
PAGE
TIMER0 PROC NEAR
PUSH DS
PUSH ES
PUSH AX
PUSH BX
PUSH CX
PUSH DX
MOV AX,DATA
MOV DS,AX
MOV ES,AX
;out one +x pulse to the I/O
G00_X:
MOV DX,300H ;向步进电机发脉冲(基地址=300H,0位=脉冲,1位=方向)
MOV AL,01H
OUT DX,AL
MOV CX,1
CALL WAITF
MOV AL,00H
OUT DX,AL
G00_END: MOV AL,20H
OUT 20H,AL
POP DX
POP CX
POP BX
POP AX
POP ES
POP DS
STI
IRET
TIMER0 ENDP
WAITF PROC NEAR ;普通的延时子程序
PUSH AX
WAITF1:
IN AL,61H
AND AL,10H
CMP AL,AH
JE WAITF1
MOV AH,AL
LOOP WAITF1
POP AX
RET
WAITF ENDP
MAIN ENDP
CODE ENDS
END MAIN