1. You can now buy finished microcontroller project from us, Check out the Store for the complete list of projects.
  2. Need a custom project, Send us some details about your project. So that we can quote the price for it.

Interfacing Serial Port (RS232) with 8051 microcontroller 1.0

Interfacing Serial Port with 8051 microcontroller

  1. Binu
    Program to establish a serial communication link between the PC and the 8051

    Description:
    Serial communication is often used either to control or to receive data from an embedded microprocessor. Serial communication is a form of I/O in which the bits of a byte begin transferred appear one after the other in a timed sequence on a single wire. Serial communication has become the standard for intercomputer communication. In this Project, we'll try to build a serial link between 8051 and PC using RS232.
    [​IMG]
    Using the Serial Port
    8051 provides a transmit channel and a receive channel of serial communication. The transmit data pin (TXD) is specified at P3.1, and the receive data pin (RXD) is at P3.0. The serial signals provided on these pins are TTL signal levels and must be boosted and inverted through a suitable converter(Max232) to comply with RS232 standard.
    All modes are controlled through SCON, the Serial CONtrol register. The SCON bits are defined as SM0, SM1, SM2, REN, TB8, RB8, TI, RI from MSB to LSB. The timers are controlled using TMOD, the Timer MODe register, and TCON, the Timer CONtrol register.

    Use Hyper Terminal at PC side to send/receive Data
    Code (Text):
    1. #pragma SMALL DB OE
    2. #include <reg51.h>
    3.  
    4. unsigned char ReceiveSerial() {
    5.  
    6.       unsigned char c;
    7.  
    8.       TMOD = 0x20;        /* configure timer for the correct baud rate */
    9.         TH1 = 0xe6;    /* 1200 bps for 12 MHz clock */
    10.         TCON = 0x00;    /* Set timer to not running */
    11.  
    12.       SCON = 0x50;    /* Set Serial IO to receive and normal mode */
    13.       TR1 = 1;        /* start timer to Receive */      
    14.       while( (SCON & 0x01) == 0 ) /* wait for receive data */;
    15.       c = SBUF;
    16.       return c;
    17. }
    18.  
    19. void SendSerial(unsigned char c) {
    20.  
    21.         /* initialize..set values for TMOD, TH1 and TCON */
    22.         /* set the Tx interrupt in SCON to indicate sending data */
    23.         /* start timer */
    24.         /* write character to SBUF */
    25.         /* wait for completion of sent data */
    26. }
    27.  
    28. void main(void) {
    29.  
    30.       unsigned char c;
    31.  
    32.       while( 1 ) {
    33.  
    34.           /* Use ReceiveSerial to read in a character 'c' */
    35.           /* Do some computation on 'c' */
    36.           /* Send the result using SendSerial() */
    37.         }
    38. }
    coemplong likes this.
Loading...