#include #include #define LSR 0x3fd /*Estado da porta série. Este registo contém os seguintes bits (activos a 1):*/ #define RBR 0x3f8 /*carácter recebido pela porta série*/ #define THR 0x3f8 /*carácter a ser enviado pela porta série*/ char receber_porta_serie() { unsigned char c; /* Caracter lido*/ unsigned char b = inportb( LSR ); /* ler registo de estado */ while ((b&1) == 0){ /*ESPERA ACTIVA*/ b = inportb (LSR); } c = inportb(RBR); return c; } int main (){ char valorLido; FILE *fout; fout = fopen( "p10_ex2.txt", "w" ); valorLido = receber_porta_serie(); while (valorLido != 32){ /*comparar com o espaco, ASCII 32 (decimal)*/ fputc(valorLido,fout); valorLido = receber_porta_serie(); } fclose(fout); return 0; }