TurboC版的串口通信程序改成delphi版(200分)

  • 主题发起人 主题发起人 NRen
  • 开始时间 开始时间
N

NRen

Unregistered / Unconfirmed
GUEST, unregistred user!
帮我把下面的TurboC版的串口通信程序改成delphi版的,我从未接触过串口,
控件用ComPort,谢谢,
/* 液晶显示器检测程序 */
/* 通过串行口发送 ASIIC 码,波特率2400 */
/* 发送格式为:@G12,T1,2,3,4,5#y/r/n */
/* y是G12,T1,2,3,4,5的异或,是校验位,/r/n是回车换行 */
#include <stdio.h>
#include <dos.h>
#include <math.h>

#define s_port 2 /* 使用串行口2 */

int init_uart(int s_p);
char receive();

char m[]={'@','G','1','2',',','T','1',',','2',',','3',',','4',',','6',',','7',',',
/* '8',',','9',',','1','0',',','1','1',',','1','2',',','1','3',',','1','4',',',
'1','5',',','1','6',',','1','7',',','1','8',',','1','9',',','2','0',',',
'2','1',',','2','2',',','2','3',',','2','4',',','2','5',',','2','6',',',
'2','7',',','2','8',',','2','9',',','3','0',',','3','1',',','3','2',',',
'3','3',',','3','4',',','3','5',',','3','6',',','3','7',',','3','8',',',
'3','9',',','4','0',',','4','1',',','4','2',',','4','3',',',
'4','5',',','4','6',',',*/

'#',0x0};
/* char m[]={'@','G','1','2',',','T','1',',','#',0x0};*/
main() {
char *c,cc;
init_uart(s_port); /* 初始化传行口 */
c=m;
cc='@';
printf(&quot;/n&quot;);
while(*c!=0) {
while( !( inportb(0x2fd) & 0x20 ) ) { ; }
outportb(0x2f8,*c);
printf(&quot;%c &quot;,*c);
if(*c!='#') cc=cc ^ *c;
c++;
}
while( !( inportb(0x2fd) & 0x20 ) ) { ; }
outportb(0x2f8,cc);
printf(&quot;%d &quot;,cc);
while( !( inportb(0x2fd) & 0x20 ) ) { ; }
outportb(0x2f8,0x0d);
printf(&quot;%d &quot;,0x0d);
while( !( inportb(0x2fd) & 0x20 ) ) { ; }
outportb(0x2f8,0x0a);
printf(&quot;%d/n &quot;,0x0a);
cc=receive();
printf(&quot;/n end of check up/n/n&quot;);
}

char receive() {
long hex;
char c,sign,wait;

wait = 1;
while( !(inportb(0x2fd) & 0x01) ) { ; }
c = inportb(0x2f8);
printf(&quot; %c&quot;,c);
return(c);
}

int init_uart(int s_p) {
int F8,F8L,F9H,FB,FC;
int re;
re=0;
if(s_p==2) {
F8=0x2f8;
F8L=0x2f8;
F9H=0x2f9;
FB=0x2fb;
FC=0x2fc;
} else if(s_p==3) {
F8=0x3f8;
F9H=0x3f9;
F8L=0x3f8;
FB=0x3fb;
FC=0x3fc;
} else re=1;
outportb(FB,0x80);
outportb(F8L,0x30);
outportb(F9H,0x00); /* 波特率2400 */
outportb(FB,0x03);
outportb(FC,0x03);
outportb(F8,0x0);
return(re);
}
 
你既然知道如果发送和接收,改用SPCOMM应该没有问题。
 
看来还是没人答呀!
我已经搞定了:ComPort1.WriteStr('@G12,T1,2,3,4,6,7,8,9,#'#56#13#10);
谢谢蓝叶菱的支持!
 

Similar threads

I
回复
0
查看
1K
import
I
I
回复
0
查看
818
import
I
I
回复
0
查看
843
import
I
后退
顶部