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 / i want to do serial

i want to do serial

|

Microcontroller › 8051 › serial communication in proteus and hyperterminal › i want to do serial

August 11, 2012 at 3:29 am #8443
ayushman
Participant

i want to do serial communication from hyperterminal tp 8051 and want to display the text on LCD. all charecters are display correctly bet when i press spacebar the LCD display some garbage value. Is there any solution to to diplay the spacebar correctly on LCD. here is my code

 

 

#include<reg51.h>
sbit rs= P2^0;
sbit rw= P2^1;
sbit en= P2^2;
////////////////////////////////////Delay////////////////////////////////////
void mdelay(unsigned int itime)
{
unsigned int i,j;
for(i=0;i<itime;i++)
for(j=0;j<1275;j++);
}
// / / / / / / / / / / / / / / / / / / / / / / / / / / / / / L   C  D COMMAND////////////////////////////////////
void lcdcmd(unsigned char value)
{
P1=value;
rs=0;
rw=0;
en=1;
mdelay(1);
en=0;
}
// / / / / / / / / / / / / / / / / / / / / / / / / / / / / L   C  D VALUE//////////////////////////////////////
void lcd_data(unsigned char value)
{
P1 = value;
rs = 1;
rw = 0;
en = 1;
mdelay(1);
en = 0;
}
/////STRING LCD////////
void string_lcd(unsigned char *ptr)
{
 unsigned int h=0,j=0;
 while(*ptr)
 {
 h++;
 if(h<15)
 {
 lcd_data(*ptr++);
 }
 if(h>=15)
 {
 lcdcmd(0xC0+j);
 lcd_data(*ptr++);
 j++;
 }
 }
 }
 // / / / / / / / / / / / / / / / / / / / / / / / / / / U  A  R  T INITIALIZATION///////////////////////////////
void uart_init()
{
TMOD=0x20;
TH1=0xFD;
SCON=0x50;
TR1=1;
}
// / / / / / / / / / / / / / / / / / / / / / / / / / / / L   C  D INITIALIZATION//////////////////////////////
void lcd_init()
{
lcdcmd(0x38);
lcdcmd(0x0E);
lcdcmd(0x01);
lcdcmd(0x06);
lcdcmd(0x80);
}
/////////////////////convert HEX  TO ASCII////////////////////////////
unsigned char convertascii(unsigned char temp)
{
if(temp==’ ‘)
{
return(temp+0x20);
}
else if(temp>=0x0a)
{
return(temp+0x80);
}
}
////////////////////////////////////MAIN/////////////////////////////////////
void main()
{
unsigned char str2[40],*ptr,temp1;
unsigned int i=0;
ptr=str2;
uart_init();
lcd_init();
while(SBUF!=0x0D) //Checking if the enter is pressed or not
{
while(RI==0);
RI=0;
temp1=SBUF;
str2=convertascii(temp1);
i++;
}
str2
=’’;
string_lcd(ptr);
while(1);
}
 

 

RSS Recent Posts

  • Fixing board, Easy question HEX SCHMITT July 9, 2025
  • Can I make two inputs from one?? July 9, 2025
  • The Analog Gods Hate Me July 9, 2025
  • How to make string LEDs? July 9, 2025
  • It's Amazing What A Buck And A Quarter.... July 8, 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