文章目录
实验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