UTF-16 encoding

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

does anybody how I can encode text into UTF-16 to send out on USART? For example, I want to send the following string in UTF-16:

unsigned char temp[] = "test";

I'm not sure how I should be declaring this to make it 16 bits/character. Thanks for the help.

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

I think it's standard C:

wchar_t temp[] = L"test";

The "trick" being that pre-pended L on the string defintion.

Cliff

Last Edited: Thu. May 31, 2007 - 04:36 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How would I break it out into 1 byte chunks to send to the USART?

Nevermind, i just used memcpy and moved it into an array. Thanks for the help.

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

As far as I know, UTF16 uses 16 bits for each character. But, each 16 bit word can be broken into 8 bit bytes. At the other end, the bytes a assembled, end-to-end and the result is interpreted using the rules of UTF16.

That is all there is to it.

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

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

This is for PORTB, not the UART but this little bit of code seems to do the trick (on my compiler anyway):

#include 
#include 

wchar_t temp[] = L"test";

int main (void)
{
	int i;
	char *p = (char *) &temp;

	for (i=0; i<8; i++) {
		PORTB = *p++;
	}

	while(1) {
	}
}