Table of Contents

1. Simple example

1. Simple example

This very short example can test if the toolchain and the simulator are installed.

Compile / Test Loop

Figure II.1. Compile / Test Loop


#include <io.h>
void wait(unsigned int n)
{
  __asm__ __volatile__ (
                        "1: \n"
			" dec   %[n] \n"      /* 2 cycles */
			" jne   1b \n"        /* 2 cycles */
			: [n] "+r"(n));
}

int main(void)
{
  unsigned char b;

  P5SEL  = 0x00;  // Selector         = 0:GPIO     1:peripheral
  P5DIR  = 0x70;  // Direction        = 0:input    1:output
  P5OUT  = 0x00;

  b = 0x10;
  while (1)
    {
      wait(50000);
      wait(50000);
      wait(50000);
      wait(50000);

      P5OUT = b;
      b <<= 1;
      if (b == 0x80) b = 0x10;
    }
  return 0;
}

The program can be compiled using the following line ...

msp430-gcc -mmcu=msp430x1611 main.c -o test.elf

... and used in the simulator using the next one.

wsim-iclbsn2 --mode=time --modearg=10s --ui test.elf