首页  编辑  

几个I/O端口操作函数

Tags: /超级猛料/Hardware.硬件相关/其它硬件/   Date Created:

function _inpw(port: WORD): WORD;

       cdecl;

       external 'msvcrt.dll';

function _outpw(port: WORD): WORD;

       cdecl;

       external 'msvcrt.dll';

---------------------------------------

function PortIn(IOport:word):byte; assembler;

asm

 mov dx,ax

 in al,dx

end;

function PortInW(IOport:word):word; assembler;

asm

 mov dx,ax

 in ax,dx

end;

procedure PortOut(IOport:word; Value:byte); assembler;

asm

 xchg ax,dx

 out dx,al

end;

procedure PortOutW(IOport:word; Value:word); assembler;

asm

 xchg ax,dx

 out dx,ax

end

{ Example use }

PROCEDURE TMainWin.Command(val:BYTE);

VAR Delay,num:INTEGER;

BEGIN

  PortOut(Port,Val);

  FOR Delay:= 1 TO 500 DO;

  PortOut(Port+2,7);

  FOR Delay:= 1 TO 500 DO;

  num:= PortIn(Port+1) AND $32;

  ShowMessage('Value read = '+IntToStr(num))

END;