微机实验1\ 4~6\8\10(中断实验/8254/8255)

实验01 存储器读写

在这里插入图片描述
在这里插入图片描述

实验04 中断实验

TPC04_1.ASM

 	include io.inc
	.model small
	.stack
	.data
intmsg byte 'You are so cute!',13,10,0
counter byte 0
	.code
start:
	mov ax,@data
	mov ds,ax

	mov ax,350bh
	int 21h
	push es
	push bx
	cli
	push ds
	mov ax,seg new0bh
	mov ds,ax
	mov dx,offset new0bh
	mov ax,250bh
	int 21h
	pop ds

	in al,21h
	push ax
	and al,0f7h
	out 21h,al
	mov counter,0
	sti

start1:
	cmp counter,5
	jb start1
	cli
	pop ax
	out 21h,al
	pop dx
	pop ds
	mov ax,250bh
	int 21h
	sti
	.exit 0


new0bh proc
	sti
	push ax
	push si
	push ds
	mov ax,@data
	mov ds,ax
	inc counter
	mov si,offset intmsg
	call dpstri
	mov al,20h
	out 20h,al
	pop ds
	pop si
	pop ax
	iret
new0bh endp

dpstri proc
	push ax
	push bx
dps1:
	mov al,[si]
	cmp al,0
	jz dps2
	mov bx,0
	mov ah,0eh
	int 10h
	inc si
	jmp dps1
dps2:	
	pop bx
	pop ax
	ret
dpstri endp




	;.exit 0
	end start

TPC04_2.ASM

 	include io.inc
	.model small
	.stack
	.data
intmsg byte 'TPCA Interrupt No.10!',13,10,0
counter byte 0
	.code
start:
	mov ax,@data
	mov ds,ax

	mov ax,3572h
	int 21h
	push es
	push bx
	cli
	push ds
	mov ax,seg new72h
	mov ds,ax
	mov dx,offset new72h
	mov ax,2572h
	int 21h
	pop ds

	in al,21h
	push ax
	and al,0fbh
	out 21h,al
	in al,0a1h
	push ax
	and al,0fbh
	out 0a1h,al
	
	mov counter,0
	sti

start1:
	cmp counter,5
	jb start1
	cli
	pop ax
	out 0a1h,al
	pop ax
	out 21h,al
	pop dx
	pop ds
	mov ax,2572h
	int 21h
	sti
	.exit 0


new72h proc
	sti
	push ax
	push si
	push ds
	mov ax,@data
	mov ds,ax
	inc counter
	mov si,offset intmsg
	call dpstri
	mov al,20h
	out 0a0h,al
	out 20h,al
	pop ds
	pop si
	pop ax
	iret
new72h endp

dpstri proc
	push ax
	push bx
dps1:
	mov al,[si]
	cmp al,0
	jz dps2
	mov bx,0
	mov ah,0eh
	int 10h
	inc si
	jmp dps1
dps2:	
	pop bx
	pop ax
	ret
dpstri endp




	;.exit 0
	end start

TPC04_3.ASM

  	include io.inc
	.model small
	.stack
	.data
msg3 byte 'TPCA Interrupt No.3!',13,10,0
msg31 byte 'TPCA Interrupt No.3 AGAIN!',13,10,0
msg10 byte 'TPCA Interrupt No.10!',13,10,0
msg101 byte 'TPCA Interrupt No.10 AGAIN!',13,10,0

ioff3 word ?
iseg3 word ?

ioff10 word ?
iseg10 word ?



counter3 byte 0
counter10 byte 0
	.code
start:
	mov ax,@data
	mov ds,ax



	mov ax,350bh
	int 21h
	mov iseg3,es
	mov ioff3,bx

	mov ax,3572h
	int 21h
	mov iseg10,es
	mov ioff10,bx

	cli
	push ds
	mov ax,seg new0bh
	mov ds,ax
	mov dx,offset new0bh
	mov ax,250bh
	int 21h
	pop ds


	push ds
	mov ax,seg new72h
	mov ds,ax
	mov dx,offset new72h
	mov ax,2572h
	int 21h
	pop ds


	in al,21h
	push ax
	and al,0f3h
	out 21h,al
	in al,0a1h
	push ax
	and al,0fbh
	out 0a1h,al
	
	mov counter3,0
	mov counter10,0
	sti

start1:
	cmp counter3,5
	jb start1
start2:
	cmp counter10,5
	jb start2

	cli
	pop ax
	out 0a1h,al
	pop ax
	out 21h,al

	mov dx,ioff3
	mov ds,iseg3
	mov ax,250bh
	int 21h

	mov dx,ioff10
	mov ds,iseg10
	mov ax,2572h
	int 21h

	sti
	.exit 0

