[DemoCode下载] ML51的串口0发送接收中断

[复制链接]
926|2
 楼主| jiekou001 发表于 2019-11-29 21:47 | 显示全部楼层 |阅读模式
  1. /*---------------------------------------------------------------------------------------------------------*/
  2. /*                                                                                                         */
  3. /* Copyright(c) 2019 Nuvoton Technology Corp. All rights reserved.                                         */
  4. /*                                                                                                         */
  5. /*---------------------------------------------------------------------------------------------------------*/

  6. //***********************************************************************************************************
  7. //  Website: http://www.nuvoton.com
  8. //  E-Mail : MicroC-8bit@nuvoton.com
  9. //  Date   : Jan/21/2019
  10. //***********************************************************************************************************

  11. /***********************************************************************************************************
  12. //  File Function: ML51 UART0 receive and transmit loop test
  13. /***********************************************************************************************************/
  14. #include "ML51.H"

  15. unsigned char uart_receive_data;
  16. bit receiveFlag,bufOverFlag;

  17. /*************************************************************
  18. //  UART interrupt subroutine.
  19. /**************************************************************/
  20. void Serial_ISR (void) interrupt 4
  21. {
  22.     if (RI)
  23.     {   
  24.       receiveFlag = 1;
  25.       uart_receive_data = SBUF;
  26.       clr_SCON_RI;                                         // Clear RI (Receive Interrupt).
  27.     }
  28.     if (TI)
  29.     {      
  30.         clr_SCON_TI;                                       // Clear TI (Transmit Interrupt).
  31.     }

  32. }


  33. void main(void)
  34. {
  35.   
  36. /* Initial UART0 */
  37.     MFP_P31_UART0_TXD;
  38.     P31_PUSHPULL_MODE;
  39.     MFP_P30_UART0_RXD;
  40.     P30_INPUT_MODE;
  41.     UART_Open(24000000,UART0_Timer3,115200);                 /*condition is: Fsys, UART0 or UART1 , Baudrate  */
  42.     ENABLE_UART0_PRINTF;

  43.     ENABLE_UART0_INTERRUPT;                                  /* Enable UART0 interrupt */
  44.     ENABLE_GLOBAL_INTERRUPT;                                 /* Global interrupt enable */
  45.   
  46. /* while receive data from RXD, send this data to TXD */
  47.   while(1)
  48.   {
  49.     if (receiveFlag)
  50.     {
  51.       receiveFlag = 0;
  52.       clr_IE_ES;
  53.       UART_Send_Data(UART0,uart_receive_data);
  54.       set_IE_ES;
  55.     }
  56.   }
  57. }


天灵灵地灵灵 发表于 2019-11-30 18:10 | 显示全部楼层
代码很熟悉,先启用外设的中断,然后启用全局中断。
新塘初级用户 发表于 2020-7-31 09:39 | 显示全部楼层
楼主,我想问一下,我在使用例程的时候,把main函数里的if(receiveFlag)条件删了,想让他无条件执行,为什么反而不执行了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

147

主题

1518

帖子

2

粉丝
快速回复 在线客服 返回列表 返回顶部