[技术问答] n76e003串口1中断问题

[复制链接]
 楼主| 卧龙小子 发表于 2019-7-3 11:39 | 显示全部楼层 |阅读模式
n76e003 使用官方代码串口1,中断进不去,我是脱机下用ttl发串口数据让它进入中断看IO取反电平但是没看到电平变化估计没进入中断。请问大家有没有办法
1562123773(1).jpg
643757107 发表于 2019-7-5 09:18 | 显示全部楼层
你中断里没任何实际操作,怎么可以看到效果。
734774645 发表于 2019-7-6 23:09 | 显示全部楼层
楼上说的是,没看到你有翻转。
xinpian101 发表于 2019-7-7 11:45 | 显示全部楼层
没看出来你对哪个IO取反。
xinpian101 发表于 2019-7-7 11:46 | 显示全部楼层
  1. /*---------------------------------------------------------------------------------------------------------*/
  2. /*                                                                                                         */
  3. /* Copyright(c) 2017 Nuvoton Technology Corp. All rights reserved.                                         */
  4. /*                                                                                                         */
  5. /*---------------------------------------------------------------------------------------------------------*/

  6. //***********************************************************************************************************
  7. //  Nuvoton Technoledge Corp.
  8. //  Website: http://www.nuvoton.com
  9. //  E-Mail : MicroC-8bit@nuvoton.com
  10. //  Date   : Apr/21/2017
  11. //***********************************************************************************************************

  12. //***********************************************************************************************************
  13. //  File Function: N76E003 UART-1 Mode1 demo code
  14. //***********************************************************************************************************
  15. #include "N76E003.h"
  16. #include "Common.h"
  17. #include "Delay.h"
  18. #include "SFR_Macro.h"
  19. #include "Function_define.h"

  20. #define BUFFER_SIZE                16
  21. UINT8  UART_BUFFER[BUFFER_SIZE],temp;
  22. UINT16 u16CNT=0,u16CNT1=0;
  23. bit riflag;

  24. /******************************************************************************
  25. * FUNCTION_PURPOSE: Serial port 1 interrupt, echo received data.
  26. * FUNCTION_INPUTS : P0.2(RXD) serial input
  27. * FUNCTION_OUTPUTS: P1.6(TXD) serial output
  28. * Following setting in Common.c
  29. ******************************************************************************/
  30. #if 0
  31. //void InitialUART1_Timer3(UINT32 u32Baudrate) //use timer3 as Baudrate generator
  32. //{
  33. //                P02_Quasi_Mode;                //Setting UART pin as Quasi mode for transmit
  34. //                P16_Quasi_Mode;                //Setting UART pin as Quasi mode for transmit
  35. //       
  36. //          SCON_1 = 0x50;           //UART1 Mode1,REN_1=1,TI_1=1
  37. //    T3CON = 0x08;           //T3PS2=0,T3PS1=0,T3PS0=0(Prescale=1), UART1 in MODE 1
  38. //                clr_BRCK;
  39. //       
  40. //#ifdef FOSC_160000
  41. //                RH3    = HIBYTE(65536 - (1000000/u32Baudrate)-1);                  /*16 MHz */
  42. //                RL3    = LOBYTE(65536 - (1000000/u32Baudrate)-1);                        /*16 MHz */
  43. //#endif
  44. //#ifdef FOSC_166000
  45. //                RH3    = HIBYTE(65536 - (1037500/u32Baudrate));                          /*16.6 MHz */
  46. //                RL3    = LOBYTE(65536 - (1037500/u32Baudrate));                                /*16.6 MHz */
  47. //#endif
  48. //    set_TR3;         //Trigger Timer3
  49. //}
  50. #endif

  51. void SerialPort1_ISR(void) interrupt 15
  52. {
  53.     if (RI_1==1)
  54.     {                                       /* if reception occur */
  55.         clr_RI_1;                             /* clear reception flag for next reception */
  56.         UART_BUFFER[u16CNT] = SBUF_1;
  57.         u16CNT ++;
  58.                                 riflag =1;
  59.     }
  60.     if(TI_1==1)
  61.     {
  62.         clr_TI_1;                             /* if emission occur */
  63.     }
  64. }


  65. /****************************************************************************************************************
  66. * FUNCTION_PURPOSE: Main function
  67.   
  68. !!! N76E003 UART1 pin also occupied by debug pin,
  69. please remove Nu-link or not in debug mode to test UART1 function.

  70. External UART1 connect also disturb debug download

  71. ***************************************************************************************************************/
  72. void main (void)
  73. {
  74.         P12_PushPull_Mode;                // For I/O toggle display
  75.        
  76. #if 0       
  77. //for Simple use UART1 transmit out
  78.                 InitialUART1_Timer3(115200);               
  79.     while(1)
  80.     Send_Data_To_UART1(0x55);
  81.                
  82. #else                       
  83. // For interrupt setting check receive
  84.                 InitialUART1_Timer3(115200);
  85.                 set_ES_1;                                        //For interrupt enable
  86.                 set_EA;
  87.                
  88.                 while(1)
  89.                 {
  90.                         if (riflag)
  91.                         {
  92.                                         P12 = ~ P12;                        //Receive each byte P12 toggle, never work under debug mode
  93.                                         riflag = 0;
  94.                         }
  95.                 }

  96. #endif
  97.                        
  98.        
  99.                
  100. }
  101.   
xinpian101 发表于 2019-7-7 11:47 | 显示全部楼层
给你个例子,你想翻转哪个,直接写入中断函数里就行了。
xinpian101 发表于 2019-7-7 11:47 | 显示全部楼层
仔细看,里面有个标志位,在主函数里判断后再在主函数里翻转。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

11

主题

23

帖子

0

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