#include #include /**********************************************************************/ switch(Baud) BRGR = F_OSC/BaudR - 16; PCON = 0x80; /**********************************************************************/ } /**********************************************************************/ /**********************************************************************/ /**********************************************************************/
#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;
{
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;
BRGR1 = BRGR/0x100;
BRGR0 = BRGR%0x100;
BRGCON = 0x01;
S1CON = 0x50;
ES1 = 1;
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;
}