Serial Communication
...................................................................................................................................

#pragma SMALL DB OE
#include <reg51.h>

unsigned char ReceiveSerial() {

       unsigned char c;

       TMOD = 0x20;        /* configure timer for the correct baud rate */
        TH1 = 0xe6;     /* 1200 bps for 12 MHz clock */
        TCON = 0x00;    /* Set timer to not running */

       SCON = 0x50;    /* Set Serial IO to receive and normal mode */
       TR1 = 1;        /* start timer to Receive */        
       while( (SCON & 0x01) == 0 ) /* wait for receive data */;
       c = SBUF;
       return c;
}

void SendSerial(unsigned char c) {

        /* initialize..set values for TMOD, TH1 and TCON */
        /* set the Tx interrupt in SCON to indicate sending data */
        /* start timer */
        /* write character to SBUF */
        /* wait for completion of sent data */
}

void main(void) {

       unsigned char c;

       while( 1 ) {

           /* Use ReceiveSerial to read in a character 'c' */
           /* Do some computation on 'c' */
           /* Send the result using SendSerial() */
        }
}
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
Click here to Download the Program...
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.



· Home
· 8051 Forum
· Active Topics
· 8051 Free Projects
· Blog
· Top 10
· Datasheets
· Electronic Tutorials
· Electronic Projects
· 8051 Tutorials
· 8051 Course
· 8051 Code Library
· Visual Basic for mC
· 8051 Programmer
· Assembler/IDE
· Products
· Ebooks
· Supporting Tools
· Tag Cloud
· Guest Book
· Contact Me
· Privacy policy

8051 Microcontroller Projects, free ebooks, project codes, AVR Projects, 8051 tutorials, electronic projects, ECE CSE BE final year projects, Embedded systems, AVR codes, embedded technology, LCD Interfacing tutorial,final year project ideas project downloads, engineering projects, Examples projects, 8051 Libraries, 8052, Microcontroller, Microprocessor, 8085, 8051 codes, PCB designing, Project Kits, kit