# 8051 C Serial Stuff

Status
Not open for further replies.

#### ahmedragia21

##### Member
Hi , i'd like to recieve a string for example an AT phone , like it sends ERROR when i send a wrong AT Command , i wanna display this to an LCD , much like what hyper terminal does , the problem is i only know how to recieve a charachter , tried this code , it works but i wonder how this works lcd_puts(&array[0]);
but it always prints the string with vague charachters .

Code:
// for recieve the string
char Ch;

// Only dealing with received bytes here
// -> Just check the RI flag
i=0;
while(Ch!='\r')
{
Ch=SBUF;
array[i]=Ch;
while(!RI);
RI = 0;  // Clear RT flag
i++;

}

//for print
lcd_puts(&array[0]);

void lcd_puts(char *aaa){
unsigned int i=0;
for(;aaa[i]!=0;i++)lcd_data(aaa[i]);
}

Last edited:

#### colin mac

##### New Member
You can use the scanf function in Keil.

#### naveencali

##### New Member
where U wanna print a string, In PC or in LCD ?
and using what U are sending the String is it Controller?

#### Pommie

##### Well-Known Member
My guess would be that you are not terminating the string.

Try,
Code:
// for recieve the string
char Ch;
// Only dealing with received bytes here
// -> Just check the RI flag
i=0;
while(Ch!='\r')
{
Ch=SBUF;
array[i]=Ch;
while(!RI);
RI = 0;  // Clear RT flag
i++;

}
[COLOR="Red"]array[i]=0;[/COLOR]

//for print
lcd_puts(&array[0]);
Alternatively, change puts to,
Code:
void lcd_puts(char *aaa){
unsigned int i=0;
for(;aaa[i]!=[COLOR="Red"]'\r'[/COLOR];i++)
lcd_data(aaa[i]);
}
Edit, actually I would change the puts to,
Code:
void lcd_puts(char *aaa){
while(*aaa!='\r')
lcd_data(*aaa++);
}
But, only do that if your compiler allows using pointers in this way (and you understand it).

Mike.

Last edited:
Status
Not open for further replies.