Hello I'm doing a program about UART in Borland C. And I have a few questions. This is the code:
#include <iostream.h>
#include <dos.h>
#include <conio.h>
#include <stdio.h>
#define COM1 0x3F8
int main(void)
{
clrscr();
// outportb( COM1 + 1, 0 );
outportb( COM1 + 3, 0x83);
outportb( COM1, 0x0C);
outportb( COM1 + 1, 0x00);
outportb( COM1 + 3, 0x03);
char ans;
char readValue;
do
{
readValue = inportb( COM1 + 5 );
if ( readValue & 0x80 )
{
printf("ERROR!");
continue;
}
if ( readValue & 1 )
{
readValue = inportb( COM1 );
printf("%c", readValue);
}
if ( kbhit() )
{
ans = getch();
outportb( COM1, ans );
}
} while ( ans != 27 );
return 0;
}
The program reads char data from the COM1 port, and finds if there's any errors.
My question is how to simplify this program, or write it in different way. I need to present two different codes and I don't have idea for the second one.
Thanks!!!