new0bh proc
	sti
	push ax
	push si
	push ds
	mov ax,@data
	mov ds,ax
	inc counter3
	mov si,offset msg3
	call dpstri

	call delay

	mov si,offset msg31
	call dpstri
	mov al,20h
	
	out 20h,al
	pop ds
	pop si
	pop ax
	iret
new0bh endp

new72h proc
	sti
	push ax
	push si
	push ds
	mov ax,@data
	mov ds,ax
	inc counter10
	mov si,offset msg10
	call dpstri

	call delay

	mov si,offset msg101
	call dpstri
	mov al,20h
	out 0a0h,al
	out 20h,al
	pop ds
	pop si
	pop ax
	iret
new72h endp





dpstri proc
	push ax
	push bx
dps1:
	mov al,[si]
	cmp al,0
	jz dps2
	mov bx,0
	mov ah,0eh
	int 10h
	inc si
	jmp dps1
dps2:	
	pop bx
	pop ax
	ret
dpstri endp

delay	proc
	push bx
	push cx
	mov bx,2000
delay1:
	mov cx,0
delay2:
	loop delay2
	dec bx
	jne delay1
	pop cx
	pop bx
 	ret
delay endp



	;.exit 0
	end start

实验05 可编程的定时器/计数器(8253/8254)

TPC05_1.ASM

 	include io.inc
	.model small
	.stack
	.data
msg byte 'hello world!',13,10,0

	.code
start:
	mov ax,@data
	mov ds,ax
	

	mov dx,283h
	mov al,10h
	out dx,al ;ctrl
	mov al,5
	mov dx,280h
	out dx,al
	mov ah,al
again:
	call deng

	in al,dx
	cmp al,ah
	jz again
	push ax
	call dispuib
	call dispcrlf
	pop ax
	mov ah,al
	cmp al,0
	jnz again
	.exit 0
deng proc
	push cx
	mov cx,1000
deng1:
	loop deng1
	pop cx
	ret
deng endp
	end start

TPC05_2.ASM

  	include io.inc
	.model small
	.stack
	.data


	.code
start:
	mov ax,@data
	mov ds,ax
	

	mov dx,283h
	mov al,37h
	out dx,al ;ctrl
	mov ax,1000h
	mov dx,280h
	out dx,al
	mov al,ah
	out dx,al

	mov dx,283h
	mov al,77h
	out dx,al ;ctrl
	mov ax,1000h
	mov dx,281h
	out dx,al
	mov al,ah
	out dx,al	


	.exit 0
	end start

TPC05_3.ASM

 	include io.inc
	.model small
	.stack
	.data
intmsg byte 'You are so cute!',13,10,0
counter byte 0
	.code
start:
	mov ax,@data
	mov ds,ax

	mov ax,350bh
	int 21h
	push es
	push bx
	cli
	push ds
	mov ax,seg new0bh
	mov ds,ax
	mov dx,offset new0bh
	mov ax,250bh
	int 21h
	pop ds

	mov dx,283h
	mov al,37h
	out dx,al ;ctrl
	mov ax,1000h
	mov dx,280h
	out dx,al
	mov al,ah
	out dx,al

	mov dx,283h
	mov al,77h
	out dx,al ;ctrl
	mov ax,1000h
	mov dx,281h
	out dx,al
	mov al,ah
	out dx,al		






	in al,21h
	push ax
	and al,0f7h
	out 21h,al
	mov counter,0
	sti

start1:
	cmp counter,5
	jb start1
	cli
	pop ax
	out 21h,al
	pop dx
	pop ds
	mov ax,250bh
	int 21h
	sti
	.exit 0


new0bh proc
	sti
	push ax
	push si
	push ds
	mov ax,@data
	mov ds,ax
	inc counter
	mov si,offset intmsg
	call dpstri
	mov al,20h
	out 20h,al
	pop ds
	pop si
	pop ax
	iret
new0bh endp

dpstri proc
	push ax
	push bx
dps1:
	mov al,[si]
	cmp al,0
	jz dps2
	mov bx,0
	mov ah,0eh
	int 10h
	inc si
	jmp dps1
dps2:	
	pop bx
	pop ax
	ret
dpstri endp




	;.exit 0
	end start

实验06 可编程并行接口(8255)

TPC06_1.ASM

  	include io.inc
	.model small;定义程序的存储模型
	.stack;定义堆栈段
	.data
