微型计算机原理与接口技术的编程题都有哪些?

一、8253

.MODEL TINY

PCIBAR3 EQU 1CH ;8位I/O空间基地址(它就是实验仪的基地址,也为DMA & 32 BIT RAM板卡上的8237提供基地址)

Vendor_ID EQU 10EBH ;厂商ID号

Device_ID EQU 8376 ;设备ID号

.STACK 100

.DATA

COM_ADDR DW 00B3H

T0_ADDR DW 00B0H

T1_ADDR DW 00B1H

IO_Bit8_BaseAddress DW

msg0 DB 'BIOS不支持访问PCI

msg1 DB '找不到Star PCI9052板卡

msg2 DB '读8位I/O空间基地址时出错

.CODE

START: MOV AX,@DATA

MOV DS,AX

NOP

CALL InitPCI

CALL ModifyAddress ;根据PCI提供的基地址,将偏移地址转化为实地址

mov dx,COM_ADD

mov al,35h;?

out dx,al ;计数器T0设置在模式2状态,BCD码计数

mov dx,T0_ADDR

mov al,00h

out dx,al

mov al,10h

out dx,al ;CLK0/1000

mov dx,COM_ADDR

mov al,77h

out dx,al ;计数器T1为模式3状态,输出方波,BCD码计数

mov dx,T1_ADDR

mov al,00h

out dx,al

mov al,10h

out dx,al ;CLK1/1000

START1: CALL IfExit ;OUT1输出频率为1S的方波

JZ START1

JMP Exit

IfExit PROC NEAR

PUSH AX

PUSH DX

MOV AH,06H

MOV DL,0FFH

INT 21H

POP DX

POP AX

RET

IfExit ENDP

InitPCI PROC NEAR

MOV AH,00H

MOV AL,03H

INT 10H ;清屏

MOV AH,0B1H

MOV AL,01H

INT 1AH

CMP AH,0

JZ InitPCI2

LEA DX,msg0

InitPCI1: MOV AH,09H

INT 21H

JMP Exit

InitPCI2: MOV AH,0B1H

MOV AL,02H

MOV CX,Device_ID

MOV DX,Vendor_ID

MOV SI,0

INT 1AH

JNC InitPCI3 ;是否存在Star PCI9052板卡

LEA DX,msg1

JMP InitPCI1

InitPCI3: MOV DI,PCIBAR3

MOV AH,0B1H

MOV AL,09H

INT 1AH ;读取该卡PCI9052基地址

JNC InitPCI4

LEA DX,msg2

JMP InitPCI1

InitPCI4: AND CX,0FFFCH

MOV IO_Bit8_BaseAddress,CX

RET

InitPCI ENDP

ModifyAddress PROC NEAR

ADD COM_ADDR,CX

ADD T0_ADDR,CX

ADD T1_ADDR,CX

RET

ModifyAddress ENDP

Exit: MOV AH,4CH

INT 21H

END START

二、8259

.MODEL TINY

PCIBAR1 EQU 14H ;PCI9052 I/O基地址(用于访问局部配置寄存器)

PCIBAR3 EQU 1CH ;8位I/O空间基地址(它就是实验仪的基地址,也为DMA & 32 BIT RAM板卡上的8237提供基地址)

PCIIPR EQU 3CH ;IRQ号

INTCSR EQU 4CH ;PCI9052 INTCSR地址

mask_int_9052 EQU 24H

Vendor_ID EQU 10EBH ;厂商ID号

Device_ID EQU 8376 ;设备ID号

.STACK 100

.DATA

IO8259_0 DW 00F0H

IO8259_1 DW 00F1H

RD_IO8259 DW 0000H

IO_Bit8_BaseAddress DW ?

PCI_IO_BaseAddress0 DW ?

PCI_IRQ_NUMBER DB ?

INT_MASK DB ?

INT_Vector DB ?

INT_CS DW ? ;保护原中断入口地址

INT_IP DW ?

