www.pudn.com > LAMP1.rar > LAMP.ASM


;386以上微机适用 
;纯dos下才能使用 
;tasm4.1或以上编译 
;*********************; 
;*       8253        *; 
;*********************; 
 io_plx_device_id	equ 05406h	;TPC卡设备ID 
 io_plx_vendor_id	equ 010b5h	;TPC卡厂商ID 
 IO_PLX_SUB_ID		EQU 0905410B5H	;TPC卡子设备及厂商ID 
 pa55    equ 218h-200H	;8255端口地址 
 pb55    equ 219h-200H 
 pc55    equ 21ah-200H 
 p55ctl  equ 21bh-200H 
data segment 
 io_base_address	db 4 DUP(0)	;TPC卡I/O基地址暂存空间 
 pcicardnotfind		db 0dh,0ah,'TPC pci card not find or address/interrupt error !!!',0dh,0ah,'$' 
 iobaseaddress		db 0dh,0ah,'TPC pci card I/O Base Address : ','$' 
 enter_return		db 0dh,0ah,'$' 
     pb   db ? 
     mess db 'Enter any key can exit to dos!',0dh,0ah,'$' 
data ends 
stacks segment 
 db 100 dup (?) 
 sta dw 50 dup(?) 
 top equ length sta 
stacks ends 
code segment 
        assume cs:code,ds:data,ss:stacks,es:data 
start: 
.386 
        cli 
        mov ax,data 
        mov ds,ax 
        mov es,ax 
        mov ax,stacks 
        mov ss,ax 
	call	findtpc		;查找TPC卡资源并显示 
 
	mov ah,09h 
	mov dx,offset mess 
	int 21h 
	MOV  DX,word ptr io_base_address	;初始化8255 
	add  dx,p55ctl 
	mov al,82h 
	out dx,al 
	MOV  DX,word ptr io_base_address 
	add  dx,pb55 
	in al,dx 
	mov pb,al 
	MOV  DX,word ptr io_base_address 
	add  dx,p55ctl 
	mov al,80h 
	out dx,al 
	MOV  DX,word ptr io_base_address 
	add  dx,pb55 
	mov al,pb 
	or al,0f0h 
	out dx,al		;turn off yellow 
	MOV  DX,word ptr io_base_address 
	add  dx,pc55 
	mov al,0f0h		;4 red lights 
	out dx,al 
	call delay10 
lll: 
	mov al,10100101b	;turn on 1,3 green light 
	MOV  DX,word ptr io_base_address 
	add  dx,pc55 
	out dx,al 
	call delay10 
	call delay10 
	or al,0f0h		; turn off 1,3 green light 
	out dx,al 
	mov cx,0008h 
ttt: 
	MOV  DX,word ptr io_base_address 
	add  dx,pb55 
	mov al,pb 
	and al,10101111b	; 1,3 yellow light turn on 
	out dx,al 
	call delay1 
	or al,01010000b 
	out dx,al		; 1,3 yellow light turn off 
	call delay1 
	loop ttt 
	MOV  DX,word ptr io_base_address 
	add  dx,pc55 
	mov al,0f0h 
	out dx,al 
	call delay1 
	mov al,01011010b 
	out dx,al		;   2,4 green   1,3 red 
	call delay10 
	call delay10 
	or al,0f0h ; turn off 2,4 green light 
	out dx,al 
	mov cx,0008h 
ggg: 
	MOV  DX,word ptr io_base_address 
	add  dx,pb55 
	mov al,pb 
	and al,01011111b 
	out dx,al   ; turn on 2,4 yellow 
	call delay1 
	or al,10100000b 
	out dx,al  ; turn off 2,4 yellow 
	call delay1 
	loop ggg 
	MOV  DX,word ptr io_base_address 
	add  dx,pc55 
	mov al,0f0h 
	out dx,al 
	call delay1 
	mov ah,06h 
	mov dl,0ffh 
	int 21h 
	jnz ppp 
	jmp lll 
ppp: 
	mov ax,4c00h 
	int 21h		;退出 
 
delay1 proc near 
	push cx 
	mov cx,0ffffh 
ccc: 
	loop ccc 
	pop cx 
	ret 
delay1 endp 
 
delay10 proc near 
	push ax 
	push cx 
	mov cx,0100h 
uuu: 
	call delay1 
	loop uuu 
	pop cx 
	pop ax 
	ret 
delay10 endp 
 
findtpc proc near		;查找TPC卡资源并显示 
	pushad 
	pushfd 
	MOV	AX,0B101H 
	INT	1AH 
	JC	findtpc_notfind		;检查PCI BIOS是否存在 
 
	MOV	AX,0B102H 
	MOV	CX,io_plx_device_id 
	MOV	DX,io_plx_vendor_id 
	MOV	SI,0 
	INT	1AH 
	JC	findtpc_notfind		;检查TPC卡是否安装,设备号、厂商号 
 
	MOV	AX,0B10AH 
	MOV	DI,02CH 
	INT	1AH 
	JC	findtpc_notfind 
	CMP	ECX,IO_PLX_SUB_ID 
	JNZ	findtpc_notfind		;检查TPC卡是否安装,子设备号、厂商号 
 
	MOV	AX,0B10AH 
	MOV	DI,18H 
	INT	1AH 
	JC	findtpc_notfind		;读TPC卡I/O基址信息 
	mov	dword ptr io_base_address,ecx 
	and	ecx,1 
	jz	findtpc_notfind		;检查是否为i/o基址信息 
	mov	ecx,dword ptr io_base_address 
	and	ecx,0fffffffeh 
	mov	dword ptr io_base_address,ecx	;去除i/o指示位并保存 
 
	mov	dx,offset iobaseaddress		;显示i/o提示信息 
	mov	ah,09h 
	int	21h 
	mov	ax,word ptr io_base_address 
	call	dispword			;显示i/o基地址 
 
	mov	dx,offset enter_return		;加回车符,换行符 
	mov	ah,09h 
	int	21h 
	popfd 
	popad 
	ret 
findtpc_notfind: 
	mov dx,offset pcicardnotfind		;显示未找到tpc卡提示信息 
	mov ah,09h 
	int 21h 
	mov ax,4c00h 
	int 21h		;退出 
findtpc endp 
 
dispword proc near		;显示子程序 
	push dx 
	push cx 
	push bx 
	mov cx,4 
	mov bx,16 
dispword_loop1: 
	push ax 
	push cx 
	sub bx,4 
	mov cx,bx 
	shr ax,cl 
	and al,0fh	;首先取低四位 
	mov dl,al 
	cmp dl,9	;判断是否<=9 
	jle dispword_num		;若是则为'0'-'9',ASCII码加30H 
	add dl,7	;否则为'A'-'F',ASCII码加37H 
dispword_num: 
	add dl,30h 
	mov ah,02h	;显示 
	int 21h 
	pop cx 
	pop ax 
	loop dispword_loop1 
	pop bx 
	pop cx 
	pop dx 
	ret		;子程序返回 
dispword endp 
code ends 
end start