msg byte 'hello world!',13,10,0

	.code
start:
	mov ax,@data
	mov ds,ax
	
	mov al,89h   ;1000 1001方式控制字
	mov dx,28bh
	out dx,al;ctrl word
	
	mov dx,28ah
	in al,dx;rd from c
	mov dx,288h
	out dx,al;wt to a

	.exit 0

	end start

TPC06_2.ASM

  	include io.inc
	.model small
	.stack
	.data
intmsg byte 'You are so lovely!',13,10,0
light byte 01h
counter byte 0
	.code
start:
	mov ax,@data
	mov ds,ax

	mov ax,350bh
	int 21h
	push es
	push bx
	cli
	push ds
	mov ax,seg new0bh
	mov ds,ax
	mov dx,offset new0bh
	mov ax,250bh
	int 21h
	pop ds





	in al,21h
	push ax
	and al,0f7h
	out 21h,al
	mov counter,0

	mov al,0a9h  
	mov dx,28bh
	out dx,al;ctrl word
	mov al,0dh;方式1 A端口输出需设置PC6为1,且位控制字输出到控制端口
	out dx,al
	mov dx,288h
	out dx,al;out;需要先输出一次

	sti

start1:
	cmp counter,8
	jb start1
	cli
	pop ax
	out 21h,al
	pop dx
	pop ds
	mov ax,250bh
	int 21h
	sti
	.exit 0


new0bh proc
	sti
	push ax
	push si
	push ds
	mov ax,@data
	mov ds,ax
	inc counter
	
	call litlight


	;mov si,offset intmsg
	;call dpstri
	mov al,20h
	out 20h,al
	pop ds
	pop si
	pop ax
	iret
new0bh endp

dpstri proc
	push ax
	push bx
dps1:
	mov al,[si]
	cmp al,0
	jz dps2
	mov bx,0
	mov ah,0eh
	int 10h
	inc si
	jmp dps1
dps2:	
	pop bx
	pop ax
	ret
dpstri endp

litlight proc
	
	mov al,light
	call disphb
	call dispcrlf
	mov al,light
	mov dx,288h
	out dx,al;wt to a
	rol light,1


litlight endp


	;.exit 0
	end start



TPC06_3.ASM

   	include io.inc
	.model small
	.stack
	.data
intmsg byte 'You are so lovely!',13,10,0
light byte 01h
counter byte 0
	.code
start:
	mov ax,@data
	mov ds,ax

	mov ax,350bh
	int 21h
	push es
	push bx
	cli
	push ds
	mov ax,seg new0bh
	mov ds,ax
	mov dx,offset new0bh
	mov ax,250bh
	int 21h
	pop ds





	in al,21h
	push ax
	and al,0f7h
	out 21h,al
	mov counter,0

	mov al,0b9h  
	mov dx,28bh
	out dx,al;ctrl word
	mov al,09h;A端口输入需要设置PC4为1
	out dx,al
	mov dx,288h
	out dx,al;out

	sti

start1:
	cmp counter,5
	jb start1
	cli
	pop ax
	out 21h,al
	pop dx
	pop ds
	mov ax,250bh
	int 21h
	sti
	.exit 0


new0bh proc
	sti
	push ax
	push si
	push ds
	mov ax,@data
	mov ds,ax
	inc counter
	
	call litlight


	;mov si,offset intmsg
	;call dpstri
	mov al,20h
	out 20h,al
	pop ds
	pop si
	pop ax
	iret
new0bh endp

dpstri proc
	push ax
	push bx
dps1:
	mov al,[si]
	cmp al,0
	jz dps2
	mov bx,0
	mov ah,0eh
	int 10h
	inc si
	jmp dps1
dps2:	
	pop bx
	pop ax
	ret
dpstri endp

litlight proc
	mov dx,288h
	in al,dx;wt to a	
	call disphb
	call dispcrlf
	




litlight endp


	;.exit 0
	end start



实验08 数码管显示

TPC08-1.ASM

附上老师给的代码。。

;***************************
;*  LED数码管一位静态显示  *
;***************************
 include io.inc
 .model small
 .stack
 .data
led byte 3fh,06h,5bh,4fh,66h,6dh,7dh,07h,7fh,6fh    ;段码
msg byte 0dh,0ah,'Input a number (0--9), other key exit.',0dh,0ah,0
 .code
start: mov ax,@data
 mov ds,ax
 mov dx,28bh            ;使8255的A口为输出方式
 mov ax,80h
 out dx,al
again:
    mov ax,offset msg    ;显示提示信息
    call dispmsg
    call readc              ;从键盘接收字符
    cmp al,'0'             ;是否小于0
    jb  done               ;若是则退出
    cmp al,'9'             ;是否大于9
    ja  done               ;若是则退出
    sub al,30h             ;将所得字符的ASCII码减30H
    mov bx,offset led      ;bx为数码表的起始地址
    xlat                   ;求出相应的段码
    mov dx,288h            ;8255的A口输出
    out dx,al
    jmp again
done:
 .exit 0             ;返回
 end start

自己写的:

  	include io.inc
	.model small;定义程序的存储模型
	.stack;定义堆栈段
	.data
	.code
lit   byte 3fh,06h,5bh,4fh,66h,6dh,7dh,07h,7fh,6fh
start:
	mov ax,@data
	mov ds,ax
	
	mov al,80h   ;1000 1001
	mov dx,28bh
	out dx,al;ctrl word
	
	call readuiw
	mov bx,ax
	mov al,lit[bx]	
	mov dx,288h
	out dx,al
	.exit 0
	end start

TPC08-2.ASM

;************************************
;*   LED数码管多位动态显示"3456"    *
;************************************
 include io.inc
 .model small
 .stack
 .data
led byte 3fh,06h,5bh,4fh,66h,6dh,7dh,07h,7fh,6fh ;段码
buf byte 3,4,5,6         ;存放要显示的数字
msg byte 'Press any key to exit.',0
 .code
start: mov ax,@data
 mov ds,ax
 mov ax,offset msg
 call dispmsg

 mov dx,28bh ;8255设为A和B口输出
 mov al,80h
 out dx,al
        mov al,0  ;控制端口B为低,关掉数码管显示
        mov dx,289h
        out dx,al
start1: xor si,si
 mov ah,08h ;位码
again:
    mov bl,buf[si] ;bl为要显示的数
    mov bh,0
    mov al,led[bx] ;求出对应的led数码
    mov dx,288h  ;8255的端口A输出
    out dx,al
    mov al,ah  ;使一个数码管亮
    mov dx,289h
    out dx,al
    call delay  ;延时
    ;
 mov al,0 ;关掉数码管显示
 mov dx,289h
 out dx,al
    ;
        inc si
        shr ah,1
        jnz again
    ;

 call readkey
 jz start1 ;有键按下则退出

 .exit 0                  ;返回

delay proc                ;延时
    push cx
    mov cx,10000
delay1:    loop delay1
    pop cx
    ret
delay endp
 end start

自己写的:

   	include io.inc
	.model small;定义程序的存储模型
	.stack;定义堆栈段
	.data
	.code
msg   byte 'Go!',13,10,0
lit   byte 3fh,06h,5bh,4fh,66h,6dh,7dh,07h,7fh,6fh
buf	byte 0,0,0,0
start:
	mov ax,@data
	mov ds,ax
	
	mov al,80h   ;1000 
	mov dx,28bh
	out dx,al;ctrl word
	
	mov cl,0
fun:	
	
	mov ax,offset msg
	call dispmsg
	call dispcrlf
	mov si,3
	
	call led

	mov cl,0
	test cl,0
	jz fun
	
	.exit 0
led	proc
	push ax
	push bx
	push dx
	mov ah,08h ;left est pipe
led1:	mov bx,si
	inc si
	mov al,lit[bx]
	mov dx,288h
	out dx,al	; set seg
	mov al,ah
	mov dx,289h
	out dx,al	;set bit
	call delay
	ror ah,1;to right
	cmp ah,80h
	jnz led1
	
	pop dx
	pop bx
	pop ax
	ret
led	endp

delay proc
	push bx
	push cx
	mov bx,5
delay1:
	mov cx,0
delay2:
	loop delay2
	dec bx
	jne delay1
	pop cx
	pop bx
	ret
delay endp
	end start

TPC08-4.ASM

;**************************************
;*  LED数码管多位循环显示"0000-9999"  *
;**************************************
 include io.inc
 .model small
 .stack
 .data
led byte 3fh,06h,5bh,4fh,66h,6dh,7dh,07h,7fh,6fh ;段码
buf byte 0,0,0,0         ;存放要显示数字
msg byte 'Press any key to exit.',0
 .code
start: mov ax,@data
 mov ds,ax
 mov ax,offset msg
 call dispmsg

 mov dx,28bh ;8255设为A和B口输出
 mov al,80h
 out dx,al
        mov al,0  ;控制端口B为低,关掉数码管显示
        mov dx,289h
        out dx,al
start1:
 xor si,si
 mov ah,08h ;位码
again:
    mov bl,buf[si] ;bl为要显示的数
    mov bh,0
    mov al,led[bx] ;求出对应的led数码
    mov dx,288h  ;8255的端口A输出
    out dx,al
    mov al,ah  ;使一个数码管亮
    mov dx,289h
    out dx,al
    call delay                   ;延时
    ;
        mov al,0               ;关掉数码管显示
        mov dx,289h
        out dx,al
    ;
        inc si
        shr ah,1
        jnz again
    ;
    mov bl,buf+3    ;要显示的数加1
    inc bl
    cmp bl,10
    jb next3
    mov bl,0
    mov bh,buf+2
    inc bh
    cmp bh,10
    jb next2
    mov bh,0
    mov cl,buf+1
    inc cl
    cmp cl,10
    jb next1
    mov cl,0
    mov ch,buf
    inc ch
    cmp ch,10
    jb next0
    mov ch,0
next0: mov buf,ch
next1: mov buf+1,cl
next2: mov buf+2,bh
next3: mov buf+3,bl
    ;
  call readkey
 jz start1 ;有键按下则退出

    mov al,0 ;关掉数码管显示
    mov dx,289h
    out dx,al

    .exit 0                  ;返回

delay proc                ;延时
    push cx
    mov cx,10000
delay1:    loop delay1
    pop cx
    ret
delay endp
 end start

实验10 模/数转换器

TPC10-1.ASM

不足:没有试验readkey的作用,即程序可以一直运行,死循环

   	include io.inc
	.model small;定义程序的存储模型
	.stack;定义堆栈段
	.data
	.code

start:
	mov ax,@data
	mov ds,ax
	

	
again:
	;call readkey
	;jnz again;readkey可以直接调用,有输入退出程序
	mov dx,298h	
	out dx,al ;start

	call delay
	in al,dx
	call disphb
	mov al,20h
	call dispc
	
	jmp again
	.exit 0
delay proc
	push bx
	push cx
	mov bx,2000
delay1:
	mov cx,0
delay2:
	loop delay2
	dec bx
	jne delay1
	pop cx
	pop bx
	ret

delay endp
	end start

TPC10-2.ASM

  	include io.inc
	.model small;定义程序的存储模型
	.stack;定义堆栈段
	.data
	.code

start:
	mov ax,@data
	mov ds,ax
	
	mov al,88h   ;1000 1000
	mov dx,28bh
	out dx,al;ctrl word
once:
	mov dx,298h
	out dx,al;start
	mov dx,28ah;port c
again:
	in al,dx
	test al,80h
	jz again
	mov dx,298h
	in al,dx
	call disphb
	mov al,20h
	call dispc
	call delay
	jmp once



	.exit 0
delay proc
	push bx
	push cx
	mov bx,2000
delay1:
	mov cx,0
delay2:
	loop delay2
	dec bx
	jne delay1
	pop cx
	pop bx
	ret

delay endp
	end start

TPC10-3.ASM

相比之前的,就加个启动ADC和修改中断程序使其能够取数和打印。
不足:每次只能打印一个(要想实现多次打印,需要修改主程序)

  	include io.inc
	.model small
	.stack
	.data
intmsg byte 'You are so lovely!',13,10,0
counter byte 0
	.code
start:
	mov ax,@data
	mov ds,ax

	mov ax,350bh
	int 21h
	push es
	push bx
	cli
	push ds
	mov ax,seg new0bh
	mov ds,ax
	mov dx,offset new0bh
	mov ax,250bh
	int 21h
	
	pop ds
	in al,21h
	push ax
	and al,0f7h
	out 21h,al
	
	sti
	mov dx,298h
	out dx,al;start
	call delay;等一段时间,使其转换,然后中断请求和响应
	cli
	pop ax
	out 21h,al
	pop dx
	pop ds
	mov ax,250bh
	int 21h
	sti
	.exit 0


new0bh proc
	sti
	push ax
	push si
	push ds
	mov ax,@data
	mov ds,ax
	
	mov dx,298h
	in al,dx
	call disphb
	mov al,20h
	call dispc

	mov al,20h
	out 20h,al
	pop ds
	pop si
	pop ax
	iret
new0bh endp

delay proc
	push bx
	push cx
	mov bx,2000
delay1:
	mov cx,0
delay2:
	loop delay2
	dec bx
	jne delay1
	pop cx
	pop bx
	ret

delay endp


	;.exit 0
	end start
  • 9
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
提供的源码资源涵盖了Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 适合毕业设计、课程设计作业。这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。 所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随时与博主沟通,第一时间进行解答!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值