aboutsummaryrefslogtreecommitdiffstats
path: root/msp430/main.c
blob: 5c83c2eb78242964611c61f09a8702104d549a3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <msp430.h>

#define FOCI_MSP430
#include "../foci.h"

int main()
{
    WDTCTL = WDTPW | WDTHOLD;

    DCOCTL = 0;
    BCSCTL1 = CALBC1_1MHZ;
    DCOCTL = CALDCO_1MHZ;

    P1SEL = BIT1 | BIT2;  // P1.1 = RXD, P1.2=TXD
    P1SEL2 = BIT1 | BIT2; // P1.1 = RXD, P1.2=TXD
    UCA0CTL1 |= UCSSEL_2; // SMCLK
    UCA0BR0 = 104;        // 1MHz 9600
    UCA0BR1 = 0;          // 1MHz 9600
    UCA0MCTL = UCBRS0;    // Modulation UCBRSx = 1
    UCA0CTL1 &= ~UCSWRST;

    init();

    foci_putchar('o');
    foci_putchar('k');
    foci_putchar('\n');

    for (;;) {
        interpret();
        foci_putchar('o');
        foci_putchar('k');
        foci_putchar('\n');
        //printf(compiling() ? "compiled <%d>\n" : "ok <%d>\n", depth());
    }
}

void foci_putchar(int ch)
{
    while (!(IFG2 & UCA0TXIFG));
    UCA0TXBUF = ch;
}

int foci_getchar(void)
{
    int ch;

    while (!(IFG2 & UCA0RXIFG));
    ch = UCA0RXBUF;
    foci_putchar(ch);
    return ch;
}