Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.75 KB | None | 0 0
  1.  /* Name       : Sample Comm's Program - Polled Version - termpoll.c     */
  2.  /* Written By : Craig Peacock <cpeacock@senet.com.au>                   */
  3.  /* Date       : Saturday 22nd February 1997                             */
  4.  
  5.  /*        Copyright 1997 CRAIG PEACOCK <cpeacock@senet.com.au>          */
  6.  
  7.  /*         See http://www.senet.com.au/~cpeacock/serial1.htm            */
  8.  /*                       For More Information                           */
  9.  
  10. #include <dos.h>
  11. #include <stdio.h>
  12. #include <conio.h>
  13. #include <time.h>
  14.  
  15. #define PORT1 0x3F8
  16. #define TTL 2
  17.  
  18.   /* Defines Serial Ports Base Address */
  19.   /* COM1 0x3F8                        */
  20.   /* COM2 0x2F8                */
  21.   /* COM3 0x3E8                */
  22.   /* COM4 0x2E8                */
  23.  
  24. void main(void)
  25. {
  26.  int c;
  27.  int ch;
  28.  time_t now;
  29.  outportb(PORT1 + 1 , 0);   /* Turn off interrupts - Port1 */
  30.  
  31.  /*         PORT 1 - Communication Settings         */
  32.  
  33.  outportb(PORT1 + 3 , 0x80);  /* SET DLAB ON */
  34.  outportb(PORT1 + 0 , 0x03);  /* Set Baud rate - Divisor Latch Low Byte */
  35.                   /* Default 0x03 =  38,400 BPS */
  36.                   /*         0x01 = 115,200 BPS */
  37.                   /*         0x02 =  57,600 BPS */
  38.                   /*         0x06 =  19,200 BPS */
  39.                   /*         0x0C =   9,600 BPS */
  40.                   /*         0x18 =   4,800 BPS */
  41.                   /*         0x30 =   2,400 BPS */
  42.  outportb(PORT1 + 1 , 0x00);  /* Set Baud rate - Divisor Latch High Byte */
  43.  outportb(PORT1 + 3 , 0x03);  /* 8 Bits, No Parity, 1 Stop Bit */
  44.  outportb(PORT1 + 2 , 0xC7);  /* FIFO Control Register */
  45.  outportb(PORT1 + 4 , 0x0B);  /* Turn on DTR, RTS, and OUT2 */
  46.  
  47.  printf("\nSample Comm's Program. Press ESC to quit \n");
  48.  
  49.  do { c = inportb(PORT1 + 5);          /* Check to see if char has been */
  50.                        /* received.                     */
  51.       if (c & 1) {
  52.           ch = inportb(PORT1); /* If so, then get Char          */
  53.           outportb(PORT1, ch);
  54.           printf("%c",ch);
  55.       }    /* Print Char to Screen          */
  56.  
  57.       if (kbhit()){
  58.             ch = getch();         /* If key pressed, get Char */
  59.         outportb(PORT1, ch);
  60.             printf("%c", ch);
  61.             now = time(0);
  62.             while (1 == 1) {
  63.                 if (time(0) - now > TTL) {
  64.                     printf("\n\n\n Raspunsul nu a ajuns se retrimite... [%c] \n\n\n", ch);
  65.                     outportb(PORT1, ch);
  66.                     now = time(0);
  67.                 } else {
  68.                     c = inportb(PORT1 + 5);          /* Check to see if char has been */
  69.                                        /* received.                     */
  70.                    if (c & 1) {
  71.                        char ch2 = inportb(PORT1); /* If so, then get Char          */
  72.                        if (ch2 == ch) {
  73.                             printf("\n\n\n Raspunsul a ajuns\n\n\n");
  74.                             break;
  75.                        }
  76.                    }
  77.  
  78.                 }
  79.             }
  80.       } /* Send Char to Serial Port */
  81.  
  82.     } while (ch !=27); /* Quit when ESC (ASC 27) is pressed */
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement