write complete word instead that single char at once

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hello

I have compiled with success this tutorial that show
how implement software UART

https://www.avrfreaks.net/index.p...

Now I would create a function "Software_UART("HELLO WORD)" that print all at once.

This is my actual main:

int main(void)
{
	char c = 'A';

	dbg_tx_init();

	while(1)
	  {
		dbg_putchar(c);
		if(++c > 'Z') c = 'A';
	  }

	return 0;
}

I would something like

void main(void)
{
  Software_UART('HELLO WORD')
}

whith option to have also carriage return

Thanks in advice

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
void Software_UART(char * str) {
  while (*str) {
     dbg_putchar(*str++);
  }
  dbg_putchar('\n');
}

or similar should do what you want. (the '\n' at the end end if new line - you may want '\r' and then '\n' or perhaps to omit that bit all together?)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

And before you get really confused, you would call that with this:

Software_UART("HELLO WORLD");

What you have written will not compile.

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The subroutine to print a string is usually puts("the string") or printf("the string"); These are c library functions that have been around since c was written in 73 or so. The library functions are summarized in every c book.

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

For the OP the important distinction in C is that the single quote, ', delimits (marks the start and end) a single isolated character. The double quote, ", delimits a full C-string, complete with terminating null character.

Your code does not have to send that null character. The usual scheme is to step through the string until a null is found, then send a line terminator ( CR or LF or both) instead of the null, then stop sending.

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net