标题: 串口設置求助stc 15w4k56 [打印本页]

作者: a0931727149    时间: 2017-1-13 06:11
标题: 串口設置求助stc 15w4k56
單片機用stc15w4k56s4 內部振盪  下載 STC 公司範例 自己加串口送出 A 字符ˊ 結果是可以下載程式,沒ˊ有收到串口的字符ˊ, 求ˊˊ助先進們.應如何ˊ設置還是我的蕊片壞了 #define MAIN_Fosc                22118400L        //隅砱翋奀笘#define        RX1_Lenth                32                        //揹諳諉彶遣喳酗僅
#define        BaudRate1                115200UL        //恁寁疏杻薹


#define        Timer1_Reload        (65536UL -(MAIN_Fosc / 4 / BaudRate1))                //Timer 1 笭蚾硉ㄛ 勤茼300KHZ
#define        Timer2_Reload        (65536UL -(MAIN_Fosc / 4 / BaudRate1))                //Timer 2 笭蚾硉ㄛ 勤茼300KHZ

#include        "STC15Fxxxx.H"


/*************        掛華曹講汒隴        **************/
u8        idata RX1_Buffer[RX1_Lenth];        //諉彶遣喳
u8        TX1_Cnt;        //楷冞數杅
u8        RX1_Cnt;        //諉彶數杅
bit        B_TX1_Busy;        //楷冞疆梓祩


/*************        掛華滲杅汒隴        **************/



/**********************************************/
void main(void)
{
        B_TX1_Busy = 0;
        RX1_Cnt = 0;
        TX1_Cnt = 0;

        S1_8bit();                                //8弇杅擂
        S1_USE_P30P31();                //UART1 妏蚚P30 P31諳        蘇
//          S1_USE_P36P37();                //UART1 妏蚚P36 P37諳
//          S1_USE_P16P17();                //UART1 妏蚚P16 P17諳

/*
        TR1 = 0;                        //疏杻薹妏蚚Timer1莉汜
        AUXR &= ~0x01;                //S1 BRT Use Timer1;
        AUXR |=  (1<<6);        //Timer1 set as 1T mode
        TH1 = (u8)(Timer1_Reload >> 8);
        TL1 = (u8)Timer1_Reload;
        TR1  = 1;
*/

        AUXR &= ~(1<<4);        //Timer stop                疏杻薹妏蚚Timer2莉汜
        AUXR |= 0x01;                //S1 BRT Use Timer2;
        AUXR |=  (1<<2);        //Timer2 set as 1T mode
        TH2 = (u8)(Timer2_Reload >> 8);
        TL2 = (u8)Timer2_Reload;
        AUXR |=  (1<<4);        //Timer run enable

        REN = 1;        //埰勍諉彶
        ES  = 1;        //埰勍笢剿

        EA = 1;                //埰勍擁笢剿
       

B_TX1_Busy=1;
  SBUF =0x41;
while(B_TX1_Busy);


        while (1)
        {
                if(TX1_Cnt != RX1_Cnt)                //彶善徹杅擂
                {
                        if(!B_TX1_Busy)                //楷冞諾玿
                        {
                                B_TX1_Busy = 1;                //梓祩楷冞疆
                                SBUF = RX1_Buffer[TX1_Cnt];        //楷珨跺趼誹
                                if(++TX1_Cnt >= RX1_Lenth)        TX1_Cnt = 0;        //旌轎祛堤揭燴
                        }
                }
        }
}

/********************* UART1笢剿滲杅************************/
void UART1_int (void) interrupt UART1_VECTOR
{
        if(RI)
        {
                RI = 0;
                RX1_Buffer[RX1_Cnt] = SBUF;                //悵湔珨跺趼誹
                if(++RX1_Cnt >= RX1_Lenth)        RX1_Cnt = 0;        //旌轎祛堤揭燴
        }

        if(TI)
        {
                TI = 0;
                B_TX1_Busy = 0;                //壺楷冞疆梓祩
        }
}









作者: ahshmj    时间: 2017-1-13 18:50
注释都乱码了。




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1