|
本帖最后由 hdd961140543 于 2013-3-3 09:48 编辑
分享一个自己写的串口程序,中断+循环队列接收连续字符串
经过在STC12C5608AD单片机上的测试,连续发送接收都没有出现过误码。
main函数很简单,就是不停的从串口读缓冲队列中读数据,一有数据马上原封不动的发送出去。- Uart1_Init();
- while(1)
- {
- if(UartreadBufNum = ReadUartBuf(UartreadBuf))
- {
- WriteUartBuf(UartreadBuf, UartreadBufNum);
- }
-
- Delay_Ms(20);
- }
复制代码 uart.h- #ifndef __UART_H_
- #define __UART_H_
- #include "STC12C5620AD.h"
- /*********************************************************************************************/
- #define TxBufLen 64 //发送队列长度
- #define RxBufLen 64 //接收队列长度
- /**/
- typedef enum {ERROR = 0, OK = !ERROR} UartStatus;
- typedef unsigned int QeleLoType;
- typedef unsigned char QelemType;
- //队列结果体
- typedef struct
- {
- QelemType *base; //初始化时分配内存空间
- QeleLoType Qout; //队列头指针,队列不空时总指向队列头部
- QeleLoType Qin; //队列尾指针,指向队列队尾的下一个位置,向队列写入新数据就写在这里
- }UartSqqueue;
- /*********************************************************************************************/
- void Uart1_Init(void);
- UartStatus InitTxqu(void);
- UartStatus TxSqIn(QelemType e);
- UartStatus TxSqOut(void);
- UartStatus WriteUartBuf(QelemType *Buf, QeleLoType Num);
- UartStatus InitRxqu(void);
- UartStatus RxSqIn(QelemType e);
- UartStatus RxSqOut(QelemType *RDat);
- QeleLoType ReadUartBuf(QelemType *Buf);
- #endif
复制代码 uart.c上传我写的工程文件
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|