72
{ c = 0;
for( m = 100;m;m-- )
{ send_port( PORT,*ps );
for( n = 1000;n;n-- )
{ delay(2); /* wait about 2ms,can use dos.h libray funtion:delay */
if( kbhit() && ( getch() == 27 ) ) /* if escape key keypress */
{ printf( "\nE20:Serial Port Write Canceled!" );
exit(1);
}
if( check_stat(PORT) & 256 )
{ c = read_port( PORT );
break;
}
}
if( n ) break;
}
if( c == *ps ) ps++;
else
{ printf( "\nE10:Serial Port Write Echo Error!" );
exit(1);
}
}
send_port( PORT,'\n' );/* send command end symbol */
delay( 2 );
while( !(check_stat(PORT) & 256) );
read_port( PORT );
}
/* read string from serial port */
void string_rd( char *ps )
{ unsigned char c,i;
for( i = 0;i < 255;i++ ) /* max read 256 characters */
{ while( ! (check_stat(PORT) & 256) ) /* wait serial receive ready */
if( kbhit() && (getch() == 27) ) /* if escape key keypress */
{ printf( "\nE21:Serial Port Read Canceled!" );
exit(1);
}
c = read_port( PORT );
if( c == '\n' ) break;
*ps = c;
ps++;
}
*ps = 0;
}