Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

8051 C Serial Stuff

Status
Not open for further replies.
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:
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.

Latest threads

New Articles From Microcontroller Tips

Back
Top