#include "STC15F2K60S2.H" void UartInit(void) //115200bps@22.1184MHz { SCON = 0x50; //8λÊý¾Ý,¿É±ä²¨ÌØÂÊ AUXR |= 0x40; //¶¨Ê±Æ÷ʱÖÓ1Tģʽ AUXR &= 0xFE; //´®¿Ú1Ñ¡Ôñ¶¨Ê±Æ÷1Ϊ²¨ÌØÂÊ·¢ÉúÆ÷ TMOD &= 0x0F; //ÉèÖö¨Ê±Æ÷ģʽ TL1 = 0xD0; //ÉèÖö¨Ê±³õʼֵ TH1 = 0xFF; //ÉèÖö¨Ê±³õʼֵ ET1 = 0; //½ûÖ¹¶¨Ê±Æ÷ÖÐ¶Ï TR1 = 1; //¶¨Ê±Æ÷1¿ªÊ¼¼Æʱ } void UART1_Isr() interrupt 4 { if(TI) //Èô´«ÊäÖжϱêÖ¾'TI'±»ÉèÖ㬼´·¢ËÍ»º³åÇøΪ¿ÕÇÒ·¢ËͼĴæÆ÷¿ÉÒÔ½ÓÊÕÐÂÊý¾Ý { TI = 0; //'TI'±»ÇåÁ㣬׼±¸·¢ËÍÏÂÒ»¸ö×Ö½Ú if(sendPosi < sendCount) //Èô·¢ËÍλÖÃСÓÚ·¢ËͼÆÊý { sendPosi++; //ACC = sendBuf[sendPosi]; //TB8 = P; SBUF = sendBuf[sendPosi]; //´®¿Ú·¢ËÍ»º´æ¼Ä´æÆ÷'SBUF'±»Ð´È룬ÒÔ½øÐз¢ËÍ } else { // b485Send = 0; receCount = 0; checkoutError = 0; } } else if(RI) //Èô½ÓÊÕÖжϱêÖ¾'RI'±»ÉèÖ㬼´½ÓÊռĴæÆ÷ÊÕµ½ÐÂÊý¾Ý { RI = 0; receBuf[receCount] = SBUF; //½ÓÊռĴæÆ÷ SBUF µÄÖµ´æ´¢µ½½ÓÊÕ»º³åÇø receBuf[receCount] ÖÐ receCount++; //receCount &= 0x1f; } }