;-------------------------------------------------------------------------------------------
;8088.asm是汇编源程序
;8088.bin是编译生成的可下载执行的最终代码
;
;编译很简单,双击make即可自动完成
;
;Notepad++是我计算机上Notepad++的快捷方式
;---------------------------------------------------------------------------------------------
led_port equ 800h
_8255_port3 equ 203h
_8255_porta equ 200h
_8255_portb equ 201h
_8255_portc equ 202h
; port_8259_0 equ 700h
; port_8259_1 equ 702h
port_8259_0 equ 400h
port_8259_1 equ 402h
dy_bit7 equ 010111111b
dy_bit8 equ 001111111b
set_key equ 0eh
add_key equ 0dh
dec_key equ 0bh
ok_key equ 07h
;---------------------------------------------------------------------------------------------
org 2000h ;程序将由监控bios下载到内存RAM的地址(0000:2000)
start:
;------------------------------------------------------
;init part
;------------------------------------------------------
mov ax,0
mov ds,ax
mov ss,ax
mov sp,7fffh
;---------------------------------------------------------
;8255 init
;---------------------------------------------------------
call _8255_init
call _8253_init
call nmi_init
call init8259
call COM_INIT
call uart_int_init
;call _8255_disp
;call _8255_key
;mov al,[LED_CODE]
;mov dx,_8255_porta
;out dx,al
;mov al,0feh
;mov dx,_8255_portb
;out dx,al
;jmp start
st001:
nop
; mov ax,offset start
; mov bx,seg start
nop
;call nmi_init
; call _8255_disp
;call _8255_key
call hour_modify
call min_modify
call key_todo
;---------------------------------------
;output sp register
;---------------------------------------
;mov ax,sp
;mov [x100],ax
;call data_out
;call reg_out
;-----------------------------------------------------
;点亮系统板上的LED
;-----------------------------------------------------
;MOV DX,800H ;800H是板子上8个LED的端口地址号
mov dx,led_port
MOV AL,0aaH ;一亮一灭间隔点亮
OUT DX,AL
call DELAY
;MOV DX,800H ;800H是板子上8个LED的端口地址号
mov dx,led_port
MOV AL,00H ;一亮一灭间隔点亮
OUT DX,AL
call DELAY
; mov ah,[cnt]
; call SEND
; mov ah,'$'
; call SEND
; lea di,STR1 ;nasm编译器不认
; mov di, STR1
; CALL STR_OUT
; mov di, STR3
; CALL STR_OUT
;mov al,01010101b
;mov al,0f0h;
;out 25H,al
;hlt
call time2BCD
jmp st001
jmp start
;------------------------------------------------------------
; DELAY PROC NEAR
;------------------------------------------------------------
;push
DELAY:
PUSH CX
PUSH BX
NOP
NOP
mov bx,10
del1:
mov cx,5882
del2:
loop del2
dec bx
jnz del1
;pop cx
;pop bx
POP BX
POP CX
RET
;-------------------------------------------
;pc16550 uart send by AH
;-------------------------------------------
LSTAT EQU 1F5H
DAT_165 EQU 1F0H
SEND: ; PROC NEAR
push dx
push ax
MOV DX,LSTAT
WAITx:
IN AL,DX
TEST AL,20H
JZ WAITx
MOV AL,AH
MOV DX,DAT_165
OUT DX,AL
pop ax
pop dx
RET
;SEND ENDP
;-------------------------------------------
;串口打印字符串
;-------------------------------------------
STR_OUT :; PROC NEAR
nop; LEA DI,STR1
push ax
push di
STR_LOOP:
;MOV AH,BYTE PTR [DI]
mov ah,byte [di]
CMP AH,'$'
JZ STR_EXIT
CALL SEND
INC DI
JMP STR_LOOP
STR_EXIT: NOP
pop di
pop ax
RET
;-----------------------------
;8255 init
;-----------------------------
_8255_init:
;mov dx,203h
mov dx, _8255_port3
;mov al,80h
mov al,89h;port a,b as output port c as input
out dx,al
ret
_8255_disp:
;bit 0
mov al,[LED_CODE]
mov dx,_8255_porta
out dx,al
;mov al,0feh
mov al, 011111110b
mov dx,_8255_portb
out dx,al
call DELAY
;bit 1
mov al,[LED_CODE+1]
mov dx,_8255_porta
out dx,al
;mov al,0feh
mov al, 011111101b
mov dx,_8255_portb
out dx,al
call DELAY
;bit 2
mov al,[LED_CODE+2]
mov dx,_8255_porta
out dx,al
;mov al,0feh
mov al, 011111011b
mov dx,_8255_portb
out dx,al
call DELAY
;bit 3
mov al,[LED_CODE+3]
mov dx,_8255_porta
out dx,al
;mov al,0feh
mov al, 011110111b
mov dx,_8255_portb
out dx,al
call DELAY
;bit 4
mov al,[LED_CODE+4]
mov dx,_8255_porta
out dx,al
;mov al,0feh
mov al, 011101111b
mov dx,_8255_portb
out dx,al
call DELAY
;bit 5
mov al,[LED_CODE+5]
mov dx,_8255_porta
out dx,al
;mov al,0feh
mov al, 011011111b
mov dx,_8255_portb
out dx,al
call DELAY
;bit 6
mov al,[LED_CODE+6]
mov dx,_8255_porta
out dx,al
;mov al,0feh
mov al, 010111111b
mov dx,_8255_portb
out dx,al
call DELAY
;bit 7
mov al,[LED_CODE+7]
mov dx,_8255_porta
out dx,al
;mov al,0feh
mov al, 001111111b
mov dx,_8255_portb
out dx,al
call DELAY
ret
;------------------------------------------
;8255 key
;------------------------------------------
_8255_key:
MOV DX,202H
IN AL,DX
TEST AL,01H
;JNZ NO_KEY
jnz key100
;INC KEY_CNT
mov di, STR4
CALL STR_OUT
key100:
MOV DX,202H
IN AL,DX
TEST AL,02H
; JNZ NO_KEY
jnz key200
;INC KEY_CNT
mov di, STR4
CALL STR_OUT
key200:
MOV DX,202H
IN AL,DX
TEST AL,04H
JNZ NO_KEY
;INC KEY_CNT
mov di, STR4
CALL STR_OUT
NO_KEY:
NOP
ret
;---------------------------------------------
;NMI init
;---------------------------------------------
nmi_init:
push es
xor ax,ax
mov es,ax
mov al,02h
xor ah,ah
shl ax,1
shl ax,1
mov si,ax
mov ax,nmi_isr
mov [es:si],ax
inc si
inc si
mov bx,cs
mov [es:si],bx
pop es
nop
ret
;---------------------------------------------
;NMI ISR
;---------------------------------------------
nmi_isr:
push di
push bx
push ax
nop
jmp isr1000
; mov di, STR5
; CALL STR_OUT
;inc [cnt]
mov al,[cnt]
inc al
cmp al,8
jl isr100
mov al,0
isr100:
nop
mov [cnt],al
;bit 0
cmp al,0
jnz isr200
;bit 0
mov ax,0
mov al,[sec0]
mov si,ax
; mov si,sec0
;mov al,[LED_CODE+si]
mov al,0ffh
mov dx,_8255_porta
out dx,al
;mov al,0feh
mov al, 011111110b
mov dx,_8255_portb
out dx,al
;call DELAY
isr200:
nop
;bit 1
cmp al,1
jnz isr300
;bit 1
; mov bx,0
; mov bl,[sec0]
mov bx,[sec]
;mov al,[LED_CODE+1]
;mov al,[LED_CODE+bx]
mov al,0ffh
mov dx,_8255_porta
out dx,al
;mov al,0feh
mov al, 011111101b
mov dx,_8255_portb
out dx,al
isr300:
nop
;bit 2
cmp al,2
jnz isr400
;bit 1
;小时的十位显示
cmp word[flash_cnt],100
;jl disp_hour
jmp disp_hour
mov al,0ffh
jmp disp_100
disp_hour:
mov bx,[hour10]
mov al,[LED_CODE+BX]
disp_100:
mov dx,_8255_porta
out dx,al
;mov al,0feh
mov al, 011111011b
mov dx,_8255_portb
out dx,al
isr400:
nop
;bit 3
cmp al,3
jnz isr500
;bit 1
mov bx,[hour]
mov al,[LED_CODE+bx]
and al,7fh
mov dx,_8255_porta
out dx,al
;mov al,0feh
mov al, 011110111b
mov dx,_8255_portb
out dx,al
isr500:
;bit 4
cmp al,4
jnz isr600
;bit 1
mov bx,[min10]
mov al,[LED_CODE+bx]
mov dx,_8255_porta
out dx,al
;mov al,0feh
mov al, 011101111b
mov dx,_8255_portb
out dx,al
isr600:
;bit 5
cmp al,5
jnz isr700
;bit 1
mov bx,[min]
mov al,[LED_CODE+bx]
and al,7fh
mov dx,_8255_porta
out dx,al
;mov al,0feh
mov al, 011011111b
mov dx,_8255_portb
out dx,al
isr700:
;bit 6
cmp al,6
jnz isr800
;bit 1
mov bx,[sec10]
mov al,[LED_CODE+bx]
;and al,7fh
mov dx,_8255_porta
out dx,al
;mov al,0feh
mov al, 010111111b
mov dx,_8255_portb
out dx,al
isr800:
;bit 7
cmp al,7
jnz isr900
;bit 1
mov bx,[sec]
mov al,[LED_CODE+bx]
mov dx,_8255_porta
out dx,al
;mov al,0feh
mov al, 001111111b
mov dx,_8255_portb
out dx,al
isr900:
jmp isr1000;skip below time update part
mov bx,cnt_2ms
inc word [bx]
cmp word [bx],500
jl isr1000
mov word [bx],0
mov bx,sec
inc word[bx]
cmp word [bx],10
jl isr1000
;if(sec>9)
mov word [bx],0
mov bx,sec10;
inc word [bx]
cmp word [bx],6
jl isr1000
;if(sec10>5)
mov word [bx],0
mov bx,min
inc word [bx]
cmp word [bx],10
jl isr1000
;if(min>9)
mov word [bx],0
mov bx,min10
inc word [bx]
cmp word [bx],6
jl isr1000
mov word [bx],0
mov bx,hour
inc word [bx]
isr1000:
call time_update
inc word [flash_cnt]
cmp word [flash_cnt],200
jl isr2000
mov word [flash_cnt],0
isr2000:
call key_scan
call time_disp
call uart_get
pop ax
pop bx
pop di
iret
;-----------------------------------------------
;data_out
;-----------------------------------------------
data_out:
push di
push ax
nop
;--------------------------------------
;bit0
mov ax,000fh
and ax,[x100]
cmp al,9
ja p001
add al,'0'
jmp p002
p001:
add al,37H
p002:nop
mov [temp1],al
;bit1
mov ax,00f0h
and ax,[x100]
shr ax,4
;add al,30h
cmp al,9
ja p003
add al,'0'
jmp p004
p003:
add al,37H
p004:nop
; mov [temp1],al
mov [temp2],al
;bit2
mov ax,0f00h
and ax,[x100]
shr ax,8
;add al,30h
cmp al,9
ja p005
add al,'0'
jmp p006
p005:
add al,37H
p006:nop
;mov [temp1],al
mov [temp3],al
;bit3
mov ax,0f000h
and ax,[x100]
shr ax,12
; add al,30h
cmp al,9
ja p007
add al,'0'
jmp p008
p007:
add al,37H
p008:nop
;mov [temp1],al
mov [temp4],al
;--------------------------------------
; mov al,[temp1]
; mov [temp+8],al
; mov al,[temp2]
; mov [temp+7],al
; mov al,[temp3]
; mov [temp+6],al
; mov al,[temp4]
; mov [temp+5],al
;--------------------------------------
; mov di,temp
; call STR_OUT
pop ax
pop di
ret
;STR_OUT ENDP
;---------------------------------------------
;register out
;---------------------------------------------
reg_out:
nop
mov di,reg_str
call STR_OUT
;---------------------------------------------------
;mov ax,5678h
mov [x100],ax
call data_out
mov al,[temp4]
mov [ax_str+3],al
mov al,[temp3]
mov [ax_str+4],al
mov al,[temp2]
mov [ax_str+5],al
mov al,[temp1]
mov [ax_str+6],al
mov di,ax_str
call STR_OUT
;-----------------------------------------------------
mov [x100],bx
call data_out
mov al,[temp4]
mov [bx_str+3],al
mov al,[temp3]
mov [bx_str+4],al
mov al,[temp2]
mov [bx_str+5],al
mov al,[temp1]
mov [bx_str+6],al
mov di,bx_str
call STR_OUT
;-------------------------------------------------------
mov [x100],cx
call data_out
mov al,[temp4]
mov [cx_str+3],al
mov al,[temp3]
mov [cx_str+4],al
mov al,[temp2]
mov [cx_str+5],al
mov al,[temp1]
mov [cx_str+6],al
mov di,cx_str
call STR_OUT
;-------------------------------------------------------
mov [x100],dx
call data_out
mov al,[temp4]
mov [dx_str+3],al
mov al,[temp3]
mov [dx_str+4],al
mov al,[temp2]
mov [dx_str+5],al
mov al,[temp1]
mov [dx_str+6],al
mov di,dx_str
call STR_OUT
;--------------------------------------------------------
mov ax,cs
mov [x100],ax
call data_out
mov al,[temp4]
mov [cs_str+3],al
mov al,[temp3]
mov [cs_str+4],al
mov al,[temp2]
mov [cs_str+5],al
mov al,[temp1]
mov [cs_str+6],al
mov di,cs_str
call STR_OUT
;-------------------------------------------------------
mov ax,ds
mov [x100],ax
call data_out
mov al,[temp4]
mov [ds_str+3],al
mov al,[temp3]
mov [ds_str+4],al
mov al,[temp2]
mov [ds_str+5],al
mov al,[temp1]
mov [ds_str+6],al
mov di,ds_str
call STR_OUT
;-------------------------------------------------------
mov ax,ss
mov [x100],ax
call data_out
mov al,[temp4]
mov [ss_str+3],al
mov al,[temp3]
mov [ss_str+4],al
mov al,[temp2]
mov [ss_str+5],al
mov al,[temp1]
mov [ss_str+6],al
mov di,ss_str
call STR_OUT
;--------------------------------------------------------
mov ax,es
mov [x100],ax
call data_out
mov al,[temp4]
mov [es_str+3],al
mov al,[temp3]
mov [es_str+4],al
mov al,[temp2]
mov [es_str+5],al
mov al,[temp1]
mov [es_str+6],al
mov di,es_str
call STR_OUT
;-----------------------------------------------------------
mov ax,sp
mov [x100],ax
call data_out
mov al,[temp4]
mov [sp_str+3],al
mov al,[temp3]
mov [sp_str+4],al
mov al,[temp2]
mov [sp_str+5],al
mov al,[temp1]
mov [sp_str+6],al
mov di,sp_str
call STR_OUT
;-----------------------------------------------------------
mov ax,start
mov [x100],ax
call data_out
mov al,[temp4]
mov [ip_str+3],al
mov al,[temp3]
mov [ip_str+4],al
mov al,[temp2]
mov [ip_str+5],al
mov al,[temp1]
mov [ip_str+6],al
mov di,ip_str
call STR_OUT
;-----------------------------------------------------------
mov di,reg_str
call STR_OUT
ret
;--------------------------------------------------------
;intel 8253 init
;--------------------------------------------------------
;8253 init t0 timer
;-----------------------------
_8253_init:
nop
mov al,00110111b
; mov al,00110110b;工作方式设置
mov dx,303h
out dx,al
mov dx,300h;低字节
mov al,00h
;mov al,40h
out dx,al
mov al,40h;高字节
;mov al,9ch
out dx,al
;-----------------------------
;8253 init t1 timer
;-----------------------------
mov al,01110111b
mov dx,303h
out dx,al
mov dx,301h
mov al,00h
out dx,al
mov al,01h
out dx,al
;-----------------------------
;8253 init t2 timer
;-----------------------------
mov al,10110111b
mov dx,303h
out dx,al
mov dx,302h
mov al,00h
out dx,al
mov al,01h
out dx,al
ret
;--------------------------------------------------------
;hour_x dw 23
time2BCD:
nop
;for hour conver to BCD code
mov ax,[hour_x]
mov bl,10
div bl ;al 商 ah 余数
mov byte [hour],ah
mov byte [hour10],al
;for min_x conver to BCD code
mov ax,[min_x]
mov bl,10
div bl ;al 商 ah 余数
mov byte [min],ah
mov byte [min10],al
;for sec_x conver to BCD code
mov ax,[sec_x]
mov bl,10
div bl ;al 商 ah 余数
mov byte [sec],ah
mov byte [sec10],al
ret
;-----------------------------------------------------
time_update:
inc word [cnt_2ms]
cmp word [cnt_2ms],500
jnz time_update_exit
mov word [cnt_2ms],0
inc word [sec_x]
cmp word [sec_x],60
jnz time_update_exit
mov word [sec_x],0
inc word [min_x]
cmp word [min_x],60
jnz time_update_exit
mov word [min_x],0
inc word [hour_x]
cmp word [hour_x],24
jnz time_update_exit
mov word [hour_x],0
time_update_exit:
nop
ret
;---------------------------------------------------
;键盘定时扫描子程序,2ms执行一次
;---------------------------------------------------
key_scan:
inc word [key_cnt]
cmp word [key_cnt],10 ;20ms计时
jnz .exit0
mov word [key_cnt],0
MOV DX,202H;读取按键
IN AL,DX
and al,0fH
.state0:
cmp word [key_state],0
jnz .state1
cmp al,0fh
jz .exit0;no key press
inc word [key_state]
jmp .exit0 ;break and return
.state1:
cmp word [key_state],1
jnz .state2
cmp al,0fH
jz .state_reset
inc word [key_state]
mov byte [key_code],al
mov word [key_flag],1
jmp .exit0
.state2:
cmp word [key_state],2
jnz .state_reset
cmp al,0fH
jz .state_reset
jmp .exit0
nop
.state_reset:
mov word [key_state],0
.exit0:
nop
ret
;-----------------------------------------------------
;按键事件处理程序
;------------------------------------------------------
key_todo:
cmp word [key_flag],1
jnz .exit0
mov word [key_flag],0
mov di, STR6
CALL STR_OUT
mov ah,[key_code]
call SEND
cmp byte[key_code],0eh
jnz .exit0
inc word [state]
cmp word [state],3
jl .exit0
mov word[state],0
.exit0:
nop
ret
;----------------------------------------------------
hour_modify:
nop
cmp word [state],1
jnz .exit0
cmp word [key_flag],1
jnz .exit0
cmp byte [key_code],add_key
jnz .dec
inc word [hour_x]
cmp word [hour_x],24
jnz .dec
mov word [hour_x],0
.dec:
cmp byte [key_code],dec_key
jnz .exit0
;inc word [hour_x]
; cmp word [hour_x],0
; jz .exit0
dec word [hour_x]
;mov word [hour_x],0
.exit0:
nop
ret
;----------------------------------------------------
min_modify:
nop
cmp word [state],2
jnz .exit0
cmp word [key_flag],1
jnz .exit0
cmp byte [key_code],add_key
jnz .dec
inc word [min_x]
cmp word [min_x],60
jnz .dec
mov word [min_x],0
.dec:
cmp byte [key_code],dec_key
jnz .exit0
;inc word [hour_x]
; cmp word [hour_x],0
; jz .exit0
dec word [min_x]
;mov word [hour_x],0
.exit0:
nop
ret
;----------------------------------------------------
;时间显示函数
;----------------------------------------------------
time_disp:
;hour disp
;jmp .bit2
.bit0:
cmp word [disp_cnt],0
jnz .bit1
cmp word [state],1
jnz .1;不闪烁
;闪烁
cmp word[flash_cnt],100
jl .11
;mov bx,[hour10]
;mov al,[LED_CODE+BX]
mov al,0ffh
mov dx,_8255_porta
out dx,al
;mov al,0feh
mov al, 011111011b
mov dx,_8255_portb
out dx,al
jmp .bit1
.11:
mov bx,[hour10]
mov al,[LED_CODE+BX]
mov dx,_8255_porta
out dx,al
;mov al,0feh
mov al, 011111011b
mov dx,_8255_portb
out dx,al
jmp .bit1
.1:
mov bx,[hour10]
mov al,[LED_CODE+BX]
mov dx,_8255_porta
out dx,al
;mov al,0feh
mov al, 011111011b
mov dx,_8255_portb
out dx,al
.bit1:
cmp word [disp_cnt] ,1
jnz .bit2
; mov bx,[hour]
; mov al,[LED_CODE+BX]
; mov dx,_8255_porta
; out dx,al
; ;mov al,0feh
; mov al, 011111101b
; mov dx,_8255_portb
; out dx,al
cmp word [state],1
jnz .2;不闪烁
;闪烁
cmp word[flash_cnt],100
jl .22
;mov bx,[hour10]
;mov al,[LED_CODE+BX]
mov al,0ffh
mov dx,_8255_porta
out dx,al
;mov al,0feh
mov al, 011110111b
mov dx,_8255_portb
out dx,al
jmp .bit2
.22:
mov bx,[hour]
mov al,[LED_CODE+BX]
and al,7fh
mov dx,_8255_porta
out dx,al
;mov al,0feh
mov al, 011110111b
mov dx,_8255_portb
out dx,al
jmp .bit2
.2:
mov bx,[hour]
mov al,[LED_CODE+BX]
and al,7fh
mov dx,_8255_porta
out dx,al
;mov al,0feh
mov al, 011110111b
mov dx,_8255_portb
out dx,al
.bit2:;分钟的十位
cmp word [disp_cnt] ,2
jnz .bit3
; mov bx,[hour]
; mov al,[LED_CODE+BX]
; mov dx,_8255_porta
; out dx,al
; ;mov al,0feh
; mov al, 011111101b
; mov dx,_8255_portb
; out dx,al
cmp word [state],2
jnz .3;不闪烁
;闪烁
cmp word[flash_cnt],100
jl .33
;mov bx,[hour10]
;mov al,[LED_CODE+BX]
mov al,0ffh
mov dx,_8255_porta
out dx,al
;mov al,0feh
mov al, 011101111b
mov dx,_8255_portb
out dx,al
jmp .bit3
.33:
mov bx,[min10]
mov al,[LED_CODE+BX]
mov dx,_8255_porta
out dx,al
;mov al,0feh
mov al, 011101111b
mov dx,_8255_portb
out dx,al
jmp .bit3
.3:
mov bx,[min10]
mov al,[LED_CODE+BX]
mov dx,_8255_porta
out dx,al
;mov al,0feh
mov al, 011101111b
mov dx,_8255_portb
out dx,al
.bit3:;分钟的个位
cmp word [disp_cnt] ,3
jnz .bit4
; mov bx,[hour]
; mov al,[LED_CODE+BX]
; mov dx,_8255_porta
; out dx,al
; ;mov al,0feh
; mov al, 011111101b
; mov dx,_8255_portb
; out dx,al
cmp word [state],2
jnz .4;不闪烁
;闪烁
cmp word[flash_cnt],100
jl .44
;mov bx,[hour10]
;mov al,[LED_CODE+BX]
mov al,0ffh
mov dx,_8255_porta
out dx,al
;mov al,0feh
mov al, 011011111b
mov dx,_8255_portb
out dx,al
jmp .bit4
.44:
mov bx,[min]
mov al,[LED_CODE+BX]
and al,7fh
mov dx,_8255_porta
out dx,al
;mov al,0feh
mov al, 011011111b
mov dx,_8255_portb
out dx,al
jmp .bit4
.4:
mov bx,[min]
mov al,[LED_CODE+BX]
and al,7fh
mov dx,_8255_porta
out dx,al
;mov al,0feh
mov al, 011011111b
mov dx,_8255_portb
out dx,al
.bit4:;秒的十位
cmp word [disp_cnt] ,4
jnz .bit5
mov bx,[sec10]
mov al,[LED_CODE+BX]
mov dx,_8255_porta
out dx,al
;mov al,0feh
mov al, dy_bit7
mov dx,_8255_portb
out dx,al
.bit5:;秒的个位
cmp word [disp_cnt] ,5
jnz .exit1
mov bx,[sec]
mov al,[LED_CODE+BX]
mov dx,_8255_porta
out dx,al
;mov al,0feh
mov al, dy_bit8
mov dx,_8255_portb
out dx,al
.exit1:
;显示计数器更新
inc word [disp_cnt]
cmp word[disp_cnt],6
jnz .exit0
mov word [disp_cnt],0
.exit0:
nop
ret
;----------------------------------------------------
init8259 :
nop
mov dx,port_8259_0
mov al,17h
out dx,al
mov dx,port_8259_1
;mov al,00h
mov al,08h ;中断号 08h-0fH
out dx,al
mov al,0fh
out dx,al
;mov al,0feh
mov al,0f0h
out dx,al
; push es
; mov ax,0
; mov es,ax
; mov di,00h
; mov es:[di],offset ISR_8259
; add di,2
; mov es:[di],cs
; pop es
push es
xor ax,ax
mov es,ax
; mov al,00h
; xor ah,ah
; shl ax,1
; shl ax,1
mov ax,20h
mov si,ax
mov ax,nmi_isr
mov [es:si],ax
inc si
inc si
mov bx,cs
mov [es:si],bx
mov ax,24h ;09H interrupt vector
mov si,ax
mov ax,nmi_isr
mov [es:si],ax
inc si
inc si
mov bx,cs
mov [es:si],bx
pop es
nop
sti
ret
;------------------------------------------------
;串口接收,将收到的数据存到AH中
;------------------------------------------------
;LSTAT EQU 1F5H
;DAT_165 EQU 1F0H
LINE_165 EQU 1F3H
LSB_165 EQU 1F0H
MSB_165 EQU 1F1H
FIFO_165 EQU 1F2H
ITR EQU 1F1H
;FIFO_165 EQU 1F2H
;---------------------------------------------------
;16650 init
;---------------------------------------------------
COM_INIT:; PROC NEAR
;LINE
MOV AL,8AH
;MOV DX,1F3H
MOV DX,LINE_165
OUT DX,AL
CALL DELAY
;CALL DELAY
;CALL DELAY
;CALL DELAY
;LSB
MOV AL,120
;MOV DX,1F0H
MOV DX,LSB_165
OUT DX,AL
CALL DELAY
;CALL DELAY
;CALL DELAY
;CALL DELAY
;MSB
MOV AL,0
;MOV DX,1F1H
MOV DX,MSB_165
OUT DX,AL
CALL DELAY
;CALL DELAY
;CALL DELAY
;CALL DELAY
;LINE
;MOV AL,0AH
MOV AL,03H
;MOV DX,1F3H
MOV DX,LINE_165
OUT DX,AL
CALL DELAY
;CALL DELAY
;CALL DELAY
;CALL DELAY
;FIFO
;MOV AL,07H
MOV AL,17H
;MOV DX,1F2H
MOV DX,FIFO_165
OUT DX,AL
CALL DELAY
;CALL DELAY
;CALL DELAY
;CALL DELAY
;MOV DX,800H
MOV DX,led_port
MOV AL,0f0H
OUT DX,AL
RET
;COM_INIT ENDP
uart_int_init:
nop
mov al,1
mov dx,ITR
out dx,al
ret
uart_get:
nop
uart_LP1:
nop
mov dx,LSTAT
in al,dx
test al,01h;bit0(DR bit) 0 no data,1,has data
;jz uart_LP1; if no data ,polling again
jz .exit
mov dx, DAT_165
in al,dx
mov ah,al
call SEND;send data has get
.exit:
nop
ret
; ISR_8259 :
; nop
; ;MOV DX,800H ;800H是板子上8个LED的端口地址号
; ;MOV AL,0FFH ;一亮一灭间隔点亮
; ;OUT DX,AL
; inc dat8259
; iret
;----------------------------------------------
cnt db 100
STR1 DB 'i8088-HELLO boy or girl!' ,13,10,'$'
STR2 DB 0AH,0DH,' ',0dh,0ah,'$'
STR3 db 'ex006---8253 timer demo',13,10,'$'
STR4 db 'key0 event happen!',13,10,'$'
STR5 db 'nmi happen!',13,10,'$'
STR6 db 'xxx key event happen!',13,10,'$'
LED_CODE db 0C0h,0F9h,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H
temp db 'temp=1234h',13,10,'$'
temp1 db 'a'
temp2 db 'b'
temp3 db 'c'
temp4 db 'd'
x100 dw 0ABCDh
reg_str db '----------8088 CPU Register Out-------------',13,10,'$'
ax_str db 'AX=1234h',13,10,'$'
bx_str db 'BX=5678h',13,10,'$'
cx_str db 'CX=ABCDh',13,10,'$'
dx_str db 'DX=EF00h',13,10,'$'
cs_str db 'CS=1234h',13,10,'$'
ds_str db 'DS=5678h',13,10,'$'
ss_str db 'SS=ABCDh',13,10,'$'
es_str db 'ES=EF00h',13,10,'$'
sp_str db 'SP=EF00h',13,10,'$'
ip_str db 'IP=EF00h',13,10,'$'
sec0 db 6
sec dw 0
sec10 dw 0
min dw 0
min10 dw 0
hour dw 0
hour10 dw 0
cnt_2ms dw 0
hour_x dw 14
min_x dw 0
sec_x dw 0
flash_cnt dw 0
state dw 0
key_cnt dw 0
key_state dw 0
key_flag dw 0
key_code db 0
disp_cnt dw 0
db 55h,55h,55h,55h,55h,55h ;程序结束标志,监控bios程序,收到后自动跳转到内存0000:2000处执行
;----------------------------------------------------------------------------------------------