QuakeGod
2024-04-12 5dd1b7fdcc52a43867f924e8d220de8467af372a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#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;    
        
    }
}