how do you transmit more than one character using UART?

rcarvajal:

    void print_integer(int val) {
    int i;

    for(i=100;i>0;i/=10) {
        transmit((val/i)+48);
        val-=(val/i)*i;
    }

}



Maybe there's a better way, but this works for me... Just in case you don't have figured out how to do it. Note that it only prints integers with less than 4 digits. If you need to use bigger numbers you can increment the initial value of i of 100 to 1000 for 4 digits or less and so on.

That’s a good way to do it. But just to clarify for the original poster, 48 is the decimal value for the ACSII character ‘0’ (zero).

for integer to text (ASCII), in C, look at the standard C library, function itoa()

and if you have the memory space, printf()

I needed leading zeros for itoa(), so had to write my own versions:

//----------------------------- my_itoa_4 function --------------------------------//
// returns four digits with leading zeroes if required

void my_itoa_4(int n, char s[])
{
  int i;

  i = 0;
  do 
  {
    s[i++] = n % 10 + '0';
  }
  while ((n /= 10) >= 1);
    if ( i == 3)
      s[i++] = '0';
    else if ( i == 2)
    {
      s[i++] = '0';
      s[i++] = '0';
    }
    else if (i == 1)
    {
      s[i++] = '0';
      s[i++] = '0';
      s[i++] = '0';
    }
   s[i] = '\0'; 
  reverse(s);
}


//----------------------------- my_itoa_2 function --------------------------------//
// returns two digits with a leading zero if required

void my_itoa_2(int n, char s[])
{
  int i;

  i = 0;
  do 
  {
    s[i++] = n % 10 + '0';
  }
  while ((n /= 10) >= 1);
  if ( i == 1)
    s[i++] = '0';
  s[i] = '\0'; 
  reverse(s);
}



//------------------------------ string reverse function -----------------------------//

void reverse(char s[])
{
  int c, i, j;

  for (i = 0, j = strlen(s)-1; i < j; i++ , j--)
  {
    c = s[i];
    s[i] = s[j];
    s[j] = c;
  }
}

Leon

The function i depicted above implements trailing zeros too.