文档详情

串口发送接收程序模块程序.doc

发布:2017-12-16约7.1千字共7页下载文档
文本预览下载声明
串口发送接收程序模块程序 [日期:2008-09-12 ] [来源:net 作者:佚名] [字体:大 中 小] (投递新闻) /************************************************************************ ;* 公 司: xx ;* 模 块: serial.c ;* 功 能: 串口中断服务程序,仅需做简单调用即可完成串口输入输出的处理; ;* 出入均设有缓冲区,大小可任意设置 ;* 芯 片: AMEGA16 ;* 说 明: 未利用串口发送硬件BUFF ;* 设 计: 李耀峰 ;* 时 间: 2005-11-24 ;* 版 本: V1.0 ;* 记 录: ;************************************************************************/ /************************************************************************ 可供使用的函数名: extern void PutByte(byte c); //放入一个字节到发送缓冲区 extern void PutString(byte *puts); //发送一个定义在程序存储区的字符串到串口 extern void PutBytes(byte *outplace,byte j); //发送一串数据 extern void PutHEX(byte c); //发送一个字节的hex码,分成两个字节发 extern byte GetByte (void); //从接收缓冲区取一个byte extern void SerialInit (word baud); //串口初始化 extern byte inbufsign; //接收缓冲区数据,有数据=1。 #define CR PutString(\r\n) //发送一个回车换行 #define NUL putstring(\0) //发送一个空格 *************************************************************************/ #include iom16V.h #include macros.h #define byte unsigned char #define word unsigned int #define OLEN 20 //串口发送缓冲大小 #define ILEN 20 //串口接收缓冲大小 byte outbuf[OLEN]; //发送缓冲 byte inbuf[ILEN]; //接收数据缓冲 byte *outlast=outbuf; //最后由中断传输出去的字节位置 byte *putlast=outbuf; //最后放入发送缓冲区的字节位置 byte *inlast=inbuf; //最后接收到接收缓冲区的字节位置 byte *getlast=inbuf; //最后从发送缓冲区取走的字节位置 struct data //位定义 { unsigned bit0:1; unsigned bit1:1; unsigned bit2:1; unsigned bit3:1; unsigned bit4:1; unsigned bit5:1; unsigned bit6:1; unsigned bit7:1; }bit_flag; #define outbufsign0 bit_flag.bit0 //缓冲区数据发完标志 发完=0 #define outbufsign bit_flag.bit1 //发送缓冲区非空标志 有=1 #define inbufful bit_flag.bit2 //接收缓冲区满标志 满=1 //#define inbufsign bit_flag.bit3 //接收缓冲区非空标志 有=1 //byte outbufsign0; //缓冲区数据发完标志 发完=0 //byte outbufsign; //发送缓冲区非空标志 有=1 //byte inbufful; //接收缓冲区满标志 满=1 byte inbufsign; //接收缓冲区非空标志 有=1 #define CR PutString(\r\n) //CR=回车换行 #define SPACE PutByte(0x20) //发送一个空格。 #prag
显示全部
相似文档