8086 Proteus 8253制作跑表

1.构建系统

2.驱动代码

cpp 复制代码
.MODEL	SMALL
.8086
.stack
.code
.startup
NMI_init: push es        ;NMI中断向量初始化
      xor ax, ax
      mov es, ax
      mov al, 02h
      xor ah, ah
      shl ax, 1
      shl ax, 1
      mov si, ax
      mov ax, offset NMI_service
      mov es:[si], ax
      inc si
      inc si
      mov bx, cs
      mov es:[si], bx
      pop es 
 mov al,10110101b       ;T2 16位 mode2 bcd
mov dx,0406h
 out dx,al
 mov dx,0404h
 mov ax,1000h ;clk=100KHz 1000分频 out=100Hz=0.01秒  
 out dx,al 
 mov al,ah                 ;高字节
 out dx,al
 lop: call key 
      call disp
      jmp lop 
      
 disp proc                 ;显示子程序
      mov bl,m_sec
      and bx,000fh         ;毫秒个位
      mov si,bx      
      mov al,situation[si] ;毫秒个位段码 
      mov bl,m_sec
      and bx,00f0h         ;毫秒十位
      mov cl,4         
      shr bx,cl            
      mov si,bx      
      mov ah,situation[si] ;毫秒十位段码         
      mov dx,0000h         ;毫秒输出地址 
      out dx,ax 
    
      mov bl,sec
      and bx,000fh
      mov si,bx      
      mov al,situation[si] 
      mov bl,sec
      and bx,00f0h
      mov cl,4         
      shr bx,cl
      mov si,bx      
      mov ah,situation[si]          
      mov dx,0200h         ;秒输出地址 
      out dx,ax 
      ret     
disp  endp 

key     proc near
        mov dx,0600h
        in  al,dx
        test al,01h   
        jnz  exitkey     
        call delay          ;消抖      
        mov dx,0600h
        in  al,dx
        test al,01h
        jnz  exitkey
        inc  state
 waitkey:in  al,dx    
        test al,01h   
        jz   waitkey       ;等待按键释放 
        cmp  state,03h
        jb   exitkey
        mov  state,0        
exitkey:ret
key     endp

;fosc=5MHz,T=0.2us,Td ≈20ms
delay    proc  near         ;延时子程序
         push bx
         push cx
         mov bx,1           ;4
del1:    mov cx,5882        ;4
del2:    loop del2          ;17/5
         dec bx             ;2
         jnz del1           ;16/4
         pop cx
         pop bx
         ret
delay    endp 
       
NMI_service:
      push ax 
      cmp state,0h         ;state=0,时钟清0
      je  clear
      cmp state,01h        ;state=1,时钟走时      
      je  start
      cmp state,02h        ;state=2,时钟停止 
      je  stop
      jmp  exit
clear:mov m_sec,0
      mov sec,0
      jmp exit      
start:mov al,m_sec    
      add al,1             ;毫秒+1
      daa     
      mov m_sec,al  
      cmp m_sec,00h
      jne exit      
      mov m_sec,0  
      mov al,sec
      add al,1             ;秒+1
      daa     
      mov sec,al  
      cmp sec,60h
      jb  exit      
      mov sec,0
      jmp exit
stop: 
exit: pop ax
      iret 
.data 
state         db 0;0_clear,1_start,2_stop
m_sec         db 00h 
sec           db 00h
situation   db 3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH ;共阴    
sit_end=$ 	
END

3.运行测试

相关推荐
star learning white3 小时前
STM32入门学习5
stm32·嵌入式硬件·学习
新晨单片机设计4 小时前
S006A-基于STM32单片机温湿度检测系统【Proteus仿真+Keil程序+原理图】
stm32·单片机·proteus
逐步前行6 小时前
ESP32-S3-分区表(Partition Table)
单片机
星河单片机6 小时前
STM32驱动HS‑S37A水位传感器+OLED完整实验讲解
stm32·单片机·嵌入式硬件
代码不接地7 小时前
【EDA】0.公共部分&元件库设计
嵌入式硬件
糖糖单片机设计7 小时前
STM32水稻苗大棚环境监测系统
stm32·单片机·嵌入式硬件
star learning white9 小时前
STM32入门学习3
stm32·单片机·学习
jianqiang.xue9 小时前
审查技能库(上):内存安全四件套
stm32·单片机·物联网·架构·esp32
XiHongShi20169 小时前
cpuz分享,建议保存
单片机·学习
恒锐丰科技林技术员9 小时前
EG2226 全桥驱动芯片:高压电机逆变驱动的高性价比方案
经验分享·嵌入式硬件·硬件工程