爱
爱元元的哥哥
Unregistered / Unconfirmed
GUEST, unregistred user!
{ -----------------------------------------------------------------------------}<br>{ 更新日期: 29/3/2002 修改作者:司马华鹏 }<br>{ -----------------------------------------------------------------------------} <br>{ 这个模块是单独的数模转换函数模块 }<br>{------------------------------------------------------------------------------}<br><br>unit UnitAD;<br><br>interface<br><br> function PortReadByte(Addr:Word):Byte;<br> function PortreadWord(Addr:Word):Word;<br> Function PortReadWordLs(Addr:Word):Word;<br> Procedure PortWriteByte(Addr:Word;Value:Byte);<br> Procedure PortWriteWord(Addr:Word;Value:Word);<br> Procedure PortWriteWordLs(Addr:Word;Value:Word);<br> <br>implementation<br><br>//PortReadByte函数<br>//参数:端口地址<br>//返回:从指定端口得到的单字节值(8位)<br><br>Function portReadByte(Addr:Word):Byte;assembler;register;<br>asm<br> MOV DX,AX<br> IN AL,DX<br>end;<br><br>//高速读取端口函数 PortReadWord 函数<br>//参数:端口地址<br>//返回从指定端口得到的双字节值(16位)<br>//注意:可能有些卡和计算机不能访问全部Word<br><br>Function PortReadWord(Addr:Word):Word;assembler;register;<br>asm<br> MOV DX,AX<br> IN AX,DX<br>end;<br><br>//低速读端口值 :PortReadWordLs<br>// 参数:端口地址<br>//返回从指定端口得到的双字节值(16位)<br>//注意工作时要调整延迟<br><br>Function PortReadWordLs(Addr:Word):Word;assembler;Register;<br>const<br> DELAY=150;<br> //依靠CPU的速度和卡的速度<br>Asm<br> MOV DX,AX<br> IN AL,DX<br> //读LSB端口<br> MOV ECX,DELAY<br> @1:<br> LOOP @1 //在两次读之间延时<br> XCHG AH,AL<br> INC DX //端口地址加一<br> IN AL,DX //读MSB端口<br> XCHG AH,AL //重新存储字节顺序<br>end;<br><br>//写端口 ortWriteByte函数<br><br>Procedure PortWriteByte(addr:Word;value:byte);assembler;register;<br>asm<br> XCHG AX,DX<br> OUT DX,AL<br>end;<br><br>//高速写端口 :PortWriteWord函数<br>Procedure PortWriteWord(Addr:Word;Value:Word);assembler;register;<br>asm<br> XCHG AX,DX<br> OUT DX,AX<br>end;<br><br>//低速写端口函数<br>Procedure PortWriteWordLS(Addr:Word;Value:Word);assembler;register;<br>const<br> DELAY=150;<br>asm<br> XCHG AX,DX<br> OUT DX,AL<br> MOV ECX,DELAY<br> @1:<br> LOOP @1<br> XCHG AH,AL<br> INC DX<br> OUT DX,AL<br>end;<br><br><br><br>end.<br>