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.运行测试

相关推荐
Zwawa20 分钟前
GPS 模块怎么用:NMEA 语句怎么读、度分怎么换算成度、校验和怎么验,以及 GNSS、IMU 和轮子怎么融合出位置
c语言·单片机·嵌入式
en.en..3 小时前
UART 与 RTS/CTS 硬件流控:理清二者的从属关系
单片机
网易独家音乐人Mike Zhou1 天前
【STM32】STM32WB55 BLE Notify 配置文档 —— 从 CubeMX 开服务到手机收到数据
stm32·单片机·mcu·嵌入式·蓝牙·iot·ble
女神下凡1 天前
芯易选(133):建荣(AppoTech)_开发指南
linux·arm开发·stm32·单片机·嵌入式硬件
网易独家音乐人Mike Zhou1 天前
【STM32】STM32WB55 BLE 广播不出来 —— 排查与烧录避坑记录
stm32·单片机·mcu·物联网·嵌入式·蓝牙·ble
Brilliantwxx1 天前
【项目】 智慧监测系统 开发笔记(三)界面切换、阀值保存、TB6612、联网、ESP8266机智云、语音控制、智能公元
笔记·stm32·单片机·嵌入式硬件
wuyk5551 天前
嵌入式故障诊断-Bug016-指针强转对齐错误非对齐访问HardFault
stm32·单片机·嵌入式硬件·mcu
凯基迪科技2 天前
芯片解密:MCU 单片机解密原理、方案流程与避坑实战指南
单片机·芯片解密·单片机解密·stm32程序提取·muc解密
辰哥单片机设计2 天前
STM32智能家居(机智云)丨2027单片机新项目
stm32·单片机·嵌入式硬件
女神下凡3 天前
芯参谋(131):山景(MVsilicon)_开发指南
linux·arm开发·stm32·单片机·嵌入式硬件