com_pc-mcu

时间:2023-03-09 09:50:39
com_pc-mcu
#include <REG52.H>  

unsigned char UART_buff;
bit New_rec = , Send_ed = , Money = ;
void main (void)
{
SCON = 0x50;
TMOD = 0x20;
TH1 = 0xFD;
TL1 = 0xFD;
TR1 = ;
ES = ;
EA = ;
while(Money == ); while()
{
if((New_rec == ) && (Send_ed == ))
{
UART_buff = SBUF;
SBUF = UART_buff;
New_rec = ;
Send_ed = ;
}
}
} void ser_int (void) interrupt {
if(RI == )
{
RI = ;
New_rec = ;
UART_buff = SBUF;
if(UART_buff == '') Money = ;
Money = ;
} else
{
TI = ;
Send_ed = ;
} }

2.mcu sends a1234, pc receives 1234


#define MAIN_Fosc        11059200L
#include "15W4KxxS4.H"
#include <intrins.h> #define uint8 unsigned char
#define uint16 unsigned int #define BAUD 9600
#define TM (65536 - (MAIN_Fosc/4/BAUD)) volatile uint8 Flag=FALSE; uint8 uart1temp; void Uart1_Init(void)
{ PCON &= 0x3f;
SCON = 0x50;
AUXR |= 0x40;
AUXR &= 0xfe;
TMOD &= 0x0f;
TMOD |= 0x20;
TL1 = 0xDC;
TH1 = 0xDC;
ET1 = ;
TR1 = ;
} void SendDataByUart1(uint8 dat)
{
if(!(dat^'a'))TI=;
else
{
TI=;
SBUF = dat;
while(TI == );
TI = ;
}
} void Uart1() interrupt UART1_VECTOR using
{
ES = ;
Flag=TRUE;
if (RI )
{
RI = ;
uart1temp = SBUF;
}
if (TI)
{
TI = ;
}
ES = ;
} void USART1_Tx_Puts(void)
{
if(Flag)
{
ES = ;
SendDataByUart1(uart1temp); ES = ;
Flag=FALSE;
}
} int main()
{
Uart1_Init();
ES = ;
EA = ;
while()
{
USART1_Tx_Puts( );
} }

3. mcu uart3 receives string, uart4 sends string.


#define MAIN_Fosc        11059200L    //¶¨ÒåÖ÷ʱÖÓ
#include "15W4KxxS4.H"
#include <intrins.h> // ¼ÓÈë´ËÍ·Îļþºó,¿ÉʹÓÃ_nop_¿âº¯Êý
#include <string.h> // ¼ÓÈë´ËÍ·Îļþºó,¿ÉʹÓÃstrstr¿âº¯Êý #define uint8 unsigned char
#define uint16 unsigned int #define S3RI 0x01
#define S3TI 0x02
#define S4RI 0x01
#define S4TI 0x02 #define BAUD 9600 // ²¨ÌØÂÊ
#define Buf_Max 50 uint8 xdata Rec_Buf3[Buf_Max]; //½ÓÊÕ´®¿Ú3»º´æÊý×é
uint8 xdata Rec_Buf4[Buf_Max]; //½ÓÊÕ´®¿Ú4»º´æÊý×é
uint8 i = ;
uint8 j = ; /***************************************************************************
* Ãè Êö : ´®¿Ú3³õʼ»¯º¯Êý
* Èë ²Î : ÎÞ
* ·µ»ØÖµ : ÎÞ
**************************************************************************/
void Uart3_Init(void)
{
S3CON |= 0x50; //´®¿Ú3Ñ¡Ôñ¶¨Ê±Æ÷3Ϊ²¨ÌØÂÊ·¢ÉúÆ÷£¬Æô¶¯´®ÐнÓÊÕÆ÷
S3CON &= 0x70; //8λÊý¾Ý,¿É±ä²¨ÌØÂÊ T3H=(-(MAIN_Fosc///BAUD))/;
T3L=(-(MAIN_Fosc///BAUD))%; T4T3M |= 0x08; //ÔÊÐí¶¨Ê±Æ÷3ÔËÐÐ
IE2 |= 0x08; // ´®¿Ú3Öжϴò¿ª
IE2 &= 0xDF; // ¹Ø±Õ¶¨Ê±Æ÷3ÖжÏ
} /***************************************************************************
* Ãè Êö : ´®¿Ú3·¢ËÍÊý¾Ýº¯Êý
* Èë ²Î : uint8 Êý¾Ý
* ·µ»ØÖµ : ÎÞ
**************************************************************************/
void SendDataByUart3(uint8 dat)
{
S3BUF = dat; //дÊý¾Ýµ½UARTÊý¾Ý¼Ä´æÆ÷
while(!(S3CON&S3TI)); //ÔÚֹͣλûÓз¢ËÍʱ£¬S3TIΪ0¼´Ò»Ö±µÈ´ý
S3CON&=~S3TI; //Çå³ýS3CON¼Ä´æÆ÷¶ÔÓ¦S3TI루¸Ãλ±ØÐëÈí¼þÇåÁ㣩
} /***************************************************************************
* Ãè Êö : ´®¿Ú3·¢ËÍ×Ö·û´®º¯Êý
* Èë ²Î : ×Ö·û´®
* ·µ»ØÖµ : ÎÞ
**************************************************************************/
void SendStringByUart3(uint8 *s)
{
IE2 &= 0xF7; // ´®¿Ú3ÖжϹرÕ
while (*s) //¼ì²â×Ö·û´®½áÊø±êÖ¾
{
SendDataByUart3(*s++); //·¢Ë͵±Ç°×Ö·û
}
IE2 |= 0x08; // ´®¿Ú3Öжϴò¿ª
} /**************************************
¹¦ÄÜÃèÊö£ºÎÕÊֳɹ¦Óë·ñº¯Êý
Èë¿Ú²ÎÊý£ºuint8 *a
·µ»ØÖµ£ºÎ»
***************************************/
bit Hand3(uint8 *a)
{
if(strstr(Rec_Buf3,a)!=NULL) //ÅжÏ×Ö·û´®aÊÇ·ñÊÇ×Ö·û´®Rec_Buf3µÄ×Ó´®
return ; //Èç¹û×Ö·û´®aÊÇ×Ö·û´®Rec_Buf3µÄ×Ó´®
else
return ; //Èç¹û×Ö·û´®a²»ÊÇ×Ö·û´®Rec_Buf3µÄ×Ó´®
} /**************************************
¹¦ÄÜÃèÊö£ºÇå³ý»º´æÄÚÈݺ¯Êý
Èë¿Ú²ÎÊý£ºÎÞ
·µ»ØÖµ£ºÎÞ
***************************************/
void CLR_Buf3(void)
{
uint8 k;
for(k=;k<Buf_Max;k++) //½«´®¿Ú3»º´æÊý×éµÄÖµ¶¼ÇåΪÁã
{
Rec_Buf3[k] = ;
}
i = ;
} /***************************************************************************
* Ãè Êö : ´®¿Ú3ÖжϷþÎñº¯Êý
* Èë ²Î : ÎÞ
* ·µ»ØÖµ : ÎÞ
**************************************************************************/
void Uart3() interrupt UART3_VECTOR using
{
IE2 &= 0xF7; // ´®¿Ú3ÖжϹرÕ
if (S3CON & S3RI) //´®ÐнÓÊÕµ½Í£Ö¹Î»µÄÖмäʱ¿Ìʱ£¬¸ÃλÖÃ1
{
S3CON &= ~S3RI; //Çå³ýS3CON¼Ä´æÆ÷¶ÔÓ¦S3RI루¸Ãλ±ØÐëÈí¼þÇåÁ㣩
Rec_Buf3[i] = S3BUF; //°Ñ´®¿Ú3»º´æSBUF¼Ä´æÆ÷Êý¾ÝÒÀ´Î´æ·Åµ½Êý×éRec_Buf3ÖÐ
i++;
if(i>Buf_Max) //½ÓÊÕÊý´óÓÚ¶¨Òå½ÓÊÕÊý×é×î´ó¸öÊýʱ£¬¸²¸Ç½ÓÊÕÊý×é֮ǰֵ
{
i = ;
}
}
if (S3CON & S3TI) //ÔÚֹͣλ¿ªÊ¼·¢ËÍʱ£¬¸ÃλÖÃ1
{
S3CON &= ~S3TI; //Çå³ýS3CON¼Ä´æÆ÷¶ÔÓ¦S3TI루¸Ãλ±ØÐëÈí¼þÇåÁ㣩
}
IE2 |= 0x08; // ´®¿Ú3Öжϴò¿ª
} /***************************************************************************
* Ãè Êö : ´®¿Ú4³õʼ»¯º¯Êý
* Èë ²Î : ÎÞ
* ·µ»ØÖµ : ÎÞ
**************************************************************************/
void Uart4_Init(void)
{
S4CON |= 0x50; //´®¿Ú4Ñ¡Ôñ¶¨Ê±Æ÷4Ϊ²¨ÌØÂÊ·¢ÉúÆ÷£¬Æô¶¯´®ÐнÓÊÕÆ÷
S4CON &= 0x70; //8λÊý¾Ý,¿É±ä²¨ÌØÂÊ T4H=(-(MAIN_Fosc///BAUD))/;
T4L=(-(MAIN_Fosc///BAUD))%; T4T3M |= 0x80; //ÔÊÐí¶¨Ê±Æ÷4ÔËÐÐ
IE2 |= 0x10; // ´®¿Ú4Öжϴò¿ª
IE2 &= 0xBF; // ¹Ø±Õ¶¨Ê±Æ÷4ÖжÏ
} /***************************************************************************
* Ãè Êö : ´®¿Ú4·¢ËÍÊý¾Ýº¯Êý
* Èë ²Î : uint8 Êý¾Ý
* ·µ»ØÖµ : ÎÞ
**************************************************************************/
void SendDataByUart4(uint8 dat)
{
S4BUF = dat; //дÊý¾Ýµ½UARTÊý¾Ý¼Ä´æÆ÷
while(!(S4CON&S4TI)); //ÔÚֹͣλûÓз¢ËÍʱ£¬S4TIΪ0¼´Ò»Ö±µÈ´ý
S4CON&=~S4TI; //Çå³ýS4CON¼Ä´æÆ÷¶ÔÓ¦S4TI루¸Ãλ±ØÐëÈí¼þÇåÁ㣩
} /***************************************************************************
* Ãè Êö : ´®¿Ú4·¢ËÍ×Ö·û´®º¯Êý
* Èë ²Î : ×Ö·û´®
* ·µ»ØÖµ : ÎÞ
**************************************************************************/
void SendStringByUart4(char *s)
{
IE2 &= 0xEF; //´®¿Ú4ÖжϹرÕ
while (*s) //¼ì²â×Ö·û´®½áÊø±êÖ¾
{
SendDataByUart4(*s++); //·¢Ë͵±Ç°×Ö·û
}
IE2 |= 0x10; //´®¿Ú4Öжϴò¿ª
} /**************************************
¹¦ÄÜÃèÊö£ºÎÕÊֳɹ¦Óë·ñº¯Êý
Èë¿Ú²ÎÊý£ºunsigned char *a
·µ»ØÖµ£ºÎ»
***************************************/
bit Hand4(unsigned char *a)
{
if(strstr(Rec_Buf4,a)!=NULL) //ÅжÏ×Ö·û´®aÊÇ·ñÊÇ×Ö·û´®Rec_Buf4µÄ×Ó´®
return ; //Èç¹û×Ö·û´®aÊÇ×Ö·û´®Rec_Buf4µÄ×Ó´®
else
return ; //Èç¹û×Ö·û´®a²»ÊÇ×Ö·û´®Rec_Buf4µÄ×Ó´®
} /**************************************
¹¦ÄÜÃèÊö£ºÇå³ý»º´æÄÚÈݺ¯Êý
Èë¿Ú²ÎÊý£ºÎÞ
·µ»ØÖµ£ºÎÞ
***************************************/
void CLR_Buf4(void)
{
unsigned char k;
for(k=;k<Buf_Max;k++) //½«´®¿Ú4»º´æÊý×éµÄÖµ¶¼ÇåΪÁã
{
Rec_Buf4[k] = ;
}
j = ;
} /***************************************************************************
* Ãè Êö : ´®¿Ú4ÖжϷþÎñº¯Êý
* Èë ²Î : ÎÞ
* ·µ»ØÖµ : ÎÞ
**************************************************************************/
void Uart4() interrupt UART4_VECTOR
{
IE2 &= 0xEF; // ´®¿Ú4ÖжϹرÕ
if(S4CON & S4RI) //´®ÐнÓÊÕµ½Í£Ö¹Î»µÄÖмäʱ¿Ìʱ£¬¸ÃλÖÃ1
{
S4CON &= ~S4RI; //Çå³ýS4CON¼Ä´æÆ÷¶ÔÓ¦S4RI루¸Ãλ±ØÐëÈí¼þÇåÁ㣩
Rec_Buf4[j] = S4BUF; //°Ñ´®¿Ú4»º´æSBUF¼Ä´æÆ÷Êý¾ÝÒÀ´Î´æ·Åµ½Êý×éRec_Buf4ÖÐ
j++;
if(j>Buf_Max) //½ÓÊÕÊý´óÓÚ¶¨Òå½ÓÊÕÊý×é×î´ó¸öÊýʱ£¬¸²¸Ç½ÓÊÕÊý×é֮ǰֵ
{
j = ;
}
}
if(S4CON & S4TI) //ÔÚֹͣλ¿ªÊ¼·¢ËÍʱ£¬¸ÃλÖÃ1
{
S4CON &= ~S4TI; //Çå³ýS4CON¼Ä´æÆ÷¶ÔÓ¦S4TI루¸Ãλ±ØÐëÈí¼þÇåÁ㣩
}
IE2 |= 0x10; // ´®¿Ú4Öжϴò¿ª
} /***************************************************************************
* Ãè Êö : Ö÷º¯Êý
* Èë ²Î : ÎÞ
* ·µ»ØÖµ : ÎÞ
**************************************************************************/
int main()
{
/////////////////////////////////////////////////
//×¢Òâ: STC15W4K32S4ϵÁеÄоƬ,ÉϵçºóËùÓÐÓëPWMÏà¹ØµÄIO¿Ú¾ùΪ
// ¸ß×è̬,Ð轫ÕâЩ¿ÚÉèÖÃΪ׼˫Ïò¿Ú»òÇ¿ÍÆÍìģʽ·½¿ÉÕý³£Ê¹ÓÃ
//Ïà¹ØIO: P0.6/P0.7/P1.6/P1.7/P2.1/P2.2
// P2.3/P2.7/P3.7/P4.2/P4.4/P4.5
/////////////////////////////////////////////////
P0M1 &= 0xF0; P0M0 &= 0xF0; //ÉèÖÃP0.0~P0.3Ϊ׼˫Ïò¿Ú Uart3_Init(); // ´®¿Ú3³õʼ»¯
Uart4_Init(); // ´®¿Ú4³õʼ»¯
EA = ; // ×ÜÖжϴò¿ª while()
{
if(Hand3("UART3")) // ÊÕµ½´ò¿ªLED1µÄÖ¸Áî
{
IE2 &= 0xF7; // ´®¿Ú3ÖжϹرÕ
CLR_Buf3(); //½«´®¿Ú3»º´æÊý×éµÄÖµ¶¼ÇåΪÁã
//SendStringByUart3("UART3 CHECK OK!\r\n"); //´®¿Ú3·¢ËÍ×Ö·û´®UART3 CHECK OK!
SendStringByUart4("UART4 CHECK OK!\r\n"); IE2 |= 0x08; // ´®¿Ú3Öжϴò¿ª
}
if(Hand4("UART4")) // ÊÕµ½´ò¿ªLED1µÄÖ¸Áî
{
IE2 &= 0xEF; // ´®¿Ú4ÖжϹرÕ
CLR_Buf4(); //½«´®¿Ú4»º´æÊý×éµÄÖµ¶¼ÇåΪÁã
//SendStringByUart4("UART4 CHECK OK!\r\n"); //´®¿Ú4·¢ËÍ×Ö·û´®UART4 CHECK OK!
IE2 |= 0x10; // ´®¿Ú4Öжϴò¿ª
}
}
}

4. mcu uart1 re a1234, uart2 send 1234

//pc send a1234 mcu send 1234
#define MAIN_Fosc 11059200L //?????
#include "15W4KxxS4.H"
#include <intrins.h> // ???????,???_nop_???
#include <string.h> // ???????,???strstr??? #define uint8 unsigned char
#define uint16 unsigned int #define BAUD 9600 // ???
#define TM (65536 - (MAIN_Fosc/4/BAUD))
#define Buf_Max 50
#define S2_S 0x00
#define S2RI 0x01
#define S2TI 0x02
#define S3RI 0x01
#define S3TI 0x02
#define S4RI 0x01
#define S4TI 0x02 uint8 xdata Rec_Buf1[Buf_Max]; //????1????
uint8 xdata Rec_Buf2[Buf_Max]; //????2????
uint8 xdata Rec_Buf3[Buf_Max]; //????3????
uint8 xdata Rec_Buf4[Buf_Max]; //????4????
uint8 i = ;
uint8 j = ;
uint8 m = ;
uint8 n = ; volatile uint8 Flag=FALSE; uint8 uart1temp; void Uart1_Init(void)
{ P_SW1|=0X80; //??P16 P17???1
P_SW1&=0XBF; //??P16 P17???1
P_SW2|=S2_S; //??P46 P47???2
//??1??
PCON &= 0x3f; //??1??????,????????SM0?SM1??
SCON = 0x50; //??1?8???,?????,???????
AUXR |= 0x01; //??1?????2???????
//??2??
S2CON = 0x50; //??2?8???,?????
//??3??
S3CON |= 0x10; //??3???????
S3CON &= 0x30; //??3?????2???????,8???,?????
//??4??
S4CON |= 0x10; //???????
S4CON &= 0x30; //8???,?????,??4?????2??????? AUXR |= 0x04; //???2???Fosc,?1T
T2L = 0xE0; //??????
T2H = 0xFE; //??????
AUXR |= 0x10; //?????2
} void SendDataByUart1(uint8 dat)
{
if(!(dat^'a'))TI=;
else
{
TI=;
S2BUF = dat;
while(!(S2CON&S2TI)); //?????????,S2TI?0?????
S2CON&=~S2TI;
}
} void Uart1() interrupt UART1_VECTOR using
{
ES = ;
Flag=TRUE;
if (RI )
{
RI = ;
uart1temp = SBUF;
}
if (TI)
{
TI = ;
}
ES = ;
} void USART1_Tx_Puts(void)
{
if(Flag)
{
ES = ;
SendDataByUart1(uart1temp); ES = ;
Flag=FALSE;
}
} int main()
{
Uart1_Init();
ES = ;
EA = ;
while()
{
USART1_Tx_Puts( );
} }

5. mcu u1 rec a123,u2 send 1234; u1 re b123, u3 send 123; u1 rec c123, u4 send 123; u1 rec xxx, u1 send xxx;

//pc send a1234 mcu send 1234
#define MAIN_Fosc 11059200L //?????
#include "15W4KxxS4.H"
#include <intrins.h> // ???????,???_nop_???
#include <string.h> // ???????,???strstr??? #define uint8 unsigned char
#define uint16 unsigned int #define BAUD 9600 // ???
#define TM (65536 - (MAIN_Fosc/4/BAUD))
#define Buf_Max 50
#define S2_S 0x00
#define S2RI 0x01
#define S2TI 0x02
#define S3RI 0x01
#define S3TI 0x02
#define S4RI 0x01
#define S4TI 0x02 uint8 xdata Rec_Buf1[Buf_Max]; //????1????
uint8 xdata Rec_Buf2[Buf_Max]; //????2????
uint8 xdata Rec_Buf3[Buf_Max]; //????3????
uint8 xdata Rec_Buf4[Buf_Max]; //????4????
uint8 i = ;
uint8 j = ;
uint8 m = ;
uint8 n = ;
uint8 td=; volatile uint8 Flag=FALSE; uint8 uart1temp; void Uart1_Init(void)
{ P_SW1|=0X80; //??P16 P17???1
P_SW1&=0XBF; //??P16 P17???1
P_SW2|=S2_S; //??P46 P47???2
//??1??
PCON &= 0x3f; //??1??????,????????SM0?SM1??
SCON = 0x50; //??1?8???,?????,???????
AUXR |= 0x01; //??1?????2???????
//??2??
S2CON = 0x50; //??2?8???,?????
//??3??
S3CON |= 0x10; //??3???????
S3CON &= 0x30; //??3?????2???????,8???,?????
//??4??
S4CON |= 0x10; //???????
S4CON &= 0x30; //8???,?????,??4?????2??????? AUXR |= 0x04; //???2???Fosc,?1T
T2L = 0xE0; //??????
T2H = 0xFE; //??????
AUXR |= 0x10; //?????2
} void SendDataByUart1(uint8 dat)
{ if(!(dat^'a')|!(dat^'b')|!(dat^'c')){TI=; td= dat; }//Èç¹ûÊÇaÔò²»·¢ËÍ
else if(td=='a')
{ TI=;
S2BUF = dat;
while(!(S2CON&S2TI)); //?????????,S2TI?0?????
S2CON&=~S2TI;
} else if(td=='b')
{
TI=;
S3BUF = dat;
while(!(S3CON&S3TI)); //?????????,S2TI?0?????
S3CON&=~S3TI;
}
else if(td=='c')
{
TI=;
S4BUF = dat;
while(!(S4CON&S4TI)); //?????????,S2TI?0?????
S4CON&=~S4TI;
}
else
{
TI=;
SBUF = dat;
while(!TI); //?????????,S2TI?0?????
TI=;
} } void Uart1() interrupt UART1_VECTOR using
{
ES = ;
Flag=TRUE;
if (RI )
{
RI = ;
uart1temp = SBUF;
}
if (TI)
{
TI = ;
}
ES = ;
} void USART1_Tx_Puts(void)
{
if(Flag)
{
ES = ;
SendDataByUart1(uart1temp); ES = ;
Flag=FALSE;
}
} int main()
{
Uart1_Init();
ES = ;
EA = ;
while()
{
USART1_Tx_Puts( );
} }

6.  ...5, u4 rec q, exit loop, enter new function

//pc send a1234 mcu send 1234
#define MAIN_Fosc 11059200L #define Main_Fosc_KHZ (MAIN_Fosc / 1000)
#include "15W4KxxS4.H"
#include <intrins.h>
#include <string.h> #define uint8 unsigned char
#define uint16 unsigned int #define Buf_Max 50
uint8 data Rec_Buf[Buf_Max];
#define S2_S 0x00
#define S2RI 0x01
#define S2TI 0x02
#define S3RI 0x01
#define S3TI 0x02
#define S4RI 0x01
#define S4TI 0x02 uint8 i = ;
uint8 j = ;
uint8 m = ;
uint8 n = ;
uint8 td=; volatile uint8 Flag=FALSE; uint8 uart1temp; void Uart1_Init(void)
{ P_SW1|=0X80; //串口1在P1.6,P1.7
P_SW1&=0XBF;
// P_SW2|=S2_S; //串口2在P1.0,P1.1
//
// PCON &= 0x3f;
// SCON = 0x50; //?
// AUXR |= 0x01; // T2
//
// S2CON = 0x50; //
//
// S3CON |= 0x10; //
// S3CON &= 0x30; //
//
// S4CON |= 0x10; //
// S4CON &= 0x30; //
//
// AUXR |= 0x04; //
// T2L = 0xE0; //
// T2H = 0xFE; //
// AUXR |= 0x10; // SCON = 0x50;
S2CON = 0x50; //8位数据,可变波特率
S3CON = 0x10; //8位数据,可变波特率
S3CON &= 0xBF; //串口3选择定时器2为波特率发生器
S4CON = 0x10; //8位数据,可变波特率
S4CON &= 0xBF; //串口4选择定时器2为波特率发生器
SCON = 0x50; //8位数据,可变波特率
AUXR |= 0x01; //串口1选择定时器2为波特率发生器
AUXR |= 0x04; //定时器2时钟为Fosc,即1T
T2L = 0xE8; //设定定时初值
T2H = 0xFF; //设定定时初值
AUXR |= 0x10; //启动定时器2 } void SendDataByUart1(uint8 dat)
{
if(!(dat^'a')|!(dat^'b')|!(dat^'c')|!(dat^'q') ){TI=; td= dat; }
else if(td=='a')
{ S2BUF = dat;
while(!(S2CON&S2TI));
S2CON&=~S2TI;
} else if(td=='b')
{
S3BUF = dat;
while(!(S3CON&S3TI));
S3CON&=~S3TI;
} else if (td=='c')
{ S4BUF = dat;
while(!(S4CON&S4TI));
S4CON&=~S4TI; }
} void USART1_Tx_Puts(void)
{
if(Flag)
{
ES = ;
SendDataByUart1(uart1temp); ES = ;
Flag=FALSE;
}
} void SendDataByUart12(uint8 dat)
{
SBUF = dat;
while(! TI );
TI=; } /*
void SendDataByUart12(uint8 dat)
{
SBUF = dat;
while(!TI);
TI=0; }*/
void USART1_Tx_Puts12(void)
{
if(Flag)
{
ES = ;
SendDataByUart12(uart1temp); ES = ;
Flag=FALSE;
}
} int main()
{ P1M1 &= 0x3F; P1M0 &= 0x3F; //设置P1.6~P1.7为准双向口
Uart1_Init();
ES = ;
EA = ; while()
{ USART1_Tx_Puts ( );
if( td=='q')
{
SBUF=;
break;
}
} while()
{ USART1_Tx_Puts12 ( ); } } void Uart1() interrupt UART1_VECTOR using
{
ES = ;
Flag=TRUE;
if (RI )
{
RI = ;
uart1temp = SBUF;
Rec_Buf[i] = uart1temp; //把串口1缓存SBUF寄存器数据依次存放到数组Rec_Buf中
i++;
if(i>Buf_Max) //接收数大于定义接收数组最大个数时,覆盖接收数组之前值
{
i = ;
}
} if (TI)
{
TI = ;
}
ES = ;
}