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

相关推荐
xuxie9912 小时前
start9 霍尔双相编码器
单片机
兆龙电子单片机设计12 小时前
【STM32项目开源】STM32单片机语音分类垃圾桶-蓝牙APP
stm32·单片机·嵌入式硬件·物联网·开源·自动化·毕业设计
零涂毕业设计13 小时前
毕业设计模块开发-OLED显示屏(IIC协议0.96寸)STM32 ESP32 FPGA Linux驱动免费分享
linux·stm32·单片机·嵌入式·esp32·fpga·oled
阿龙的工作记录14 小时前
深入理解Linux设备驱动模型
linux·嵌入式硬件·工作记录
ye1501277745514 小时前
220V转5V1A隔离芯片WT5602
单片机·嵌入式硬件·其他·硬件工程
武汉万象奥科15 小时前
AGV导航控制器方案 | 基于HD-RK3576系列核心板的算控融合一体化平台
arm开发·嵌入式硬件·arm核心板·单板机
ye1501277745516 小时前
DC24V-100V转3.3V500mA隔离芯片WT5602
单片机·嵌入式硬件·其他·硬件工程
Lumos6fly16 小时前
51单片机从零到实战(15)——数字时钟温度计
单片机·嵌入式硬件·51单片机
gwf21616 小时前
磨损均衡算法(Wear Leveling)——SSD如何让每块闪存“公平退休“?
运维·数据库·人工智能·python·嵌入式硬件·算法·智能硬件
zlinear数据采集卡18 小时前
从“脏信号”到“纳伏级纯净”:硬核拆解DABL7606的多级抗混叠滤波与24位过采样算法
arm开发·科技·嵌入式硬件·fpga开发·开源