msg0 DB 'BIOS不支持访问PCI

msg1 DB '找不到Star PCI9052板卡

msg2 DB '读PCI9052 I/O基地址时出错$'

msg3 DB '读8位I/O空间基地址时出错$'

msg4 DB '读IRQ号出错$'

msg5 DB '8259中断 00H 次$'

BUFFER DB

Counter DB ?

ReDisplayFlag DB 0

.CODE

START: MOV AX,@DATA

MOV DS,AX

MOV ES,AX

NOP

CALL InitPCI

CALL ModifyAddress ;根据PCI提供的基地址,将偏移地址转化为实地址

CALL ModifyVector ;修改中断向量、允许中断

MOV AH,00H

MOV AL,03H

INT 10H ;清屏

MOV AH,09H

LEA DX,msg5

INT 21H

CALL Init8259

MOV Counter,0 ;中断次数

MOV ReDisplayFlag,1 ;需要显示

STI ;开中断

START1: CALL IfExit

CMP ReDisplayFlag,0

JZ START1

CALL LedDisplay

MOV ReDisplayFlag,0

JMP START1

Init8259 PROC NEAR

MOV DX,IO8259_0

mov al,13H

out dx,al

MOV DX,IO8259_1

mov al,08H

out dx,al

MOV AL,09H

OUT DX,AL

mov al,0feH ;屏蔽寄存器

OUT DX,AL

RET

Init8259 ENDP

ToChar PROC NEAR ;转化为可显示的16进制数

ADD AL,'0'

CMP AL,'9'

JBE ToChar1

ADD AL,07H

ToChar1: RET

ToChar ENDP

LedDisplay PROC NEAR

MOV AL,Counter

MOV AH,AL

AND AL,0FH

CALL ToChar

MOV Buffer + 1,AL

AND AH,0F0H

ROR AH,4

MOV AL,AH

CALL ToChar

MOV Buffer,AL

MOV AH,02H

MOV DL,10

MOV DH,0

INT 10H ;定位光标

MOV AH,09H

LEA DX,Buffer

INT 21H

RET

LedDisplay ENDP

INT_0: PUSH DX

PUSH AX

CALL ClearInt

JC INT_0_0

MOV DX,RD_IO8259

IN AL,DX

IN AL,DX ;判断由哪个中断源引起的中断

MOV AL,Counter

ADD AL,1

DAA

MOV Counter,AL

MOV ReDisplayFlag,1

INT_0_0: MOV DX,IO8259_0

MOV AL,20H

OUT DX,AL

POP AX

POP DX

IRET

IfExit PROC NEAR

PUSH AX

PUSH DX

MOV AH,06H

MOV DL,0FFH

INT 21H

POP DX

POP AX

JZ IfExit1

JMP Exit

IfExit1: RET

IfExit ENDP

InitPCI PROC NEAR

MOV AH,00H

MOV AL,03H

INT 10H ;清屏

MOV AH,0B1H

MOV AL,01H

INT 1AH

CMP AH,0

JZ InitPCI2

LEA DX,msg0

InitPCI1: MOV AH,09H

INT 21H

JMP Exit

InitPCI2: MOV AH,0B1H

MOV AL,02H

MOV CX,Device_ID

MOV DX,Vendor_ID

MOV SI,0

INT 1AH

JNC InitPCI3 ;是否存在Star PCI9052板卡

LEA DX,msg1

JMP InitPCI1

InitPCI3: MOV DI,PCIBAR1

MOV AH,0B1H

MOV AL,09H

INT 1AH ;读取该卡PCI9052基地址

JNC InitPCI4

LEA DX,msg2

JMP InitPCI1

InitPCI4: AND CX,0FFFCH

MOV PCI_IO_BaseAddress0,CX

MOV DI,PCIBAR3

MOV AH,0B1H

MOV AL,09H

INT 1AH ;读取该卡扩展的8位IO基地址

JNC InitPCI5

LEA DX,msg3

