本帖最后由 zsp06312222 于 2017-6-28 20:14 编辑
新塘最新的单片机N76E003,配置好时钟串口定时器,就是接受不了DMX512通讯协议的数据。仿真能进中断。
程序如下:(欢迎大侠指点赐教)
void SerialPort0_ISR(void) interrupt 4 //4
{
UINT8 rece_data;
if(RI)
{ /* if reception occur */
clr_RI; /* clear reception flag for next reception */
if(RB8==0) //RB8
{
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--;
}
}
}
}
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; //
/*0x70*/
SCON = 0x70; //UART0 Mode1,REN=1,TI=1
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;
set_TR1;
set_RB8; //This bit is for setting the stop bit 2 high/low status
set_ES; //enable UART interrupt
set_EA; //enable global interrupt
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
不知道我的配置有问题没:串口0模式3 定时器1模式2
void InitialUART0_Timer1(UINT32 u32Baudrate) //SMOD = 1
{
P05_PushPull_Mode; //P05 ÍÆÍìÊä³ö TR
P06_Quasi_Mode; //Setting UART pin as Quasi mode for transmit
P07_Quasi_Mode; //Setting UART pin as Quasi mode for transmit
clr_UART0PX; //clr_UART0PX AUXR1 &= ~SET_BIT2
P06=1;P07=1; //
TIMER1_MODE2_ENABLE; //
clr_SMOD0; //
SCON = 0xF0; //UART0 Mode1,REN=1,TI=1 //SCON = 0xD0; //0x50
TMOD|= 0x20; //Timer1 Mode2 //
// set_SMOD; //UART0 Double Rate Enable //
clr_SMOD;
set_T1M; //
clr_BRCK; //Serial port 0 baud rate clock source = Timer1 //´®¿Ú0²¨ÌØÂÊʱÖÓԴΪ¶¨Ê±Æ÷1
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 //
}
一周热门 更多>