Board logo

标题: [建议]强烈建议! [打印本页]

作者: sunny1979     时间: 2003-11-20 00:00    标题: [建议]强烈建议!

编程区需要高手介入,好多问题至今还是问题,没有得到解答!
SOS:C里边的串口怎么定义,好象没人知道!
作者: 如是大师     时间: 2003-11-21 00:00
这一块我不太熟..不敢发言..
作者: sunny1979     时间: 2003-11-24 00:00    标题: 有谁帮我?

有谁帮我?[em01]
作者: GhostJ     时间: 2003-11-24 00:00
何為"串口"可以解釋一下嗎

作者: jddj007     时间: 2003-11-25 00:00
TC for DOS下控制串口
在Trubo C for DOS下要通过串口发送数据,就需要知道串口地址,然后才可以向该地址直接发送字符。
程序如下:
#include
#include
#include
#include
#include
#include
#include
typedef  short SHORT;

#define WAITIME 30000
#define DBUF    0X0       /* DATA BUFFER REGISTER  */
#define LSR     0x5       /* line status register  */

static SHORT portaddress[]={0x3f8,0x2f8,0x3e8,0x2e8};
/* 串口地址 COM1  COM2  COM3  COM4 */
static SHORT portadd; /*串口号码*/

/*发送数据到指定地址*/
void Out_func( port, c )
SHORT port;
char  c;
{
   SHORT i = 0;

   do
   {
      i++;
      if (i == WAITIME) break;
   }
   while (!(inp(port+LSR) & 0x20));  /* 0x3ed */
         /* wait until trans preparation */

   if (i < WAITIME)
      outp(port+DBUF,c);
}

/*把连续的字符串分解成单个字符发送*/
void Out_Array( num, str )
SHORT num;
char  *str;
{
   SHORT i;
   char *p;

   p = str;
   for ( i = 0; i<num; i++, p++ )
       Out_func( portadd, *p );
}

/*初始化串口*/
void light_init()
{
   Out_func( portadd, 0x1b );
   Out_func( portadd, 0x40 );

   /*发送清屏命令*/
   Out_func( portadd, 0x0c );
}