This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to rework "printf" function to use for two UARTS in the cygnal's MCU?

Hi,everyone!
A problem here:The cygnal's MCU has two
serial ports,so "printf" function must be reworked.But I don't know how to do it.
Give me a hand!
Thanks a lot!

Parents
  • This is a start on this problem:

    //-----------------------------------------------
    #include "stdio.h"
    
    volatile unsigned char sio_selector = 0;
    
    //-----------------------------------------------
    char putchar (char c)
    {
    if (sio_selector == 0)
      {
      while (!TI_0);  /* wait until transmitter ready */
      TI_0 = 0;
      SBUF0 = c;      /* output character */
      }
    else
      {
      while (!TI_1);  /* wait until transmitter ready */
      TI_1 = 0;
      SBUF1 = c;      /* output character */
      }
    
    return (c);
    }
    
    
    //-----------------------------------------------
    char _getkey (void)
    {
    char c;
    
    if (sio_selector == 0)
      {
      while (!RI_0);  /* wait for a character */
      c = SBUF0;
      RI_0 = 0;       /* clear receive interrupt bit */
      }
    else
      {
      while (!RI_1);  /* wait for a character */
      c = SBUF1;
      RI_1 = 0;       /* clear receive interrupt bit */
      }
    
    return (c);
    }
    
    
    //-----------------------------------------------
    void main (void)
    {
    //Initialize SIO0
    //Initialize SIO1
    
    while (1)
      {
      sio_selector = 0;
      printf ("Serial Port 0\r\n");
    
      sio_selector = 1;
      printf ("Serial Port 1\r\n");
      }
    }
    //-----------------------------------------------

    Of course this is polled and uses the putchar and _getkey functions. You'll have to provide your own code to initialize the serial ports and timers.

    Jon

Reply
  • This is a start on this problem:

    //-----------------------------------------------
    #include "stdio.h"
    
    volatile unsigned char sio_selector = 0;
    
    //-----------------------------------------------
    char putchar (char c)
    {
    if (sio_selector == 0)
      {
      while (!TI_0);  /* wait until transmitter ready */
      TI_0 = 0;
      SBUF0 = c;      /* output character */
      }
    else
      {
      while (!TI_1);  /* wait until transmitter ready */
      TI_1 = 0;
      SBUF1 = c;      /* output character */
      }
    
    return (c);
    }
    
    
    //-----------------------------------------------
    char _getkey (void)
    {
    char c;
    
    if (sio_selector == 0)
      {
      while (!RI_0);  /* wait for a character */
      c = SBUF0;
      RI_0 = 0;       /* clear receive interrupt bit */
      }
    else
      {
      while (!RI_1);  /* wait for a character */
      c = SBUF1;
      RI_1 = 0;       /* clear receive interrupt bit */
      }
    
    return (c);
    }
    
    
    //-----------------------------------------------
    void main (void)
    {
    //Initialize SIO0
    //Initialize SIO1
    
    while (1)
      {
      sio_selector = 0;
      printf ("Serial Port 0\r\n");
    
      sio_selector = 1;
      printf ("Serial Port 1\r\n");
      }
    }
    //-----------------------------------------------

    Of course this is polled and uses the putchar and _getkey functions. You'll have to provide your own code to initialize the serial ports and timers.

    Jon

Children
No data