(Asynchronous Mode) - - - ( 1, 5~8, 1~2) & (Parity) 1 ; * S erial Port (BIOS INT 14H) - 1 -
UART (Univ ers al As y nchronous Receiver / T rans mitter) 8250A 8250A { COM1(3F8H). - Line Control Register : (data,stop bit, parity bit ) 3FBH - Line Status Register : 3FDH - Modem Control Register : 3FCH - Modem Status Register : 3FEH (CT S(Clear T o Send), DSR(Data Set Ready)line report - Baud Rate Generator : Baud Rate - Interrupt Enable Register : 8250A 4 3F9H - Interrupt ID Register : 3FAH - Receiver Buffer Register : 3F8H - T ransmitter Holding Register : " - 2 -
8250A Base Address - 3 -
EIA RS 232C 25pin 9pin ( ) - 4 -
* Polling, - Polling. F1 ~ F2 ~ F3 ~ F4 ~ F5 ~ Polling #include <stdio.h> #include <conio.h> #include <dos.h> #define COM_PORT 1 /* COM2 */ #define LF 0x0a #define CR 0x0d #define ESC 27 char status_ah; /* Line Status */ char status_al; /* Modem Status */ void init_serial(int port, unsigned char code) /* open com port*/ { union REGS r; r.x.dx = port; r.h.ah = 0; r.h.al = code; /* initialization code ---> main( ) */ int86(0x14, &r, &r); /* ROM BIOS INT 14H call. */ - 5 -
void check_rx(int port) { union REGS r; void r.x.dx = port; r.h.ah = 3; /* function 03H(Status Read) */ int86(0x14, &r, &r); /* BIOS INT 14H */ status_ah=r.h.ah; /* Line Status */ status_al=r.h.al; /* Modem Status */ menu(void) { int i; void clrscr(); window(1,1,80,7); clrscr(); for (i=0;i<80;i++) printf("="); printf("\t F1 = Serial Port Initialization \n"); printf("\t F2 = Line and Modem Status printf("\t F3 = Transmission Mode Set printf("\t F4 = Receiver Mode Set printf("\t F5 = Tx/Rx Polling Mode Set for (i=0;i<80;i++) printf("="); win(void) { int i; void for (i=0;i<80;i++) printf("="); window(1,10,80,25); clrscr(); tx_char(int port, char ch) { union REGS r; \n"); \n"); \n"); \n"); do { check_rx(com_port); /* Status Checking */ while(!(status_ah & 0x60));/* LSR and THR register empty? */ r.x.dx = port; r.h.ah = 1; r.h.al = ch; /* */ /* */ /* */ 0 1 1 0 * * * * - - - - - - - - - - - - - - - - - - - - T ransmitter Break Error Rx 0 Empty Detect Ready T ransmitter Buffer Empty int86(0x14, &r, &r); /* INT 14h for Transmission of 1 char. */ - 6 -
void tx(void) { char ch; while(1) { textattr(7); if(kbhit()) /* Transmission Request */ { ch=getch(); switch(ch) { case ESC : return; case CR : putch(cr); putch(lf); tx_char(com_port, CR); tx_char(com_port, LF); default : putch(ch); tx_char(com_port, ch); char rx_char(int port) { union REGS r; char ch; check_rx(com_port); /* Status Checking */ if(status_ah & 0x01) { r.x.dx=port; r.h.ah=2; int86(0x14, &r, &r); return r.h.al; /* Rx Data return */ else return 0x00; /* Data Empty */ void rx(void) { char ch; while(1) { textattr(7); if(kbhit()) { ch=getch(); - 7 -
if(ch==esc) return; else { ch=rx_char(com_port); if(ch!=0) { textattr(7<<4); /* Reversed Text Attribute */ putch(ch); /* Received Data */ textattr(7); /* Original Text Attribute */ void polling(void) { char ch; while(1) { textattr(7); if(kbhit()) /* Transmission Request */ { ch=getch(); switch(ch) { case ESC : return; case CR : tx_char(com_port, ch); tx_char(com_port, LF); putch(ch); putch(lf); default : tx_char(com_port, ch); putch(ch); else /* Receive Request */ { ch=rx_char(com_port); /* Data Receive */ if(ch!=0) { textattr(7<<4); /* Reversed Text */ putch(ch); /* Data Received */ textattr(7); /* Original Text Attribute */ - 8 -
void main(void) { union REGS r; char textattr(7); menu(); i, ch, fch, fkey=0; window(1,8,80,9); clrscr(); printf(" Function Key? (F1/F2/F3/F4/F5) "); while(1) { if (kbhit()) { ch=getch(); if (ch==0) { fch=getch(); /* function key input */ fkey=1; /* function key inputed */ window(1,8,80,9); clrscr(); printf(" Current Function : "); switch(fch) 1 1 1 0 0 1 1 1 - - - - - - - - - - - - - - - - - - - - - Baud stop rate ( ) bit (9600) (2) (8 ) { case 0x3b :/* F1 = serial port initialization */ init_serial(com_port, 0xe7); printf("serial Port Initialization \n"); win(); case 0x3c : /* F2 = Line and Modem Status */ check_rx(com_port); printf("line Status = %x H", status_ah); printf("\t Modem Status = %x H \n", status_al); win(); case 0x3d :/* F3 = Transmission Mode */ printf("transmission Mode \n"); win(); tx(); case 0x3e : /* F4 = Receiver Mode */ printf("receiver Mode win(); \n"); - 9 -
rx(); case 0x3f : /* F5 = Polling Function Input */ printf("tx/rx Polling Mode \n"); win(); polling(); default : /* Unknown Function Input */ printf("unknown Fuction \n"); win(); else /* not input function key */ { if (fkey==1) /* inputed function key */ { switch(ch) { case ESC : return; case CR : putch(lf); putch(cr); default : putch(ch); * Polling * (F1)/ (F2)/ (F3)/ (F4)/ ( )(F5) * * ESC Function ESC. - 10 -
MS- DOS MS- DOS BI OS - - - - - > I O. SYS :, SYSI NT MS- DOS ker nel - - - > MSDOS. SYS : I NT21H, C i nt dos( ), i nt dosx( ) MS- DOS Shel l - - - - > command. com :, bat ch f i l e &, rout i ne :. rout i ne :. CALL. [ ] r eg. h. ah = 0x30 ; f unct i on 30H i nt 86( 0x14, &r eg, &r eg) ; - - - - > ml = r eg. h. al ; mh = r eg. h. ah ; i nt dos( ), i nt 86( ), i nt 86x( ) cal l f unct i on. - - - - > dos. h st r uct ur e uni on SREGS : uni on REGS : dos. h. - 11 -