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

📄 serial.c

📁 ucos是一个很不错的嵌入式操作系统
💻 C
字号:
/*
*********************************************************************************************************
*                                                uC/OS-II
*                                          The Real-Time Kernel
*
*                        (c) Copyright 1992-1998, Jean J. Labrosse, Plantation, FL
*                                           All Rights Reserved
*
*                                                  V2.00
*
* File : serial.C
* 功能:	基于中断的串口驱动及显示程序
*********************************************************************************************************
*/

#ifndef	OS_MASTER_FILE
#include "includes.h"
#endif

#include <serial.h>
unsigned char TxBuf[LenTxBuf],RxBuf[LenRxBuf];	//收发缓冲区
unsigned char inTxBuf,outTxBuf,inRxBuf,outRxBuf;//收发缓冲区读写指针
bit TIflag=1;		//发送区空标志 

void InitSerial() reentrant	//串口初始化,9600,8bit,1bit stop
{
TMOD=TMOD&0x0F;
TMOD=TMOD|0x20;
TH1=0xFD;
TL1=0xFD;
SCON=0x50;
PCON=0x00;
TR1=1;
}

void InitSerialBuffer(void) reentrant	//串口缓冲区初始化
{
inTxBuf=outTxBuf=0;
inRxBuf=outRxBuf=0;
ES=1;
}

void serial(void) reentrant 
{
if(TI){
TI=0;
while(inTxBuf!=outTxBuf){
SBUF=TxBuf[outTxBuf];
while(TI==0);
TI=0;
outTxBuf=(outTxBuf+1)%LenTxBuf;
}
TIflag=1;
}
if(RI){
RI=0;
if(((inRxBuf+1)%LenTxBuf)==outRxBuf) return;
RxBuf[inRxBuf]=SBUF;
inRxBuf=(inRxBuf+1)%LenTxBuf;
}
}

void PrintChar(unsigned char ch) reentrant
{
if(((inTxBuf+1)%LenTxBuf)==outTxBuf) return;
TxBuf[inTxBuf]=ch;
inTxBuf=(inTxBuf+1)%LenTxBuf;
if(TIflag){
TIflag=0;
TI=1;
}
}

void PrintStr(unsigned char *str) reentrant
{
int i;
unsigned char ch;
OS_ENTER_CRITICAL();
for(i=0;i<MaxLenStr;i++){
ch=*(str+i);
if(ch=='\0') break;
else if(ch=='\n'){
PrintChar('\n');
PrintChar('\r');
}
else
PrintChar(ch);
}
OS_EXIT_CRITICAL();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -