Writing Multiple Bytes via USART

Post your requests and ideas on the future development of mikroC.
Post Reply
Author
Message
pinout
Posts: 54
Joined: 01 Apr 2007 19:09

Writing Multiple Bytes via USART

#1 Post by pinout » 09 Oct 2007 22:57

Hi

In order to write multiple bytes via USART, we have to create a loop and new variables just for that process:

Code: Select all

char i; 
char temp;  
char *ptr;
 
void main() { 
Usart_Init(9600); 

while(1){ 
            ptr = "Hello"; 
            temp = strlen(ptr); 
            for(i=1; i<=temp; i++){ 
            Usart_write(*ptr); 
            ptr++; } 
            
           delay_ms(1000); 
                                    } 
                                      }
Please write some library function that takes care of all that. E.g

Code: Select all

USART_Write_Text("Hello")

Thanks!
pinout

User avatar
srdjan
mikroElektronika team
Posts: 1552
Joined: 28 Dec 2005 12:47
Location: Serbia

Re: Writing Multiple Bytes via USART

#2 Post by srdjan » 10 Oct 2007 11:24

pinout wrote:Hi

In order to write multiple bytes via USART, we have to create a loop and new variables just for that process:

Code: Select all

char i; 
char temp;  
char *ptr;
 
void main() { 
Usart_Init(9600); 

while(1){ 
            ptr = "Hello"; 
            temp = strlen(ptr); 
            for(i=1; i<=temp; i++){ 
            Usart_write(*ptr); 
            ptr++; } 
            
           delay_ms(1000); 
                                    } 
                                      }
Please write some library function that takes care of all that. E.g

Code: Select all

USART_Write_Text("Hello")

Thanks!
pinout
You want us to write what you have already written yourself. I do not see the difference between you writing this routine yourself in your code and using the same routine written by us and placed in the library.
Anyway, here is the code:

Code: Select all

void Usart_Write_Text(char * ptr) {

  while (*ptr)
    Usart_Write(*ptr++);

}

pinout
Posts: 54
Joined: 01 Apr 2007 19:09

#3 Post by pinout » 10 Oct 2007 20:26

Hi

What I wrote was 7 lines of code just for sending text>= 2 characters. Having it all done for you in a library routine makes coding quicker and more legible.

Thanks for the library routine. I get "invalid expression" though. Has this routine just been introduced :. an update is required (I have 7.0.0.3 though)?

pinout

User avatar
srdjan
mikroElektronika team
Posts: 1552
Joined: 28 Dec 2005 12:47
Location: Serbia

#4 Post by srdjan » 11 Oct 2007 08:13

pinout wrote:Hi

Thanks for the library routine. I get "invalid expression" though.
- How did you managed to get invalid expression message? I compile it without problems. Maybe you did not copy it right, maybe you missed to copy some of the brackets.
pinout wrote: Has this routine just been introduced :. an update is required (I have 7.0.0.3 though)?
- The routine was written just yesterday for you. We'll see about adding it to the library. You have the source code now. Also, we did use similar routines within distributed examples.

Post Reply

Return to “mikroC Wish List”