ZHAOBAO511 发表于 2024-5-30 08:54:15

请教RTX51TINY 加入串口收发后只能发一次是什么情况?

代码如下,是不是串口中断要单独处理一下?
void job0 (void) _task_ 0
{

      P0M1 = 0;
      P0M0 = 0; //设置为准双向口
      P1M1 = 0;
      P1M0 = 0; //设置为准双向口
      P3M1 = 0;
      P3M0 = 0; //设置为准双向口
      P5n_standard(0xff);      //设置为准双向口
      LED1=0;
      LED2=1;
LED3=1;
      LED4=1;
      LED5=1;
LED6=1;
      LED7=1;
LED8=1;
      
      UART4_config(4);      // 选择波特率, 2: 使用Timer2做波特率, 其它值: 使用Timer4做波特率.
      
      EA = 1;
      youshuju=0;
      
      os_create_task (1);
      os_create_task (2);
      os_create_task (3);
      os_create_task (4);
      os_create_task (5);
      os_create_task (6);
      os_create_task (7);
os_delete_task (0);
      while(1)
      {

                                 os_wait(K_IVL,2,0);
                         LED1=!LED1;

      }
}

void job1 (void) _task_ 1
{

      
      
      //1602显示

      while(1)
      {

                                 LED2=!LED2;
               
                        delay_ms(1);
               
                              if(youshuju==1)//收到数据标志
      {

                send_UART4(0XFF);//加头发送
                send_UART4(RX4_Buffer);

                send_UART4(RX4_Buffer);

                send_UART4(RX4_Buffer);

                send_UART4(RX4_Buffer);
                send_UART4(0XEE);//加尾发送
                youshuju=0;
                RX4_write = 0;
                B_TX4_Busy = 0;                //标志发送忙
      }
      
      
                }      
      
}
void job2 (void) _task_ 2
{

      while(1)
      {
                os_wait(K_IVL,2,0);

                         LED3=!LED3;
               
               
               }

      
}


void send_UART4(u8 dat)
{
      u8 temp = 0;
B_TX4_Busy = 1;                //标志发送忙
      S4BUF = dat; //写数据到UART数据寄存器
      while (!TI4)
                ; //不忙后发送数据
      CLR_TI4();
      B_TX4_Busy = 0;                //标志发送忙
}




/********************* UART4中断函数************************/
void UART4_int (void) interrupt UART4_VECTOR
{
      if(RI4)
      {
                CLR_RI4();
                RX4_Buffer = S4BUF;
                if(++RX4_write >= RX4_Length)      
                        youshuju=1;
                else
                {
                        youshuju=0;
                }
                        //RX4_write = 0;
      }

      if(TI4)
      {
                CLR_TI4();
                B_TX4_Busy = 0;
      }

}
页: [1]
查看完整版本: 请教RTX51TINY 加入串口收发后只能发一次是什么情况?