C Programming :
Function :_bios_serialcom
Syntax
#include <bios.h>
unsigned _bios_serialcom(int cmd, int port, char abyte);
Description
_bios_serialcom performs various RS-232 communications over the I/O port given in port.
A port value of 0 corresponds to COM1, 1 corresponds to COM2, and so forth.
The value of cmd can be one of the following values (defined in bios.h):
_COM_INIT Sets the communications parameters to the value in abyte.
_COM_SEND Sends the character in abyte out over the communications line.
_COM_RECEIVE Receives a character from the communications line. The abyte argument is ignored.
_COM_STATUS Returns the current status of the communications port. The abyte argument is ignored.
When cmd is _COM_INIT, abyte is a OR combination of the following bits:
Select only one of these:
_COM_CHR7 7 data bits
_COM_CHR8 8 data bits
Select only one of these:
_COM_STOP1 1 stop bit
_COM_STOP2 2 stop bits
Select only one of these:
_COM_NOPARITY No parity
_COM_ODDPARITY Odd parity
_COM_EVENPARITY Even parity
Select only one of these:
_COM_110 110 baud
_COM_150 150 baud
_COM_300 300 baud
_COM_600 600 baud
_COM_1200 1200 baud
_COM_2400 2400 baud
_COM_4800 4800 baud
_COM_9600 9600 baud
For example, a value of ( _COM_9600 | _COM_ODDPARITY | _COM_STOP1 |_COM_CHR8 ) for abyte sets thecommunicationsportto9600
baud,oddparity,1 stop bit, and 8 data bits. _bios_serialcom uses the BIOS 0x14 interrupt.
For all values of cmd, _bios_serialcom returns a 16-bit integer of which the upper 8 bits are status bits and the lower 8 bits vary, depending on the
value of cmd. The upper bits of the return value are defined as follows:
Bit 15 Time out
Bit 14 Transmit shift register empty
Bit 13 Transmit holding register empty
Bit 12 Break detect
Bit 11 Framing error
Bit 10 Parity error
Bit 9 Overrun error
Bit 8 Data ready
If the abyte value could not be sent, bit 15 is set to 1. Otherwise, the remaining upper and lower bits are appropriately set. For example, if a framing
error has occurred, bit 11 is set to 1.
With a cmd value of _COM_RECEIVE, the byte read is in the lower bits of the return value if there is no error. If an error occurs, at least one of the
upper bits is set to 1. If no upper bits are set to 1, the byte was received without error. With a cmd value of _COM_INIT or COM_STATUS, the return
value has the upper bits set as defined, and the lower bits are defined as follows:
Bit 7 Received line signal detect
Bit 6 Ring indicator
Bit 5 Data set ready
Bit 4 Clear to send
Bit 3 Change in receive line signal detector
Bit 2 Trailing edge ring detector
Bit 1 Change in data set ready
Bit 0 Change in clear to send
Example :
/* _bios_serialcom example (for COM1) */
/*
This example can be used to communicate between
two PCs via a null modem cable.
This example is specific to COM1.
*/
#include <bios.h>
#include <conio.h>
#include <dos.h>
#define DTR 0x01 // Data Terminal Ready
#define RTS 0x02 // Ready To Send
#define COM1PORT 0x0000 // Pointer to Location of COM1 port
#define COM2PORT 0x0002 // Pointer to Location of COM2 port
#define COM1 0
#define COM2 1
#define DATA_READY 0x100
#define FALSE 0
#define TRUE !FALSE
#define SETTINGS ( 0xE0 | 0x00 | 0x02 | 0x00) // 9600,N,7,1
int main( void )
{
int in,
out,
status,
DONE = FALSE,
far *RS232_Addr;
/* Determine port location of COM1.
0x40:0x00 = COM1 I/O port address
0x40:0x02 = COM2 I/O port address
*/
RS232_Addr = MK_FP( 0x0040, COM1PORT );
if( !*RS232_Addr )
return -1;
_bios_serialcom( 0, COM1, SETTINGS );
cprintf( "... BIOSCOM [ESC] to exit ...\n" );
while( !DONE )
{
/* Reset DTR and RTS to prepare for send/receive of next character */
outportb( *RS232_Addr + 4, DTR | RTS );
/* Get status of com port */
status = _bios_serialcom( 3, COM1, 0 );
if( status & DATA_READY )
/* There's a character on the port. Get it and echo. */
if(( out =_bios_serialcom( 2, COM1, 0 ) & 0x7F) != 0)
putch( out );
if( kbhit() )
/* Key has been struck. Get it and send to port */
if( (in = getch()) == '\x1B' )
/* User pressed ESCAPE. Don't send to port */
DONE = TRUE;
else
/* Send character to com port. */
_bios_serialcom( 1, COM1, in );
}
return 0;
}
Function :_bios_serialcom
Syntax
#include <bios.h>
unsigned _bios_serialcom(int cmd, int port, char abyte);
Description
_bios_serialcom performs various RS-232 communications over the I/O port given in port.
A port value of 0 corresponds to COM1, 1 corresponds to COM2, and so forth.
The value of cmd can be one of the following values (defined in bios.h):
_COM_INIT Sets the communications parameters to the value in abyte.
_COM_SEND Sends the character in abyte out over the communications line.
_COM_RECEIVE Receives a character from the communications line. The abyte argument is ignored.
_COM_STATUS Returns the current status of the communications port. The abyte argument is ignored.
When cmd is _COM_INIT, abyte is a OR combination of the following bits:
Select only one of these:
_COM_CHR7 7 data bits
_COM_CHR8 8 data bits
Select only one of these:
_COM_STOP1 1 stop bit
_COM_STOP2 2 stop bits
Select only one of these:
_COM_NOPARITY No parity
_COM_ODDPARITY Odd parity
_COM_EVENPARITY Even parity
Select only one of these:
_COM_110 110 baud
_COM_150 150 baud
_COM_300 300 baud
_COM_600 600 baud
_COM_1200 1200 baud
_COM_2400 2400 baud
_COM_4800 4800 baud
_COM_9600 9600 baud
For example, a value of ( _COM_9600 | _COM_ODDPARITY | _COM_STOP1 |_COM_CHR8 ) for abyte sets thecommunicationsportto9600
baud,oddparity,1 stop bit, and 8 data bits. _bios_serialcom uses the BIOS 0x14 interrupt.
For all values of cmd, _bios_serialcom returns a 16-bit integer of which the upper 8 bits are status bits and the lower 8 bits vary, depending on the
value of cmd. The upper bits of the return value are defined as follows:
Bit 15 Time out
Bit 14 Transmit shift register empty
Bit 13 Transmit holding register empty
Bit 12 Break detect
Bit 11 Framing error
Bit 10 Parity error
Bit 9 Overrun error
Bit 8 Data ready
If the abyte value could not be sent, bit 15 is set to 1. Otherwise, the remaining upper and lower bits are appropriately set. For example, if a framing
error has occurred, bit 11 is set to 1.
With a cmd value of _COM_RECEIVE, the byte read is in the lower bits of the return value if there is no error. If an error occurs, at least one of the
upper bits is set to 1. If no upper bits are set to 1, the byte was received without error. With a cmd value of _COM_INIT or COM_STATUS, the return
value has the upper bits set as defined, and the lower bits are defined as follows:
Bit 7 Received line signal detect
Bit 6 Ring indicator
Bit 5 Data set ready
Bit 4 Clear to send
Bit 3 Change in receive line signal detector
Bit 2 Trailing edge ring detector
Bit 1 Change in data set ready
Bit 0 Change in clear to send
Example :
/* _bios_serialcom example (for COM1) */
/*
This example can be used to communicate between
two PCs via a null modem cable.
This example is specific to COM1.
*/
#include <bios.h>
#include <conio.h>
#include <dos.h>
#define DTR 0x01 // Data Terminal Ready
#define RTS 0x02 // Ready To Send
#define COM1PORT 0x0000 // Pointer to Location of COM1 port
#define COM2PORT 0x0002 // Pointer to Location of COM2 port
#define COM1 0
#define COM2 1
#define DATA_READY 0x100
#define FALSE 0
#define TRUE !FALSE
#define SETTINGS ( 0xE0 | 0x00 | 0x02 | 0x00) // 9600,N,7,1
int main( void )
{
int in,
out,
status,
DONE = FALSE,
far *RS232_Addr;
/* Determine port location of COM1.
0x40:0x00 = COM1 I/O port address
0x40:0x02 = COM2 I/O port address
*/
RS232_Addr = MK_FP( 0x0040, COM1PORT );
if( !*RS232_Addr )
return -1;
_bios_serialcom( 0, COM1, SETTINGS );
cprintf( "... BIOSCOM [ESC] to exit ...\n" );
while( !DONE )
{
/* Reset DTR and RTS to prepare for send/receive of next character */
outportb( *RS232_Addr + 4, DTR | RTS );
/* Get status of com port */
status = _bios_serialcom( 3, COM1, 0 );
if( status & DATA_READY )
/* There's a character on the port. Get it and echo. */
if(( out =_bios_serialcom( 2, COM1, 0 ) & 0x7F) != 0)
putch( out );
if( kbhit() )
/* Key has been struck. Get it and send to port */
if( (in = getch()) == '\x1B' )
/* User pressed ESCAPE. Don't send to port */
DONE = TRUE;
else
/* Send character to com port. */
_bios_serialcom( 1, COM1, in );
}
return 0;
}
No comments:
Post a Comment