?? sci.c
字號:
/*-----------------------------------------------------*
*文件描述:本文件包含了串行通信的4子程序,分別為: *
*(1)SCISend1:串行發(fā)送1字節(jié) *
*(2)SCISendN:串行發(fā)送n字節(jié) *
*(3)SCIRe1:串行接收1字節(jié) *
*(4)SCIReN:串行接收n字節(jié) *
*-------------《嵌入式應(yīng)用技術(shù)基礎(chǔ)教程》--------------*/
//[以下為子程序源代碼]
//[包含頭文件]
#include "SCI.h"
/*SCISend1:串行發(fā)送1個字節(jié)-----------------------------*
*功 能:串行發(fā)送1個字節(jié) *
*參 數(shù):要發(fā)送的數(shù)據(jù) *
*返 回:無 *
*-----------------------------------------------------*/
void SCISend1(unsigned char o)
{//判斷ReStatusR的第SendTestBit位是否為1,是1可以發(fā)送
while(1)
if ((ReSendStatusR & (1<<SendTestBit)) != 0)
{ ReSendDataR=o;
break;}
}
/*SCISendN:串行發(fā)送N個字節(jié)-----------------------------*
*功 能:發(fā)送數(shù)組中的N個字節(jié)數(shù)據(jù) *
*參 數(shù):待發(fā)送的數(shù)據(jù)字節(jié)數(shù)及其要存放的數(shù)組首地址 *
*返 回:無 *
*-----------------------------------------------------*/
void SCISendN(unsigned char n,unsigned char ch[])
{int i;
for(i=0;i<n;i++)
SCISend1(ch[i]);
}
/*SCIRe1:串行收一個字節(jié)數(shù)據(jù)----------------------------*
*功 能:從串行口接收1個字節(jié)的數(shù)據(jù) *
*參 數(shù):標(biāo)志指針p *
*返 回:接收到的數(shù)據(jù)(若接收失敗,返回0xff) *
*說 明:參數(shù)*p帶回接收標(biāo)志=0收到數(shù)據(jù),=1未收到數(shù)據(jù) *
*-----------------------------------------------------*/
unsigned char SCIRe1(unsigned char *p)
{ unsigned int k;
unsigned char i;
//ReStatusR第ReTestBit位為1表示可接收數(shù)據(jù)
for(k=0;k<0xfbbb;k++)
if ((ReSendStatusR & (1<<ReTestBit)) != 0)
{i=ReSendDataR;
*p=0x00;
break;}
if(k>=0xfbbb)
{i=0xff;
*p=0x01;}
return i; //返回接收到的數(shù)據(jù)
}
/*SCIReN:HC08串行接收N個字節(jié)---------------------------*
*功 能:接收N個字節(jié)數(shù)據(jù),并存放在ch數(shù)組中 *
*參 數(shù):待接收的數(shù)據(jù)字節(jié)數(shù)及其存放的數(shù)組首地址 *
*返 回:接收標(biāo)志=0收到數(shù)據(jù),=1未收到數(shù)據(jù) *
*-----------------------------------------------------*/
unsigned char SCIReN(unsigned char n,unsigned char ch[])
{int m;
unsigned char fp;
m=0;
while (m<n)
{
ch[m]=SCIRe1(&fp);
if (fp==1) return 1;
m++;
}
return 0;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -