|
單片機(jī)用stc15w4k56s4 內(nèi)部振盪 下載 STC 公司範(fàn)例 自己加串口送出 A 字符ˊ 結(jié)果是可以下載程式,沒ˊ有收到串口的字符ˊ, 求ˊˊ助先進(jìn)們.應(yīng)如何ˊ設(shè)置還是我的蕊片壞了 #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; //楷冞數(shù)杅
u8 RX1_Cnt; //諉彶數(shù)杅
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; //壺楷冞疆梓祩
}
}
|
|