JMP InitPCI1

InitPCI5: AND CX,0FFFCH

MOV IO_Bit8_BaseAddress,CX

MOV DI,PCIIPR

MOV AH,0B1H

MOV AL,09H

INT 1AH ;读取IRQ号

JNC InitPCI6

LEA DX,msg4

JMP InitPCI1

InitPCI6: MOV PCI_IRQ_NUMBER,CL

RET

InitPCI ENDP

ModifyAddress PROC NEAR

MOV AX,IO_Bit8_BaseAddress

ADD IO8259_0,AX

ADD IO8259_1,AX

ADD RD_IO8259,AX

RET

ModifyAddress ENDP

ModifyVector PROC NEAR

PUSH ES

MOV AL,PCI_IRQ_NUMBER

CMP AL,08H

JAE ModifyVector1

ADD AL,08H ;IRQ0..7 -> 中断向量8..F

JMP ModifyVector2

ModifyVector1: ADD AL,70H-08H ;IRQ8..F -> 中断向量70H..77H

ModifyVector2: MOV INT_Vector,AL

MOV AH,35H

INT 21H

MOV INT_IP,BX ;保护原中断处理例程地址

MOV AX,ES

MOV INT_CS,AX

MOV AL,INT_Vector

LEA DX,INT_0

PUSH DS

PUSH CS

POP DS

MOV AH,25H

INT 21H ;设置新中断向量

POP DS

MOV BL,PCI_IRQ_NUMBER

MOV DX,21H

CMP AL,08H

JB ModifyVector3

MOV DX,0A1H

ModifyVector3: IN AL,DX

MOV INT_MASK,AL

AND BL,07H

MOV CL,BL

MOV BL,1

SHL BL,CL

NOT BL

AND AL,BL

OUT DX,AL ;允许中断

POP ES

STI

RET

ModifyVector ENDP

ClearInt PROC NEAR ;清楚PCI9052、系统中断控制器的中断标志

MOV DX,PCI_IO_BaseAddress0

ADD DX,INTCSR

; IN AL,DX

; AND AL,mask_int_9052

; JZ ClearInt3 ;不是8259引取的中断

INC DX

IN AL,DX

OR AL,0CH

OUT DX,AL ;清除PCI9052的中断标志位

MOV AL,PCI_IRQ_NUMBER

CMP AL,08H

JAE ClearInt1

AND AL,7

OR AL,60H

MOV DX,20H

OUT DX,AL

JMP ClearInt2

ClearInt1: AND AL,7

OR AL,60H

MOV DX,0A0H

OUT DX,AL

MOV DX,20H

MOV AL,62H

OUT DX,AL

ClearInt2: CLC

RET

;ClearInt3: STC

; RET

ClearInt ENDP

Exit: CLI

MOV BL,PCI_IRQ_NUMBER

MOV DX,21H

CMP AL,08H

JB Exit1

MOV DX,0A1H

Exit1: MOV AL,INT_MASK

OUT DX,AL ;屏蔽中断

PUSH DS

MOV AL,INT_Vector

MOV DX,INT_IP ;保护原中断处理例程地址

MOV AX,INT_CS

MOV AH,25H

INT 21H ;设置新中断向量

POP DS

STI

MOV AH,4CH

INT 21H

END START

三、8251

.MODEL TINY

;使用8253的计数器0,外接2Mhz,经26分频后,送给8251,产生4800bps

PCIBAR3 EQU 1CH ;8位I/O空间基地址(它就是实验仪的基地址,也为DMA & 32 BIT RAM板卡上的8237提供基地址)

Vendor_ID EQU 10EBH ;厂商ID号

Device_ID EQU 8376 ;设备ID号

.STACK 100

.DATA

CTL_ADDR DW 00F1H ;控制字或状态字

DATA_ADDR DW 00F0H ;读写数据

W_8253_T0 DW 00B0H ;计数器0地址

W_8253_C DW 00B3H ;控制字

