delphi与51单片机串行通信
//delphi源码
unit Unit1;
interface
uses
type
var
implementation
{$R *.dfm}
procedure TFCOMM.FormShow(Sender: TObject);
begin
comm1.startcomm;
end;
procedure TFCOMM.FormClose(Sender: TObject; var Action: TCloseAction);
begin
comm1.stopcomm;
end;
//自定义发送数据过程
procedure senddata;
var
i:integer;
commflg:boolean;
begin
viewstring:= ;
commflg:=true;
for i:=1 to 9 do
begin
sleep(2);
viewstring:=viewstring+inttohex(sbuf[i],1)+ ;
end;
viewstring:=发送+viewstring;
fcomm.memo1.lines.add(viewstring);
fcomm.memo1.lines.add( );
if
end;
procedure TFCOMM.Button1Click(Sender: TObject);
begin
sbuf[1]:=byte($95); //帧头
sbuf[2]:=byte($10); //命令号
sbuf[3]:=byte($20);
sbuf[4]:=byte($25);
sbuf[5]:=byte($95); //帧头
sbuf[6]:=byte($10); //命令号
sbuf[7]:=byte($20);
sbuf[8]:=byte($25);
sbuf[9]:=byte($25);
senddata;
end;
procedure TFCOMM.Button2Click(Sender: TObject);
begin
memo1.clear;
end;
procedure TFCOMM.Button3Click(Sender: TObject);
begin
close;
end;
procedure TFCOMM.Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
var
i:integer;
begin
viewstring:=;
move(buffer^,rbuf,bufferlength);
for i:=1 to bufferlength do
viewstring:=viewstring+ inttohex(rbuf[i],2)+ ;
viewstring:=接收+ viewstring;
memo1.lines.add(viewstring);
memo1.lines.add();
end;
end.
//单片机源码
#include
void send(b)
{
}
delphi51单片机串行通 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)