Upload
jgporg
View
257
Download
0
Embed Size (px)
DESCRIPTION
PRINT OUT COPIES FOR CN LAB FIRST EX
Citation preview
bioscom and _bios_serialcom <BIOS.H>
RS-232 communications (serial I/O)
Declaration: int bioscom(int cmd, char abyte, int port); unsigned _bios_serialcom(int cmd, int port, char abyte);
RemarksBoth bioscom and _bios_serialcom use BIOS interrupt 0x14 to perform variousRS-232 communications over the I/O port given in port.
Arg. What It Is/Does
abyte
cmd Port
OR combination of bits that specifies COM port settings (ignored if cmd = 2 or 3) Specifies the I/O operation to performIdentifies the I/O port; 0 = COM1, 1 = COM2, etc.
Return Value:For all values of cmd, both functions return a 16-bit integer.
The upper 8 bits of the return value are status bits. þ If one or more status bits is set to 1, an error has occured. þ If no status bits are set to 1, the byte was received without error.
The lower 8 bits of the return value depend on the value of cmd specified:
Portability:
DOS UNIX ANSI C C++ Only Yes
bioscom example
Value of cmd Lower 8 bits of return value
0 (_COM_INIT) or 3 (_COM_STATUS)
The lower bits are defined as shown in the preceding diagram.
1 (_COM_SEND) ...
2 (_COM_RECEIVE)
The byte read is in the lower bits of the return value--if there is no error (no upper bits are set to 1).
#include <bios.h>#include <conio.h>
#define COM1 0#define DATA_READY 0x100#define TRUE 1#define FALSE 0
#define SETTINGS ( 0x80 | 0x02 | 0x00 | 0x00)
int main(void){ int in, out, status, DONE = FALSE;
bioscom(0, SETTINGS, COM1); cprintf("... BIOSCOM [ESC] to exit ...\n"); while (!DONE) { status = bioscom(3, 0, COM1); if (status & DATA_READY) if ((out = bioscom(2, 0, COM1) & 0x7F) != 0) putch(out); if (kbhit()) { if ((in = getch()) == '\x1B') DONE = TRUE; bioscom(1, in, COM1); } } return 0;}
bios_serialcom example
#include <bios.h>#include <conio.h>
#define COM1 0#define DATA_READY 0x100#define TRUE 1#define FALSE 0#define SETTINGS (_COM_1200 | _COM_CHR7 | _COM_STOP1 | _COM_NOPARITY)
int main(void){ unsigned in, out, status;
_bios_serialcom(_COM_INIT, COM1, SETTINGS); cprintf("... _BIOS_SERIALCOM [ESC] to exit ...\r\n"); for (;;) { status = _bios_serialcom(_COM_STATUS, COM1, 0); if (status & DATA_READY) if ((out = _bios_serialcom(_COM_RECEIVE, COM1, 0) & 0x7F) != 0) putch(out); if (kbhit()) { if ((in = getch()) == '\x1B') break; _bios_serialcom(_COM_SEND, COM1, in); } } return 0;}