2 see README.txt for details.
4 original by: chris <cliechti@gmx.net>
6 modified by: Vladimir Burian <buriavl2@fel.cvut.cz>
17 inline uint32_t qcount() {
21 result |= ((uint32_t)QCNTH << 16);
29 void delay(unsigned int d) {
37 Main function with init an an endless loop that is synced with the
38 interrupts trough the lowpower mode.
46 WDTCTL = WDTCTL_INIT; //Init watchdog timer
48 P1OUT = P1OUT_INIT; //Init output data of port1
49 P1SEL = P1SEL_INIT; //Select port or module -function on port1
50 P1DIR = P1DIR_INIT; //Init port direction register of port1
51 P1IES = P1IES_INIT; //init port interrupts
54 P2OUT = P2OUT_INIT; //Init output data of port2
55 P2SEL = P2SEL_INIT; //Select port or module -function on port2
56 P2DIR = P2DIR_INIT; //Init port direction register of port2
57 P2IES = P2IES_INIT; //init port interrupts
61 P3OUT = 0xff; //light LED during init
62 delay(65535); //Wait for watch crystal startup
64 // fllInit(); //Init FLL to desired frequency using the 32k768 cystal as reference.
65 P3OUT = 0x00; //switch off LED
67 TACTL = TACTL_AFTER_FLL; //setup timer (still stopped)
68 CCTL0 = CCIE|CAP|CM_2|CCIS_1|SCS; //select P2.2 with UART signal
71 TACTL |= MC1; //start timer
73 eint(); //enable interrupts
75 printf("\r\n====== openMSP430 in action ======\r\n"); //say hello
76 printf("\r\nSimple Line Editor Ready\r\n"); //say hello
78 printf("\n[QCount = 0x%08lX]\n", qcount());
80 while (1) { //main loop, never ends...
81 printf("> "); //show prompt
83 while (reading) { //loop and read characters
84 LPM0; //sync, wakeup by irq
86 led++; // Some lighting...
90 P3OUT = (0x01 << led);
96 printf("\r\n"); //finish line
97 buf[pos++] = 0; //to use printf...
98 printf(":%s\r\n", buf);
99 reading = 0; //exit read loop
100 pos = 0; //reset buffer
104 if (pos > 0) { //is there a char to delete?
105 pos--; //remove it in buffer
106 putchar('\b'); //go back
107 putchar(' '); //erase on screen
108 putchar('\b'); //go back
113 //only store characters if buffer has space
114 if (pos < sizeof(buf)) {
115 putchar(rxdata); //echo
116 buf[pos++] = rxdata; //store