请问用TC2.0可以写通信方面的程序嘛?

yiko88 2004-08-29 08:59:20
请请问用TC2.0可以写通信方面的程序,可以写还的话,还要下载一下什么东东嘛?
如果那位写得出,可以给一个代码例子
...全文
153 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
CsdnPlayer 2004-08-30
  • 打赏
  • 举报
回复
建议你去看看dev-cpp。
CsdnPlayer 2004-08-30
  • 打赏
  • 举报
回复
国内认真搞C语言得太少了。
你到国外下载网络扩展包,不就行了?TC2只是一个环境。没有include里的头文件,他什么也做不了。
sharkhuang 2004-08-30
  • 打赏
  • 举报
回复
2者没有必然联系.
liushuaiboy 2004-08-30
  • 打赏
  • 举报
回复
mark
new_c 2004-08-29
  • 打赏
  • 举报
回复
好东西哦 收藏 谢谢
Rance 2004-08-29
  • 打赏
  • 举报
回复
继续~~~~~~~~~~```

gettime(&record_time);
average_v=SCALE*TEST_AREA_WIDTH/cnt.PassTime;
/***** display and write record to ctrldata.txt ****/
/*printf("PTC01%02x%02x ",cnt.c[0],cnt.c[1]);*/
/*printf("\nP T %04x ",cnt.PassTime);
printf("RT%02d:%02d:",record_time.ti_hour,record_time.ti_min);
printf("%02d.%02d ",record_time.ti_sec,record_time.ti_hund);
printf(" AV%010.4f ",average_v);*/

fprintf(fp,"\nP T %04x ",cnt.PassTime);
fprintf(fp,"RT%02d:%02d:",record_time.ti_hour,record_time.ti_min);
fprintf(fp,"%02d.%02d ",record_time.ti_sec,record_time.ti_hund);
fprintf(fp," AV%010.4f ",average_v);
/************** count flow ******************/
if (COUNT_TIME_UNIT==1) tt[1]=record_time.ti_min;
switch(COUNT_TIME_UNIT)
{ case 1:if((tt[1]-tt[0])!=0)
{
/*printf("\n\n%2ds* * * zong shu * * * * * %3ld ",tt

[0],tongji);*/
tt0=tt[0];
for(i=480;i<595;i++)
for(j=40;j<55;j++) putpixel(i,j,14);
itoa(tt0,temp,10);
outtextxy(480, 43,temp);
itoa(tongji,temp,10);
outtextxy(540,43,temp);
lamp(200,40,EGA_BLUE);
/* lamp(250,40,EGA_BLUE);
lamp(300,40,EGA_BLUE); */

if(tongji>30)
{
lamp(200,40,EGA_GREEN);
lamp(300,40,EGA_BLUE);
for(i=140;i<160;i++)
for(j=35;j<50;j++) putpixel(i,j,14);
outtextxy(140,40,"10");
sleep(10); /***** tongji>25 ******/
lamp(200,40,EGA_BLUE);
}
else if(tongji>25)
{ lamp(200,40,EGA_GREEN);
lamp(300,40,EGA_BLUE);
for(i=140;i<160;i++)
for(j=35;j<50;j++) putpixel(i,j,14);
outtextxy(140,40,"08");
sleep(8);
lamp(200,40,EGA_BLUE);
}
else if(tongji>20)
{ lamp(200,40,EGA_GREEN);
lamp(300,40,EGA_BLUE);
for(i=140;i<160;i++)
for(j=35;j<50;j++) putpixel(i,j,14);
outtextxy(140,40,"06");
sleep(6);
lamp(200,40,EGA_BLUE);
}
else
{ lamp(200,40,EGA_GREEN);
lamp(300,40,EGA_BLUE);
for(i=140;i<160;i++)
for(j=35;j<50;j++) putpixel(i,j,14);
outtextxy(140,40,"04");
sleep(4);
lamp(200,40,EGA_BLUE);
};

/* lamp(250,40,EGA_YELLOW);
sleep(1);
lamp(250,40,EGA_BLUE);*/
for(i=140;i<160;i++)
for(j=35;j<50;j++) putpixel(i,j,14);
lamp(300,40,EGA_RED);

if(begin==0||begin==1) begin=begin+1;
else
{
fprintf(statistic,"%3d %3ld\n",tt0,tongji);
line(10+tt_1*10,465-tongji_1*5,10+tt0*10,465-tongji*5);line

(10+tt_1*10,466-tongji_1*5,10+tt0*10,466-tongji*5);
circle(10+tt0*10,465-tongji*5,2);
}
fprintf(fp,"\n%2ds &&* * * * zong shu * * * **&& %3ld

",tt[0],tongji);
tongji_1=tongji;tt_1=tt0;
tongji=0L;
for(i=480;i<595;i++)
for(j=40;j<55;j++) putpixel(i,j,14);
itoa(tt0,temp,10);
outtextxy(480, 43,temp);
itoa(tongji,temp,10);
outtextxy(540,43,temp);
}

for(i=480;i<595;i++)
for(j=66;j<82;j++) putpixel(i,j,14);
itoa(record_time.ti_hour,temp,10);
outtextxy(480,70,temp);
outtextxy(500,70,":");
itoa(tt[1],temp,10);
outtextxy(510,70,temp);
outtextxy(527,70,":");
itoa(record_time.ti_sec,temp,10);
outtextxy(536,70,temp);
itoa(tongji,temp,10);
outtextxy(570,70,temp);

tt[0]=tt[1];
tt[1]=record_time.ti_min;
tongji=tongji+1;
/* printf(" ********** %3ld\n",tongji); */
fprintf(fp," *********** %3ld\n",tongji);
break;
case 2:printf("wait for update");
if((tt[1]-tt[0])!=0)
{printf("\n\n%ds* * * zong shu * * * * %3ld ",tt

[0],tongji);
fprintf(fp,"\n\n%2ds* * * zong shu * * * * %3ld ",tt

[0],tongji);
tongji=0L;}
tt[0]=tt[1];
tt[1]=record_time.ti_hour;
tongji=tongji+1;
printf(" *********** %3ld\n",tongji);
fprintf(fp," *********** %2ld\n",tongji);
break;
}

if(kbhit()) r.x.ax=bioskey(0);
} while (r.h.al!=27);
fclose(fp);
#if CONDI
fclose(fp0);
#endif
fclose(statistic);
closegraph();
}
Rance 2004-08-29
  • 打赏
  • 举报
回复
可以啊.
我和同学写过一个串行通信的程序.
下面这个程序仅供参考:

#define COM1PORT 0
#define COM2PORT 1
#define TEST_AREA_WIDTH 0.10 /*** 0.10 m ***/
#define SCALE (1.0e6/1.085) /* unit convert ,wait for update */
#define CONDI 1 /* 1-simulate process 0-real time process */
#define COUNT_TIME_AREA_WITDH 2
#define COUNT_TIME_UNIT 1 /* 1-minite 2-hour */
#include "dos.h"
#include "graphics.h"
#include "stdlib.h"
#include "stdio.h"

/**********************初始化函数***********************/
/*******************************************************
* 入口参数: port -- 串行口参数 0---com1, 1---com2 *
* code-- 初始化串行口设置波特率(3bit) *
* 奇偶位(2bit)、停止位(1bit)、 *
* 数据长度(2bit) *
* 返 回 值:无 *
*******************************************************/
void port_init(int port,char code)
{ union REGS r;
r.x.dx=port;
r.h.ah=0;
r.h.al=code;
int86(0x14,&r,&r);
return ;
}


/**********************取串行口状态函数********************/
/*******************************************************
* 入口参数: port -- 串行口参数 0---com1, 1---com2 *
* 返 回 值:串行口状态码AX,其中 AH==传送线路状态码 *
* AL==调制解调器状态码 *

*
*******************************************************/
unsigned int check_stat(int port)
{ union REGS r;
r.x.dx=port;
r.h.ah=3;
int86(0x14,&r,&r);
return r.x.ax;
}

/*******************从串行口读取一个字符*****************/
/*******************************************************
* 入口参数: port -- 串行口参数 0---com1, 1---com2 *
* 返 回 值:1-----返回ah的最高位1,表示接收错误 *
* 非1--返回低字节al---接收字符的ascii码 *
* *
*******************************************************/


unsigned char read_port(int port) /* read a character from port*/
{
union REGS r;
while(!(check_stat(port)&256)) /*256?wait for a character*/
if(kbhit()){ getch();exit(1);}; /*****exit(1)??return 1?? */
r.x.dx=port;
r.h.ah=2;
int86(0x14,&r,&r);
if(r.h.ah&128)
{ printf(" read error in serial port");
return 1; /*接收错误*/
}
else return r.h.al;/*接收成功,返回接收的字节*/
}



/*******************向串行口发送一个字符*****************/
/*******************************************************
* 入口参数: port -- 串行口参数 0---com1, 1---com2 *
* c--------存放要发送的字符(一个字节) *
* 返 回 值:返回ah的最高位的值 *
* 1-----发送错误 , *
* 0--发送字符的ASCII码成功 *
* *
*******************************************************/

int send_port(int port,char c)
{ union REGS r;
r.x.dx=port;
r.h.al=c;
r.h.ah=1;
int86(0x14,&r,&r);
if(r.h.ah&128)
{printf(" send error in serial port");
return 1; /*返回ah的最高位*/
}
else return 0;/*返回ah的最高位*/
}


void lamp(int x,int y,int color)
{
setfillstyle(SOLID_FILL,1);
bar(x-20,y-20,x+20,y+20);
floodfill(x,y,0);
setfillstyle(SOLID_FILL,color);
setcolor(color);
circle(x,y,15);
floodfill(x,y,color);

}





main()
{ union { unsigned char c[2];
unsigned int PassTime;} cnt;
union REGS r;
FILE *fp,*fp0,*fp00,*statistic;
struct time record_time,sys_time;
float average_v;
int i,tt[2]={0,2},sec,j,begin=0;
long tongji=1L,tongji_1=0L;
int tt0=0,tt_1=0;
int me,me_1,gdriver,gmode,cankaoD,cankaoT;
unsigned char cc[4],zcc[4][2],space[2],temp[3],temp1;


/**************** process data file ************/
#if CONDI /* CONDI为1时,仿真处理 */
if((fp00=fopen("qy.txt","r+"))==NULL)
{ printf("can not open file");exit(1);}
if((fp0=fopen("temp.txt","w"))==NULL)
{ printf("can not open file");exit(1);}
temp[0]=fgetc(fp00);temp[1]=fgetc(fp00);
while(!feof(fp00))
{ temp[2]=fgetc(fp00);
/* printf("\n*%c%c%c*",temp[0],temp[1],temp[2]); */
if((temp[0]==' ')&&(temp[2]==' '))
{fputc(temp[0],fp0); fputc('0',fp0);}
else fputc(temp[0],fp0);
temp[0]=temp[1];
temp[1]=temp[2];
}
fputc(temp[1],fp0); fputc(temp[2],fp0);
fclose(fp0);fclose(fp00);
if((fp0=fopen("temp.txt","r"))==NULL)
{ printf("can not open file");exit(1);}
#endif
/****************To simulate process file is over *****/


if((fp=fopen("ctrldata.txt","a+"))==NULL)
{ printf("can not open file");exit(1);}

if((statistic=fopen("sta.txt","a+"))==NULL)
{ printf("can not open file");exit(1);}

#if !CONDI
port_init(COM1PORT,0xe3);
/***串行通信端口----COM1
波特率 9600----111
无奇偶校验位---00
一位停止位-----0
八位数据位-----11
二进制11100011=十六进制e3 */
#endif
/****************draw prepare********/
system("cls");
if(registerbgidriver(EGAVGA_driver)<0) exit(1);
detectgraph(&gdriver,&gmode);
initgraph(&gdriver,&gmode,"");
setlinestyle(1,0,1);
setbkcolor(7);
setcolor(8);
for(me=10;me<=630;me=me+10)
line(me,10,me,479);
for(me=15;me<=475;me=me+10)
line(10,me,630,me);
setlinestyle(0,0,2);
setcolor(10);
line(10,465,630,465);line(10,466,630,466);
outtextxy(600,450,"T");
outtextxy(460, 20," press Esc key:exit");
line(10,10,10,479);line(11,10,11,479);
outtextxy(20,30,"f");outtextxy(20,40,"l");
outtextxy(20,50,"o");outtextxy(20,60,"w");
setcolor(1);


do{
#if CONDI
fgets(zcc[0],2,fp0);fgets(zcc[1],2,fp0);
fgets(space,2,fp0);
fgets(zcc[2],2,fp0);fgets(zcc[3],2,fp0);
if(!feof(fp0)) fgets(space,2,fp0);
else break;
for(i=0;i<4;i++)
if ((zcc[i][0]>=48)&&(zcc[i][0]<58)) cc[i]=atoi(zcc[i]);
else if( (zcc[i][0]>='A')&&(zcc[i][0]<='F') ) cc[i]=zcc[i][0]-55;
else if((zcc[i][0]>='a')&&(zcc[i][0]<='f')) cc[i]=zcc[i][0]-87;
/*printf("\nstring %c%c%c%c",zcc[0][0],zcc[1][0],zcc[2][0],zcc[3][0]);
printf("\nHexHex %x%x%x%x",cc[0],cc[1],cc[2],cc[3]);*/
cnt.c[1]=(cc[0]<<4)+cc[1]; /* at first,to send low byte */
cnt.c[0]=(cc[2]<<4)+cc[3];
/*printf("\nPTC012 %02x%02x ",cnt.c[0],cnt.c[1]);*/
sec=random(5);
sleep(sec);
#else
cnt.c[0]=read_port(COM1PORT); /** get data from serial port*/
cnt.c[1]=read_port(COM1PORT); /** get data from serial port*/
/***??si hu bu gai jiao huan ???????temp use*dai kao cha**/
/* at first,to send low byte */
temp1=cnt.c[0];cnt.c[0]=cnt.c[1];cnt.c[1]=temp1;
#endif

young130 2004-08-29
  • 打赏
  • 举报
回复
pctcp

70,024

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