[DemoCode下载] N76E003的串口1例子

[复制链接]
3748|5
 楼主| yiy 发表于 2017-11-9 21:28 | 显示全部楼层 |阅读模式
  1. /*---------------------------------------------------------------------------------------------------------*/
  2. /*                                                                                                         */
  3. /* Copyright(c) 2015 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/2016
  11. //***********************************************************************************************************

  12. //***********************************************************************************************************
  13. //  File Function: N76E003 UART-0 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.   


 楼主| yiy 发表于 2017-11-9 21:29 | 显示全部楼层
之前没有提供,这次新版本的例子库提供了这个,赶紧来学习吧。有什么需要的提出来,说不定下个版本给你提供呢?
jiekou001 发表于 2017-11-9 21:43 | 显示全部楼层
这种通过预编译的方式,可以让我们看到多种的操作方式啊,不错不错。
yiyigirl2014 发表于 2018-12-30 16:58 | 显示全部楼层
中断接收?
wanduzi 发表于 2018-12-30 19:05 | 显示全部楼层
开发板没有提供串口适配器,还需要我额外弄个。
antusheng 发表于 2018-12-31 19:26 | 显示全部楼层
支持红外串口吗
您需要登录后才可以回帖 登录 | 注册

本版积分规则

yiy

114

主题

1966

帖子

4

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