微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

8254/8253 的 x86 timer2:始终创建 1s 而不是 wave

如何解决8254/8253 的 x86 timer2:始终创建 1s 而不是 wave

我试图通过创建方波并计算方波值为 1 的次数来使用 8254 IC 的 counter2 进行硬件延迟:


mov al,10101110B
out 43H,al
        
mov al,33h
out 42H,al
mov al,05h
out 42H,al
        
;;enable the port
in AL,61H
push ax
OR AL,00000011B ;;enable PB0 and PB1
out 61h,al
        
mov cx,200
;;make delay
        
waitf1:
        in al,62H ;; Reads from 62H The result is always 20h
        and al,20h 
        cmp al,ah
        je waitf1
            
        mov ah,al
        loop waitf1
            
        
        

pop ax
out 61h,al

程序在循环中存储,因为从端口 62h 读取的值始终为 20hPC5 始终为 1),而我预计它是方波。

解决方法

我想知道计时器是否处于模式 2 是否重要。这是我使用 MSDOS 从 timer0 获取准确时间的旧汇编代码。需要 jmp 短 $+2 延迟,可能是因为 cpu 的运行速度比 ISA 总线快一些。由于此代码从定时器获取 16 位计数,因此第 15 位可用于方波模式。原始问题不需要在这段代码中读入 dx 的中断计数。

TMR     equ     040h
Tmrgt0: cli
        mov     dx,IntCnt               ;get current int count
        mov     al,0c2h                 ;output read channel 0 cmd
        out     TMR+3,al
        jmp     short $+2
        in      al,TMR                  ;get bit  (15  )
        test    al,2                    ;br if in mode 2
        jz      Tmrgt1
        shl     al,1
        jmp     short $+2
        in      al,TMR                  ;get bits ( 7-0) << 1
        mov     ah,TMR                  ;get bits (14-8) << 1
        sti
        xchg    al,ah                   ;ax = bits 15-0
        rcr     ax,1
        test    ax,07fffh               ;if bits (14-0) == 0 re-get
        jz      Tmrgt0
        cmp     dx,IntCnt               ;if int occured re-get
        jne     Tmrgt0
        neg     ax                      ;make count positive
        ret

Tmrgt1: in      al,TMR                  ;get bits ( 7-0)
        mov     ah,TMR                  ;get bits (15-8)
        sti
        xchg    al,ah                   ;ax = bits 15-0
        cmp     dx,IntCnt               ;if int occured re-get
        jne     Tmrgt0
        neg     ax                      ;make count positive
        ret

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。