日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當前位置:首頁 > 單片機 > 單片機
[導讀]#include #include #include #include "INC\\UART.H" unsigned char xdata BaudRate = 0; unsigned char xdata Uart0_Counter = 0; unsigned char xdata Uart1_Counter = 0; unsigned char xdata Uart0_Buff[

#include

#include
#include
#include "INCUART.H"


unsigned char xdata BaudRate = 0;
unsigned char xdata Uart0_Counter = 0;
unsigned char xdata Uart1_Counter = 0;
unsigned char xdata Uart0_Buff[U0BUF_SIZE];
unsigned char xdata Uart1_Buff[U1BUF_SIZE];

/**********************************************************************/
/*名稱:Uart_Init()
/*說明:串行口初始化程序
/*輸入: BaudRate 串行口波特率
/*輸出:無
/**********************************************************************/
void Uart_Init(unsigned char Baud)
{
unsigned int BaudR;
unsigned long RCAP,BRGR;

switch(Baud)
{
case 0x00 :BaudR = 300;break;
case 0x01 :BaudR = 1200;break;
case 0x02 :BaudR = 2400;break;
case 0x03 :BaudR = 4800;break;
case 0x04 :BaudR = 9600;break;
case 0x05 :BaudR = 19200;break;
default:BaudR = 19200;break;
}
RCAP = 0xFFFF - ((F_OSC/BaudR)/16);
RCAP2H= RCAP/0x100;
RCAP2L= RCAP%0x100;
T2MOD = 0x00;
T2CON = 0x34;
S0CON = 0x50;
ES0 = 1;

BRGR = F_OSC/BaudR - 16;
BRGR1 = BRGR/0x100;
BRGR0 = BRGR%0x100;
BRGCON = 0x01;
S1CON = 0x50;
ES1 = 1;

PCON = 0x80;
EA = 1;
}
/**********************************************************************/
/*名稱:Uart0_ByteRcv()
/*說明:串行口0數(shù)據(jù)讀取中斷程序
/*輸入:無
/*輸出:無
/**********************************************************************/
static void Uart0_ByteRcv(void) interrupt 4 using 3
{
RI_0 = 0;
Uart0_Buff[Uart0_Counter] = S0BUF;
Uart0_Counter++;
if(Uart0_Counter >= U0BUF_SIZE)
{
Uart0_Counter = 0;
memset(Uart0_Buff,0x00,U0BUF_SIZE);
}
}

/**********************************************************************/
/*名稱:Uart0_StrNSend()
/*說明:串行口0指定長度字符串輸出程序
/*輸入:*str 字符串指針
/*length字符串長度
/*輸出:無
/**********************************************************************/
void Uart0_StrNSend(unsigned char *str ,unsigned char length)
{
unsigned char i;
ES0 = 0;
for(i=0;i{
S0BUF = *(str+i);
while(!TI_0);
TI_0 = 0;
}
ES0 = 1;

}

/**********************************************************************/
/*名稱:Uart1_ByteRcv()
/*說明:串行口1數(shù)據(jù)讀取中斷程序
/*輸入:無
/*輸出:無
/**********************************************************************/
static void Uart1_ByteRcv (void) interrupt 10 using 3
{
RI_1 = 0;
Uart1_Buff[Uart1_Counter] = S1BUF;
Uart1_Counter++;
if(Uart1_Counter >= U1BUF_SIZE)
{
Uart1_Counter = 0;
memset(Uart1_Buff,0x00,U1BUF_SIZE);
}
}

/**********************************************************************/
/*名稱:Uart1_ByteSend()
/*說明:串行口1單字符輸出程序
/*輸入: byte要輸出的字符
/*輸出:無
/**********************************************************************/
void Uart1_ByteSend(char byte)
{
ES1 = 0;
S1BUF = byte;
while(!TI_1);
TI_1 = 0;
ES1 = 1;
}

/**********************************************************************/
/*名稱:Uart1_StrNSend()
/*說明:串行口1指定長度字符串輸出程序
/*輸入:*str 字符串指針
/*length字符串長度
/*輸出:無
/**********************************************************************/
void Uart1_StrNSend(unsigned char *str ,unsigned char length)
{
unsigned char i;
ES1 = 0;
for(i=0;i{
S1BUF = *(str+i);
while(!TI_1);
TI_1 = 0;
}
ES1 = 1;
}
/**********************************************************************/
/*名稱:Uart1_StrSend()
/*說明:串行口1字符串輸出程序
/*輸入:*str 字符串指針
/*輸出:無
/**********************************************************************/
void Uart1_StrSend(unsigned char *str)
{
unsigned char i;
ES1 = 0;
for(i=0;i{
S1BUF = *(str+i);
while(!TI_1);
TI_1 = 0;
}
ES1 = 1;
}

本站聲明: 本文章由作者或相關(guān)機構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點,本站亦不保證或承諾內(nèi)容真實性等。需要轉(zhuǎn)載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請及時聯(lián)系本站刪除( 郵箱:macysun@21ic.com )。
換一批
延伸閱讀
關(guān)閉