handyboard.com
Home
FAQ
Docs
Software
Hardware
Get One
Community
Links

Handy Board FAQ Answers: “serial”

How do I read and write to the serial line from an Interactive C program?

It is possible for an IC program to use the serial port. Randy Sargent's instructions at
http://www.ai.mi t.edu/people/rsargent/ic/serialio.html
were written for the 6.270 board, but are directly applicable for the Handy Board running Interactive C.

Then, you can print numbers using (for example) the following printdec() routine:

/*
  printdec.c

  routine to output an integer value
  as a decimal number over the serial line

  requires serialio.c

*/

/* prints number over serial line */
void printdec(int n)
{
  int leading_digit= 0;
  int dig, div;

  if (n == 0)  {
    _printnum(0);
    return;
  }

  if (n < 0)  {
    serial_putchar('-');
    n = 0 - n;
  }

  for (div= 10000; div= div/10; div> 0) {
    dig= n/div;
    n= n - dig*div;
    if (dig || leading_digit) {
      _printnum(dig);
      leading_digit= 1;
    }
  }
}

/* prints digit from 0 to 9 over serial line */
void _printnum(int n)
{
  serial_putchar(n + '0');
}

To start a new line on the serial output, use:

void newline() {
  serial_putchar(10);
  serial_putchar(13);
}

(Last updated 2000-09-27)

 

Back to FAQ Index