serialcomm.c

来自「This a simple hardware UART test program」· C语言 代码 · 共 55 行

C
55
字号
/**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 + =
减小字号Ctrl + -
显示快捷键?