》位操作
const
bits:array[0..7] of integer=(1,2,4,8,16,32,64,128);
implementation
function testbit(abit:integer;abyte:byte):boolean;
BEGIN
result:=((bits[abit] and abyte)=bits[abit]);
END;
function setbit_1(abit:integer;abyte:byte):byte;
BEGIN
result:=abyte or bits[abit];
END;
function setbit_0(abit:integer;abyte:byte):byte;
BEGIN
result:=abyte;
if testbit(abit,abyte) then result:=abyte-bits[abit];
END;
。。。。。。
FOR EXAMPLE:
procedure TForm1.Button1Click(Sender: TObject);
var
abyte:byte;
begin
abyte:=0;
abyte:=setbit_1(0,abyte); //bit0置1
showmessage(inttohex(abyte,2));
if testbit(0,abyte) then showmessage('true');
abyte:=setbit_0(0,abyte); //bit0置0
showmessage(inttohex(abyte,2));
if not testbit(0,abyte) then showmessage('false');
end;
》串口通讯
串口用mscomm,spcomm,comport.....,推荐用comport,个人认为最好,google搜索下载有例子