plwei:你的代号和我的很像.
我这有点关于串口通讯的例子.由于时间关系,我来不及看是干什么的,
贴在这,你看着办:
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 sdapin }
END;
For Count := 1 to ClockDelay do;
End;