本帖最后由 zsp06312222 于 2017-6-30 10:04 编辑
串口初始化:
void InitialUART0_Timer1(UINT32 u32Baudrate) //T1M = 1, SMOD = 1
{
P05_PushPull_Mode; //P05
P06_Quasi_Mode; //Setting UART pin as Quasi mode for transmit
P07_Quasi_Mode; //Setting UART pin as Quasi mode for transmit
TIMER1_MODE2_ENABLE;
SCON = 0x70; //UART0 Mode1,REN=1,TI=1 //SCON = 0xD0; //0x50
TMOD |= 0x20; //Timer1 Mode2
set_SMOD; //UART0 Double Rate Enable //
set_T1M;
clr_BRCK; //Serial port 0 baud rate clock source = Timer1 //
TH1 = 256 - (1000000/u32Baudrate+1); /*16 MHz */
clr_ET1; //¹Ø±ÕTimer1ÖжÏ
set_TR1; //ʹÄܶ¨Ê±Æ÷1 TCON
set_RB8; //This bit is for setting the stop bit 2 high/low status, //ÉèÖýÓÊܵĵھÅλÊý¾Ý =1; //SCON
set_ES; //enable UART interrupt //
set_EA; //enable global interrupt //
}
串口中断处理函数:
void SerialPort0_ISR(void) interrupt 4 //4
{
UINT8 rece_data;
if(RI) //´®¿Ú0½ÓÊÜÖжϱêÖ¾
{ /* if reception occur */
clr_RI; /* clear reception flag for next reception */
if(RB8==0) //RB8
{
// if(rece_data==0) //
// {
rec_ok = 1;
dmx_channel = 0;
Adr = Address - 1; //Address = dmx;
// }
Point = 100; //3ms*250
}
else
{
if(rec_ok) //bit rec_ok;
{
if(Adr == 0) //uint Adr,Address;
{
recbuf[dmx_channel] = SBUF; //½ÓÊÜ
dmx_channel ++;
if(dmx_channel > RECCHANNEL) //RECCHANNEL = 2;
{
rec_ok = 0;
dmx_recok = 1; //
}
}
else Adr--;
}
}
}
} |