⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 serialcomm.c

📁 This a simple hardware UART test program. It receives text lines over the serial port and writes ba
💻 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 + -