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 / Replies /  #include #include

 #include #include

|

Microcontroller › 8051 › Problem with serial communication ›  #include #include

March 7, 2012 at 4:21 pm #7277
Julian
Participant

 

#include <reg51.h>
#include <stdio.h>
#define lcd_port P1
 
int j;
unsigned char word;
sbit rs = P3^5;
sbit rw = P3^6;
sbit en = P3^7;
sbit BUT_serial = P0^0;
sbit LED_serial = P2^0;
char morning[]={“Gd morning LeeYJ!”};
 
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(250);
}
 
void lcd_mrg()
{
for (j=0; morning[j]!=’’;j++)
{
  lcd_data(morning[j]);
  delay(100);
}
}
 
void serial()
{
int m;
lcdcmd(0x01);
delay(150);
 
for(m=0; m<=15; m++)
{
while (RI == 0);
word = SBUF;
lcd_data(word);
RI = 0;
}
 
lcdcmd(0xC0);
for(m=0; m<=15; m++)
{
while (RI == 0);
word = SBUF;
lcd_data(word);
RI = 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)
{
lcd_init();
lcd_mrg();
shift_left();
TMOD = 0x20;
TH1 = 0xFD;
SCON = 0x50;
TR1 = 1;
 
while(1)
{ 
if(!BUT_serial)
{
LED_serial = 0;
serial();
if (RI == 0)
{
shift_left();
}
}
 
else 
{
shift_left();
}
 
}
}
 
This is my code. Your help will be much appreciated. 

RSS feed: Recent Posts Recent Posts

  • Portable charger for my mate's new leg October 16, 2026
  • solderless sma screw mounting RF causaliy problem October 15, 2026
  • Almost Very New in PCB / KICAD DESIGN October 15, 2026
  • Delco alternator (12SI) AC-tap - what is the mate to this connector called and where to find it? October 15, 2026
  • Semi-automatic battery handler October 15, 2026

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2026 Arrowfly 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 Arrowfly
Privacy Policy | Advertising

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