aboutsummaryrefslogtreecommitdiffstats
path: root/msp430/main.c
blob: fd0489fcba0e1dcaa089196b42e5c76b25afc58a (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
53
54
55
56
57
#include <msp430.h>

#include "foci.h"

int main()
{
    WDTCTL = WDTPW | WDTHOLD;

    DCOCTL = 0;
    BCSCTL1 = CALBC1_8MHZ;
    DCOCTL = CALDCO_8MHZ;

    P1SEL = BIT1 | BIT2;  // P1.1 = RXD, P1.2=TXD
    P1SEL2 = BIT1 | BIT2; // P1.1 = RXD, P1.2=TXD
    UCA0CTL1 |= UCSSEL_2; // SMCLK
    UCA0BR0 = 208;        // 8MHz 38400
    UCA0BR1 = 0;
    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)
{
    do asm("nop");
    while ((IFG2 & UCA0TXIFG) == 0 || (UCA0STAT & UCBUSY) == UCBUSY);
    UCA0TXBUF = ch;
    while ((UCA0STAT & UCBUSY) == UCBUSY);
}

int foci_getchar(void)
{
    int ch;

    do asm("nop");
    while ((IFG2 & UCA0RXIFG) == 0 || (UCA0STAT & UCBUSY) == UCBUSY);
    ch = UCA0RXBUF;
    do asm("nop");
    while ((UCA0STAT & UCBUSY) == UCBUSY);

    foci_putchar(ch);
    return ch;
}