发信人: redfox (Z掉了几乎所有的版...), 信区: BorlandDev
标  题: Delphi编程 -- 9.2 一个串口通讯的问题
发信站: 哈工大紫丁香 (2000年09月01日16:41:27 星期五), 站内信件

一个串口通讯的问题?  
Serial Port Communications?

I want to build a simple electrical controller which receives input from
 a
sensor through a comm port and either turns a power source(s) on or 
off
based upon this signal. I want this controller to be software in 
nature.
How do I communicate through the port and is it possible to discern 
changes
in voltage.
If not, what kind of signal must be input.

When you want to write and read only binary signals you can use the 
printer
parallel port. For that purpose the Port command is useful. In the below
 an
example of some D1 code used for bidirectional 2 wire bus 
communication (I2C).
BaseAddress is $278, $378 or $3BC, depending on the LPT port used for
communication.

There is a 'but'. In D1 the port function was available but not 
documented. In
D2 and D3 it seems to have disappeared entirely (Please somebody correct
 me if
this is wrong).

We are using the parallel printer port with attached a small interface 
card
with some I/O buffering for control of RF modules. Could somebody 
indicate
whether the Port function still exist or what the alternative could be 
?

regards,

Hans Brekelmans


PROCEDURE SetIICline(Terminal: IICterminalTypes; High: Boolean);
Var Count : Word;
      CtrlAddress: word;
Begin { set iic line }
  CtrlAddress:=BaseAddress+2;
  Case Terminal of
    SCL : if High then Port[CtrlAddress]:=$08 else Port[CtrlAddress]:
=$00;
    SDA : if NOT High then Port[BaseAddress]:=$80 else 
Port[BaseAddress]:=$00;
  END;
  For Count := 1 to ClockDelay do;
End; {SetIICline}

FUNCTION GetIICline(Terminal: IICterminalTypes): Boolean;
const SDA_IN=$80; { SDA: 25 pin #11, status, NOT BUSY, bit 7 }
         SCL_IN=$08; { SCL: 25 pin #15, status, NOT Error, bit 3 }
var Count : Word;
    ReadAddress: word;
Begin
   ReadAddress:=BaseAddress+1;
   CASE Terminal OF
     SCL: GetIICline:=((Port[ReadAddress] AND SCL_IN) = SCL_IN);
     SDA: GetIICline:=((Port[ReadAddress] AND SDA_IN) = SDA_IN); { 
read sda
pin }
   END;
   For Count := 1 to ClockDelay do;
End;

 

--
※ 来源:·哈工大紫丁香 bbs.hit.edu.cn·[FROM: 202.118.227.107]
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:6.543毫秒