Microcontroller › 8051 › serial communication in proteus and hyperterminal › i want to do serial
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=’