📄 serialcomm.c
字号:
/**Serial communications module.http://mspgcc.sf.netchris <cliechti@gmx.net>*/#include <string.h>#include <stdio.h>#include "hardware.h"#include "serialComm.h"#include "tasklist.h"unsigned short serRxIndex; //receive positionchar serRxBuf[SERBUFSIZE];/**Handler for serial data (called in RX interrupt from UART).return signals if the buffer contains a complete message.serRxIndex is reset on idle line (after a timeout).*/unsigned short procchar(void) { char character = RXBUF0; P2OUT ^= BIT2; P1OUT = character; switch (character) { case '\r': //ignore CR break; case '\n': serRxBuf[serRxIndex] = '\0'; //null terminate string return TASK_serTask; //start serial handler task on completed line default: if (serRxIndex < (SERBUFSIZE-1)) { //buffer check, account null byte with -1 serRxBuf[serRxIndex++] = character; } else { //ignore character } } return 0;}/**Task which handles incomming packets from the serial port.Its started from the serial receiver interrupt.*/void serTask(void) { printf("len: %d buf: \"%s\"\n", strlen(serRxBuf), serRxBuf); serRxIndex = 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -