#include <REG52.H> unsigned char UART_buff; bit New_rec = 0, Send_ed = 1, Money = 0; void main (void) { SCON = 0x50; TMOD = 0x20; TH1 = 0xFD; TL1 = 0xFD; TR1 = 1; ES = 1; EA = 1; while(Money == 0); while(1) { if((New_rec == 1) && (Send_ed == 1)) { UART_buff = SBUF; SBUF = UART_buff; New_rec = 0; Send_ed = 0; } } } void ser_int (void) interrupt 4 { if(RI == 1) { RI = 0; New_rec = 1; UART_buff = SBUF; if(UART_buff == '1') Money = 1; Money = 1; } else { TI = 0; Send_ed = 1; } }
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 = 0; TR1 = 1; } void SendDataByUart1(uint8 dat) { if(!(dat^'a'))TI=1; else { TI=0; SBUF = dat; while(TI == 0); TI = 0; } } void Uart1() interrupt UART1_VECTOR using 1 { ES = 0; Flag=TRUE; if (RI ) { RI = 0; uart1temp = SBUF; } if (TI) { TI = 0; } ES = 1; } void USART1_Tx_Puts(void) { if(Flag) { ES = 0; SendDataByUart1(uart1temp); ES = 1; Flag=FALSE; } } int main() { Uart1_Init(); ES = 1; EA = 1; while(1) { 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 = 0; uint8 j = 0; /*************************************************************************** * Ãè Êö : ´®¿Ú3³õʼ»¯º¯Êý * Èë ²Î : ÎÞ * ·µ»ØÖµ : ÎÞ **************************************************************************/ void Uart3_Init(void) { S3CON |= 0x50; //´®¿Ú3Ñ¡Ôñ¶¨Ê±Æ÷3Ϊ²¨ÌØÂÊ·¢ÉúÆ÷£¬Æô¶¯´®ÐнÓÊÕÆ÷ S3CON &= 0x70; //8λÊý¾Ý,¿É±ä²¨ÌØÂÊ T3H=(65536-(MAIN_Fosc/12/4/BAUD))/256; T3L=(65536-(MAIN_Fosc/12/4/BAUD))%256; 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 1; //Èç¹û×Ö·û´®aÊÇ×Ö·û´®Rec_Buf3µÄ×Ó´® else return 0; //Èç¹û×Ö·û´®a²»ÊÇ×Ö·û´®Rec_Buf3µÄ×Ó´® } /************************************** ¹¦ÄÜÃèÊö£ºÇå³ý»º´æÄÚÈݺ¯Êý Èë¿Ú²ÎÊý£ºÎÞ ·µ»ØÖµ£ºÎÞ ***************************************/ void CLR_Buf3(void) { uint8 k; for(k=0;k<Buf_Max;k++) //½«´®¿Ú3»º´æÊý×éµÄÖµ¶¼ÇåΪÁã { Rec_Buf3[k] = 0; } i = 0; } /*************************************************************************** * Ãè Êö : ´®¿Ú3ÖжϷþÎñº¯Êý * Èë ²Î : ÎÞ * ·µ»ØÖµ : ÎÞ **************************************************************************/ void Uart3() interrupt UART3_VECTOR using 1 { 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 = 0; } } if (S3CON & S3TI) //ÔÚֹͣλ¿ªÊ¼·¢ËÍʱ£¬¸ÃλÖÃ1 { S3CON &= ~S3TI; //Çå³ýS3CON¼Ä´æÆ÷¶ÔÓ¦S3TI루¸Ãλ±ØÐëÈí¼þÇåÁ㣩 } IE2 |= 0x08; // ´®¿Ú3Öжϴò¿ª } /*************************************************************************** * Ãè Êö : ´®¿Ú4³õʼ»¯º¯Êý * Èë ²Î : ÎÞ * ·µ»ØÖµ : ÎÞ **************************************************************************/ void Uart4_Init(void) { S4CON |= 0x50; //´®¿Ú4Ñ¡Ôñ¶¨Ê±Æ÷4Ϊ²¨ÌØÂÊ·¢ÉúÆ÷£¬Æô¶¯´®ÐнÓÊÕÆ÷ S4CON &= 0x70; //8λÊý¾Ý,¿É±ä²¨ÌØÂÊ T4H=(65536-(MAIN_Fosc/12/4/BAUD))/256; T4L=(65536-(MAIN_Fosc/12/4/BAUD))%256; 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 1; //Èç¹û×Ö·û´®aÊÇ×Ö·û´®Rec_Buf4µÄ×Ó´® else return 0; //Èç¹û×Ö·û´®a²»ÊÇ×Ö·û´®Rec_Buf4µÄ×Ó´® } /************************************** ¹¦ÄÜÃèÊö£ºÇå³ý»º´æÄÚÈݺ¯Êý Èë¿Ú²ÎÊý£ºÎÞ ·µ»ØÖµ£ºÎÞ ***************************************/ void CLR_Buf4(void) { unsigned char k; for(k=0;k<Buf_Max;k++) //½«´®¿Ú4»º´æÊý×éµÄÖµ¶¼ÇåΪÁã { Rec_Buf4[k] = 0; } j = 0; } /*************************************************************************** * Ãè Êö : ´®¿Ú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 = 0; } } 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 = 1; // ×ÜÖжϴò¿ª while(1) { if(Hand3("UART3")) // ÊÕµ½´ò¿ªLED1µÄÖ¸Áî { IE2 &= 0xF7; // ´®¿Ú3ÖÐ¶Ï¹Ø±Õ CLR_Buf3(); //½«´®¿Ú3»º´æÊý×éµÄÖµ¶¼ÇåΪÁã //SendStringByUart3("UART3 CHECK OK! "); //´®¿Ú3·¢ËÍ×Ö·û´®UART3 CHECK OK! SendStringByUart4("UART4 CHECK OK! "); IE2 |= 0x08; // ´®¿Ú3Öжϴò¿ª } if(Hand4("UART4")) // ÊÕµ½´ò¿ªLED1µÄÖ¸Áî { IE2 &= 0xEF; // ´®¿Ú4ÖÐ¶Ï¹Ø±Õ CLR_Buf4(); //½«´®¿Ú4»º´æÊý×éµÄÖµ¶¼ÇåΪÁã //SendStringByUart4("UART4 CHECK OK! "); //´®¿Ú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 = 0; uint8 j = 0; uint8 m = 0; uint8 n = 0; 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=1; else { TI=0; S2BUF = dat; while(!(S2CON&S2TI)); //?????????,S2TI?0????? S2CON&=~S2TI; } } void Uart1() interrupt UART1_VECTOR using 1 { ES = 0; Flag=TRUE; if (RI ) { RI = 0; uart1temp = SBUF; } if (TI) { TI = 0; } ES = 1; } void USART1_Tx_Puts(void) { if(Flag) { ES = 0; SendDataByUart1(uart1temp); ES = 1; Flag=FALSE; } } int main() { Uart1_Init(); ES = 1; EA = 1; while(1) { 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 = 0; uint8 j = 0; uint8 m = 0; uint8 n = 0; uint8 td=0; 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=1; td= dat; }//Èç¹ûÊÇaÔò²»·¢ËÍ else if(td=='a') { TI=0; S2BUF = dat; while(!(S2CON&S2TI)); //?????????,S2TI?0????? S2CON&=~S2TI; } else if(td=='b') { TI=0; S3BUF = dat; while(!(S3CON&S3TI)); //?????????,S2TI?0????? S3CON&=~S3TI; } else if(td=='c') { TI=0; S4BUF = dat; while(!(S4CON&S4TI)); //?????????,S2TI?0????? S4CON&=~S4TI; } else { TI=0; SBUF = dat; while(!TI); //?????????,S2TI?0????? TI=0; } } void Uart1() interrupt UART1_VECTOR using 1 { ES = 0; Flag=TRUE; if (RI ) { RI = 0; uart1temp = SBUF; } if (TI) { TI = 0; } ES = 1; } void USART1_Tx_Puts(void) { if(Flag) { ES = 0; SendDataByUart1(uart1temp); ES = 1; Flag=FALSE; } } int main() { Uart1_Init(); ES = 1; EA = 1; while(1) { 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 = 0; uint8 j = 0; uint8 m = 0; uint8 n = 0; uint8 td=0; 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=1; 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 = 0; SendDataByUart1(uart1temp); ES = 1; Flag=FALSE; } } void SendDataByUart12(uint8 dat) { SBUF = dat; while(! TI ); TI=0; } /* void SendDataByUart12(uint8 dat) { SBUF = dat; while(!TI); TI=0; }*/ void USART1_Tx_Puts12(void) { if(Flag) { ES = 0; SendDataByUart12(uart1temp); ES = 1; Flag=FALSE; } } int main() { P1M1 &= 0x3F; P1M0 &= 0x3F; //设置P1.6~P1.7为准双向口 Uart1_Init(); ES = 1; EA = 1; while(1) { USART1_Tx_Puts ( ); if( td=='q') { SBUF=0; break; } } while(1) { USART1_Tx_Puts12 ( ); } } void Uart1() interrupt UART1_VECTOR using 1 { ES = 0; Flag=TRUE; if (RI ) { RI = 0; uart1temp = SBUF; Rec_Buf[i] = uart1temp; //把串口1缓存SBUF寄存器数据依次存放到数组Rec_Buf中 i++; if(i>Buf_Max) //接收数大于定义接收数组最大个数时,覆盖接收数组之前值 { i = 0; } } if (TI) { TI = 0; } ES = 1; }