?? main.c
字號:
/*
see README.txt for details.
chris <cliechti@gmx.net>
*/
#include "hardware.h"
#include <stdlib.h>
#include <stdio.h>
#include "swuart.h"
#include "fll.h"
/**
Delay function.
*/
void delay(unsigned int d) {
while(d--) {
nop();
nop();
}
}
/**
Main function with init an an endless loop that is synced with the
interrupts trough the lowpower mode.
*/
int main(void) {
int reading = 0;
int pos = 0;
char buf[40];
WDTCTL = WDTCTL_INIT; //Init watchdog timer
P1OUT = P1OUT_INIT; //Init output data of port1
P1SEL = P1SEL_INIT; //Select port or module -function on port1
P1DIR = P1DIR_INIT; //Init port direction register of port1
P1IES = P1IES_INIT; //init port interrupts
P1IE = P1IE_INIT;
P2OUT = P2OUT_INIT; //Init output data of port2
P2SEL = P2SEL_INIT; //Select port or module -function on port2
P2DIR = P2DIR_INIT; //Init port direction register of port2
P2IES = P2IES_INIT; //init port interrupts
P2IE = P2IE_INIT;
P2OUT |= LED; //light LED during init
delay(65535); //Wait for watch crystal startup
delay(65535);
fllInit(); //Init FLL to desired frequency using the 32k768 cystal as reference.
P2OUT &= ~LED; //switch off LED
TACTL = TACTL_AFTER_FLL; //setup timer (still stopped)
CCTL0 = CCIE|CAP|CM_2|CCIS_1|SCS; //select P2.2 with UART signal
CCTL1 = 0; //
CCTL2 = 0; //
TACTL |= MC1; //start timer
eint(); //enable interrupts
printf("\r\nSimple Line Editor Ready\r\n"); //say hello
while (1) { //main loop, never ends...
printf("> "); //show prompt
reading = 1;
while (reading) { //loop and read characters
LPM0; //sync, wakeup by irq
switch (rxdata) {
//process RETURN key
case '\r':
//case '\n':
printf("\r\n"); //finish line
buf[pos++] = 0; //to use printf...
printf(":%s\r\n", buf);
reading = 0; //exit read loop
pos = 0; //reset buffer
break;
//backspace
case '\b':
if (pos > 0) { //is there a char to delete?
pos--; //remove it in buffer
putchar('\b'); //go back
putchar(' '); //erase on screen
putchar('\b'); //go back
}
break;
//other characters
default:
//only store characters if buffer has space
if (pos < sizeof(buf)) {
putchar(rxdata); //echo
buf[pos++] = rxdata; //store
}
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -