First things first - what are those loops doing?
You're calling fscanf() twice per loop, which means half your file is being thrown away before you do anything.
Unless your file contains strings of exactly 3361 characters, you're going to send a lot of junk characters to the serial port.
Calling an input file 'outfile' doesn't seem right.
If you're wanting to dump a file to the serial port, then something like this would be better
Code:
char buff[1000];
while ( fgets( buff, 1000, infile ) != NULL ) {
for ( i = 0 ; i < strlen(buff) ; i++ ) {
outportb(PORT1, buff[i]);
}
}
Now you need to get this
Download parts A to D
Now the key information is as follows
Serial ports are controlled by a number of registers which are offset from the PORT1 register you have used.
Code:
03F8 -W serial port, transmitter holding register (THR), which contains the
character to be sent. Bit 0 is sent first.
bit 7-0 data bits when DLAB=0 (Divisor Latch Access Bit)
03F8 R- receiver buffer register (RBR), which contains the received
character. Bit 0 is received first
bit 7-0 data bits when DLAB=0 (Divisor Latch Access Bit)
03F8 RW divisor latch low byte (DLL) when DLAB=1 (see #P0876)
03F9 RW divisor latch high byte (DLM) when DLAB=1 (see #P0876)
03F9 RW interrupt enable register (IER) when DLAB=0 (see #P0877)
03FA R- interrupt identification register (see #P0878)
Information about a pending interrupt is stored here. When the ID
register is addressed, thehighest priority interrupt is held, and
no other interrupts are acknowledged until the CPU services that
interrupt.
03FA -W 16650 FIFO Control Register (FCR) (see #P0879)
03FB RW line control register (LCR) (see #P0880)
03FC RW modem control register (see #P0881)
03FD R- line status register (LSR) (see #P0882)
03FE R- modem status register (MSR) (see #P0883)
03FF RW scratch register (SCR)
(not used for serial I/O; available to any application using 16450,
16550) (not present on original 8250)
So for example, if PORT1 is 03F8, then what you're doing when you do
is writing to the "transmitter holding register".
OK, so now for handshaking
Code:
Bitfields for serial port Line Status Register (LSR):
Bit(s) Description (Table P0882)
7 =0 reserved
=1 on some chips produced by UMC
6 transmitter shift and holding registers empty
5 transmitter holding register empty (THRE)
Controller is ready to accept a new character to send.
Recall that the LSR register would be at address 03FD (or PORT1+5)
The interesting bit here is bit 5, since it tells us whether the transmit holding register is empty or not.
If it is empty, we're good to go to send another character.
So the modified loop might look something like this
Code:
char buff[1000];
while ( fgets( buff, 1000, infile ) != NULL ) {
for ( i = 0 ; i < strlen(buff) ; i++ ) {
/* send a character */
outportb(PORT1, buff[i]);
/* wait for it to finish sending */
while ( (inportb(PORT1+5) & 0x20) == 0 ) {
/* loop here until the current char has been sent */
/* the bit being tested will be set and this loop will exit */
}
}
}
The actual "Clear to Send" flag is in the Modem Status Register (MSR), but I'll leave you to get those Ralph Brown files and read up for yourself (the information you want is in the PORTS.B file).