IO_Bit8_BaseAddress DW

msg0 DB 'BIOS不支持访问PCI

msg1 DB '找不到Star PCI9052板卡

msg2 DB '读8位I/O空间基地址时出错$'

Receive_Buffer DB 10 DUP(0) ;接受缓冲器

Send_Buffer EQU Receive_Buffer ;发送缓冲器

.CODE

START: MOV AX,@DATA

MOV DS,AX

MOV ES,AX

NOP

CALL InitPCI

CALL ModifyAddress ;根据PCI提供的基地址,将偏移地址转化为实地址

CALL INIT_8253

CALL INIT_8251

START1: MOV CX,10

CALL Receive_Group

MOV CX,10

CALL Send_Group

CALL IfExit ;OUT1输出频率为1S的方波

JZ START1

JMP Exit

; JMP START1

INIT_8253 PROC NEAR

MOV DX,W_8253_C

MOV AL,37H ;定时器0,方式3

OUT DX,AL

MOV DX,W_8253_T0

MOV AL,26H ;BCD码26(2000000/26)=16*4800

OUT DX,AL

MOV AL,0

OUT DX,AL

RET

INIT_8253 ENDP

INIT_8251 PROC NEAR

CALL RESET_8251

mov dx,CTL_ADDR

mov al,7eh ;波特率系数为16,8个数据位

out dxx,al ;一个停止位,偶校验

CALL DLTIME ;延时

mov al,15h ;允许接收和发送发送数据,清错误标志

out dx,al

CALL DLTIME

RET

INIT_8251 ENDP

Reset_8251 PROC NEAR

MOV DX,CTL_ADDR

MOV AL,0

OUT DX,AL ;向控制口写入"0"

CALL DLTIME ;延时,等待写操作完成

OUT DX,AL ;向控制口写入"0"

CALL DLTIME ;延时

OUT DX,AL ;向控制口写入"0"

CALL DLTIME ;延时

MOV AL,40H ;向控制口写入复位字40H

OUT DX,AL

CALL DLTIME

RET

Reset_8251 ENDP

;接受一组数据,CX--接受数目

Receive_Group PROC NEAR

LEA DI,Receive_Buffer

Receive_Group1: CALL Receive_Byte

STOSB

LOOP Receive_Group1

RET

Receive_Group ENDP

;接受一个字节

Receive_Byte PROC NEAR

MOV DX,CTL_ADDR

Receive_Byte1: in al,dx ;读入状态

test al,2

jz Receive_Byte1 ;

mov dx, DATA_ADDR ;有

in al,dx

RET

Receive_Byte ENDP

;发送一组数据,CX--发送数目

Send_Group PROC NEAR

LEA SI,Send_Buffer

Send_Group1: lodsb

call Sendbyte

loop Send_Group1

RET

Send_Group ENDP

;发送一个字节

Sendbyte PROC NEAR

PUSH AX

MOV DX,CTL_ADDR ;读入状态

Sendbyte1: in al,dx

test al,1

jz Sendbyte1 ;允许数据发送吗?

pop ax ;发送

mov dx,DATA_

MOV CX,Device_ID

MOV DX,Vendor_ID

MOV SI,0

INT 1AH

JNC InitPCI3 ;是否存在Star PCI9052板卡

LEA DX,msg1

JMP InitPCI1

InitPCI3: MOV DI,PCIBAR3

MOV AH,0B1H

MOV AL,09H

INT 1AH ;读取该卡PCI9052基地址

JNC InitPCI4

LEA DX,msg2

JMP InitPCI1

InitPCI4: AND CX,0FFFCH

MOV IO_Bit8_BaseAddress,CX

RET

InitPCI ENDP

ModifyAddress PROC NEAR

ADD COM_ADD,CX

ADD PA_ADD,CX

ADD PB_ADD,CX

ADD PC_ADD,CX

RET

ModifyAddress ENDP

Exit: MOV AH,4CH

INT 21H

END START