ARM Technical Support Knowledge Articles

USING SIO0 AND SIO1 WITH THE DALLAS 320

Applies to: C51 C Compiler

Answer


Information in this article applies to:


QUESTION

Can I use both of the serial ports on the Dallas 320 and Cypress devices?

ANSWER

Yes. However, the serial ports will probably need to be setup to use different baud rates with different timers.

The following example program shows how you can use both serial ports in your program. The putchar and _getkey functions have been rewritten to automatically select the serial port using the sio_port variable.

#include <reg320.h>               /* special function register declarations   */

#include <stdio.h>                /* prototype declarations for I/O functions */


bit sio_port = 0;   /* SIO port to use (0 = SIO0) */

/*------------------------------------------------
------------------------------------------------*/
char putchar (char c)
{
if (sio_port == 0)
  {
  while (!TI);
  TI = 0;
  SBUF0 = c;
  }
else
  {
  while (!TI1);
  TI1 = 0;
  SBUF1 = c;
  }

return (c);
}

/*------------------------------------------------
------------------------------------------------*/
char _getkey (void)
{
char c;

if (sio_port == 0)
  {
  while (!RI);
  c = SBUF0;
  RI = 0;
  }
else
  {
  while (!RI1);
  c = SBUF1;
  RI1 = 0;
  }

return (c);
}

/*------------------------------------------------
------------------------------------------------*/
void main (void) {

/*------------------------------------------------
Setup the serial port 0 for 1200 baud at 12MHz
using timer 2.
------------------------------------------------*/

    SCON0  = 0x50;              /* SCON:  Mode 1, 8-bit UART, enable rcvr */
    T2MOD  = 0x00;              /* T2MOD: Count Up */
    T2CON  = 0x30;              /* T2CON: Use T2 for Baud Rate on SIO 0 */

    TL2    = 0xFF;
    TH2    = 0xFF;

    RCAP2L = 0xC8;              /* RCAP2: Reload value for 1200 @ 12 MHz */
    RCAP2H = 0xFE;              /* 12,000,000 / 2 / 1200 / 16 */

    TR2   = 1;                  /* TR2: T2 Run */
    TI    = 1;                  /* TI:  Set TI to send first char of SIO 0 */

/*------------------------------------------------
Setup the serial port 1 for 300 baud at 12MHz
using timer 1.
------------------------------------------------*/

    SCON1  = 0x50;              /* SCON1: Mode 1, 8-bit UART, enable rcvr */
    TMOD  |= 0x20;              /* TMOD:  Use T1 for Baud Rate on SIO 1 */
    WDCON |= 0x80;              /* SMOD_1: Set Double Baud Rate */

    TH1    = 0x30;              /* 300 baud at 12 MHz */
    TL1    = 0xFF;

    TR1   = 1;                  /* TR1: T1 Run */
    TI1   = 1;                  /* TI1: Set TI1 to send first char of SIO 1 */

/*------------------------------------------------
------------------------------------------------*/
  while (1) {
    char c;

    sio_port = !sio_port;       /* switch ports */
    printf ("Press a key: ");
    c = _getkey ();
    printf ("
You pressed %c
", c);
  }
}

MORE INFORMATION

SEE ALSO

Article last edited on: 2005-08-09 11:04:23

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential