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 and lighting of led

Help with serial communication and lighting of led

|

Microcontroller › 8051 › Help with serial communication and lighting of led

  • This topic has 1 reply, 2 voices, and was last updated 7 years, 2 months ago by GANEEV SINGH.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • December 12, 2011 at 2:38 pm #1438
    Julian
    Participant

    Greetings. I’m a beginner is programming 8051. i’m doing a project involving leds, pushbuttons, lcd n serial comm. My led, lcd and pushbuttons work fine but when i combined the serial part, it’s only either the serial is working or the lcd n led are working. I’ve provided my source code below. it’s not a difficult program. pls correct me if there’s any mistake. thx a lot. 

     

     

     

     

    #include <reg51.h>
    #include <stdio.h>
    #define lcd_port P2
     
    int j;
    sbit rs = P0^5;
    sbit rw = P0^6;
    sbit en = P0^7;
    sbit BUT0 = P0^0;
    sbit LED0 = P1^0;
    sbit BUT1 = P0^1;
    sbit LED1 = P1^1;
     
    char bz[]={“Busy”};
    char awy[]={“Not at campus”};
     
    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 shift_left()
    {
    lcdcmd(0x18);
    delay(200);
    }
     
    void lcd_busy()
    {
    for (j=0; bz[j]!=’’;j++)
    {
      lcd_data(bz[j]);
      delay(100);
    }
    }
     
    void lcd_away()
    {
    for (j=0; awy[j]!=’’;j++)
    {
      lcd_data(awy[j]);
      delay(100);
    }
    }
     
    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)
    {
    lcd_init();
     
    while(1)
    {
    if(!BUT0)
    {
    LED0 = 0;
    LED1 = 1;
    lcdcmd(0x01);   
    delay(50);
       lcd_busy();
    }
    else if(!BUT1)
    { 
    LED0 = 1;
    LED1 = 0;
    lcdcmd(0x01);
    delay(50);
       lcd_away();
    }
    else if ( BUT0 && BUT1)            // serial part
    {
    char word;
    TMOD = 0x20;
    TH1 = 0xFD;
    SCON = 0x50;
    TR1 = 1;
    while (RI == 0);
    word = SBUF;
    lcd_data(word);
    RI = 0;
    }
    else
    {
    shift_left();
    }
    }
    }
    February 19, 2018 at 8:52 am #14751
    GANEEV SINGH
    Participant

    Hi

    One thing that I think could be a problem in this code is that Timer1 is being initailized everytime you try to receive a byte. Initialization should be done once throughout the communication process. Try refering this project on EG: https://www.engineersgarage.com/microcontroller/8051projects/interface-serialport-RS232-AT89C51-circuit

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

RSS Recent Posts

  • Electronic board faulty?!? May 12, 2025
  • Is there a Power Bank that can also be charged with electricity? May 12, 2025
  • applying solder paste from a jar May 11, 2025
  • Did a Buyer Kill My Amp? May 11, 2025
  • An Update On Tarrifs May 11, 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