EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Topics / Help with serial communication

Help with serial communication

|

Microcontroller › 8051 › Help with serial communication

  • This topic has 2 replies, 2 voices, and was last updated 13 years, 6 months ago by Dexter.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • October 29, 2011 at 6:56 pm #1362
    Julian
    Participant

    Hi, 

    I’m trying to do serial communication between 8051 and virtual terminal in Proteus. Whatever that is typed on the terminal, I wish to display it on the LCD. Problem : I can’t type anything on the terminal. Only the cursor is blinking. Below is my code, please correct me if there is any mistakes.

    =================================================

     

    #include <reg51.h>
    #define lcd_port P2
     
    int j;
    sbit rs = P0^5;
    sbit rw = P0^6;
    sbit en = P0^7;
     
    void delay(unsigned int msec)  
    {
    int i,j ;
    for(i=0;i<msec;i++)
    for(j=0;j<200;j++);
    }
     
    void lcdcmd(unsigned char value)
    {
    rs = 0;
    rw = 0;
    lcd_port = value;
    en = 1;
    delay(1);
    en = 0;
    }
     
    void lcd_data(unsigned char display)
    {
    rs = 1;
    rw = 0;
    lcd_port = display;
    en = 1;
    delay(1);
    en = 0;
    }
     
    void lcd_init()
    {
    lcdcmd(0x38);
    delay(150);
    lcdcmd(0x0E);
    delay(150);
    lcdcmd(0x01);
    delay(150);
    lcdcmd(0x06);
    delay(150);
    lcdcmd(0x80);
    delay(150);
    }
     
    void main(void)
    {
    char word;
    lcd_init();
    TMOD = 0x20;
    TH1 = 0xFD;
    SCON = 0x50;
    TR1 = 1;
     
    while(1)
    {
    while (RI == 0);
    word = SBUF;
    lcd_data(word);
    RI = 0;
    }
    }
    ==============================================

     

    Not much experience in programming and first time doing serial comm, help will be much appreciated. Thanking in advance. 

    October 29, 2011 at 7:01 pm #6762
    Julian
    Participant

    Problem solved! 

    November 25, 2011 at 12:46 am #6877
    Dexter
    Participant

    TRY THIS

    MY WORKING CODE

     

     

    #include………

    …………..

    …………

     

    //  SERIAL COMMUNICATION
    void serial_init        (void);                        //initialise serial communication
    unsigned char recv_byte    (void);                        //recieves th ASCII value
    void send_byte            (unsigned char);            //sends ASCII value to PC or microcontroller
    void sendString            (unsigned char *str);
    void enter(void);

     

     

    void main()
    {

    unsigned char A;

    serial_init();
    sendString(“WELCOME TO RS232 COM1”);
    enter();
    sendString(“DEXTER8051”);
    enter();

     

    A=recv_byte()

    …………………

    ………………

    ………………

    }

     

     

    /*SENDING THE ENTER CAMMAND*/
    void enter()
    {
        send_byte(0x0d);       //  <CR>
        send_byte(0x0a);        // <LF>
    }

    /*SERIAL ROUTINES*/
    void serial_init()
    {
        SCON=0x50;                        //mode 1 serial communication
        TMOD=0x20;                        //timer 1 auto reload mode
        TH1=0xfd;                        //9600 baudrate at 11.0592 MHz
        TR1=1;
        EA=1;
        EX0=1;
        IT0=1;
        IP=0x10;
    }
    /* RECIVING BIT FROM PC*/
    unsigned char recv_byte()
    {
        unsigned char c;
        while(!RI);                        //waits till a byte is recieved
        RI = 0;
        c = SBUF;
        return(c);
    }
      /* SENDING BIT TO PC*/
    void send_byte(unsigned char ch)
    {
        TI = 0;
        SBUF = ch;
        while(!TI);
        del_1ms();
    }
    /* SENDING STRING BIT TO PC*/
    void sendString(unsigned char *str)
    {
        while(*str != ‘’)
        send_byte(*str++);
    }

     

  • Author
    Posts
Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • What is correct names for GOOD user friendly circuit drawing program? June 18, 2025
  • Curved lines in PCB design June 18, 2025
  • using a RTC in SF basic June 18, 2025
  • Is AI making embedded software developers more productive? June 18, 2025
  • Why can't I breadboard this oscillator? June 18, 2025

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise