Controlling the serial port under TC for DOS
To send data through the serial port in Trubo C for DOS, you need to know the serial port address first, and only then can you send characters directly to that address.
The program is as follows:
#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};
/* serial port addresses COM1 COM2 COM3 COM4 */
static SHORT portadd; /*serial port number*/
/*send data to the specified address*/
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);
}
/*break a continuous string into individual characters and send them*/
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 );
}
/*initialize the serial port*/
void light_init()
{
Out_func( portadd, 0x1b );
Out_func( portadd, 0x40 );
/*send clear-screen command*/
Out_func( portadd, 0x0c );
}