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("/n"
while(*c!=0) {
while( !( inportb(0x2fd) & 0x20 ) ) { ; }
outportb(0x2f8,*c);
printf("%c ",*c);
if(*c!='#') cc=cc ^ *c;
c++;
}
while( !( inportb(0x2fd) & 0x20 ) ) { ; }
outportb(0x2f8,cc);
printf("%d ",cc);
while( !( inportb(0x2fd) & 0x20 ) ) { ; }
outportb(0x2f8,0x0d);
printf("%d ",0x0d);
while( !( inportb(0x2fd) & 0x20 ) ) { ; }
outportb(0x2f8,0x0a);
printf("%d/n ",0x0a);
cc=receive();
printf("/n end of check up/n/n"
}
char receive() {
long hex;
char c,sign,wait;
wait = 1;
while( !(inportb(0x2fd) & 0x01) ) { ; }
c = inportb(0x2f8);
printf(" %c",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);
}
控件用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("/n"
while(*c!=0) {
while( !( inportb(0x2fd) & 0x20 ) ) { ; }
outportb(0x2f8,*c);
printf("%c ",*c);
if(*c!='#') cc=cc ^ *c;
c++;
}
while( !( inportb(0x2fd) & 0x20 ) ) { ; }
outportb(0x2f8,cc);
printf("%d ",cc);
while( !( inportb(0x2fd) & 0x20 ) ) { ; }
outportb(0x2f8,0x0d);
printf("%d ",0x0d);
while( !( inportb(0x2fd) & 0x20 ) ) { ; }
outportb(0x2f8,0x0a);
printf("%d/n ",0x0a);
cc=receive();
printf("/n end of check up/n/n"
}
char receive() {
long hex;
char c,sign,wait;
wait = 1;
while( !(inportb(0x2fd) & 0x01) ) { ; }
c = inportb(0x2f8);
printf(" %c",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);
}