📄 serial.h
字号:
/*
*********************************************************************************************************
* uC/OS-II
* 实时内核
*
* (c) Copyright 1992-1998, Jean J. Labrosse, Plantation, FL
* 版权所有
*
* MCU-51 专用代码
* KEIL C51大模式编译
*
* 文件名 : SERIAL.H
* 作者 : Jean J. Labrosse
* 改编 : 杨屹 gdtyy@ri.gdt.com.cn 巨龙公司系统集成开发部 2002.09.27
*********************************************************************************************************
*/
//**********************************************************************************
//杨屹 2002/08/20 第一版
//基于中断的串口驱动及显示程序
//联系方法:gdtyy@ri.gdt.com.cn(2003/07/31以前有效)
//**********************************************************************************
//使用方法:(此范例自包含,独立于其他程序。)
// 1.开头加入#include <reg51.h>语句,一定要有。
// 2.初始化串口 InitSerial();//本例中为20MHz晶体,300波特率,模式2初始化
// 3.初始化串口缓冲区 InitSerialBuffer();
// 4.使用显示字节,字,长字,字符,字符串,清屏函数。
//**********************************************************************************
//波特率计算公式:
// TH1=256-(2^SMOD/32*Fosc/12*1/Bound)
// 其中:SMOD=0,1;Fosc=晶体或晶振频率;Bound=波特率
// 本例中,SMOD=0;Fosc=20*10E6;Bound=300,所以TH1=0x52。
//**********************************************************************************
//书写风格:
// 1.带yy前缀标志的函数为杨屹改写的等效C库函数。
// 2.单个单词用小写,yy定义为前缀,不算一个单词。
// 3.多个单词(2个及以上),每个单词首字母大写。(有时变量名第一个单词首字母小写)
// 4.采用内缩风格,每次缩进8个空格。
//**********************************************************************************
#define USE_COM2
void ycc_com_init(unsigned char port,unsigned int baud,unsigned char parity) reentrant;//串口初始化
int ycc_com_sendchar(char port,unsigned char c)reentrant; // 0 is send ok other error
int ycc_com_getchar(char port,unsigned char *c)reentrant; // same as above
int ycc_com_sendbuf(char port,unsigned char * bf,int len)reentrant; //same as above
//extern int ycc_printf( char *format,...);
//void InitSerial() reentrant;//串口初始化
//void InitSerialBuffer(void) reentrant;//串口缓冲区初始化
bit yygetch(unsigned char *ch) reentrant;//从串口缓冲区读1字节数据
void PrintChar(unsigned char ch) reentrant;//显示字符
void PrintCh(unsigned char ch) reentrant;//内部使用,不建议用户使用。
void PrintByte(unsigned char Byte) reentrant;//以十六进制格式显示1个字节数据
void PrintWord(unsigned int Word) reentrant;//以十六进制格式显示1个字数据
void PrintLong(unsigned long LongWord) reentrant;//以十六进制格式显示1个长字数据
void PrintStr(unsigned char *str) reentrant;//显示字符串
void clrscr() reentrant;//清屏
void serial(void) reentrant;//串口中断服务子程序
//收发缓冲区长度
#define LenTxBuf 600 //Don't too small,because it will cause display abnormal.
#define LenRxBuf 600
#define MaxLenStr 100 /*buf[MaxLenStr+1] for '\0'*/
#define TABNum 4 //TAB键移动长度
#ifdef USE_COM2
void InitSerial2() reentrant;//串口初始化
void serial2(void) reentrant;//串口2中断服务子程序
void PrintChar2(unsigned char ch) reentrant;//显示字符
bit yygetch2(unsigned char *ch) reentrant;//从串口缓冲区读1字节数据
//通讯模块引脚定义
#define low 0
sbit LDCD = P1^1; //
sbit LRTS = P1^5; //
sbit LCTS = P1^4; //
/*串口使用timer2作为波特率发生器所得数据
65536-(12000000/32/115200)
65536-(11059200/32/115200)
fosc=11.0592m t2con|=0x34 rcap2h,rcap2l=? baud=?
0xfffd=115200,0xfffa=57600,0xfff7=38400
0xffee=19200,0xffdc=9600,0xffb8=4800,0xff70=2400,0xfee0=1200
0xfdc0=600,0xfb80=300,0xf700=150,0xee00=75,0xe500=50,0xe200=45
fosc=22.1184m t2con|=0x34 rcap2h,rcap2l=? baud=?
0xfffd=230400,0xfffa=115200,0xfff4=57600,0xffee=38400
0xffdc=19200,0xffb8=9600,0xff70=4800,0xfee0=2400,0xfdc0=1200
0xfb80=600,0xf700=300,0xee00=150,0xdc00=75,0xca00=50,0xc400=45*/
//#define LOWBPS 0xd9
#define LOWBPS 0xdc //11.0592M
#define HIGHBPS 0xff
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -