[应用方案] N76E003之串口

[复制链接]
1046|10
 楼主| Bruing 发表于 2018-10-30 10:01 | 显示全部楼层 |阅读模式
N76E003之串口.pdf (2.32 MB, 下载次数: 100)
小灵通2018 发表于 2018-10-30 11:07 | 显示全部楼层
这个系列是2个串口还是3个,看看。
dongnanxibei 发表于 2019-4-9 23:12 | 显示全部楼层
看看这个是不是我要找的资料。
zhuomuniao110 发表于 2019-4-11 23:13 | 显示全部楼层
学习一下, 这个串口兼容普通的51吧
zhuotuzi 发表于 2019-4-12 23:39 | 显示全部楼层
  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.   
zhuotuzi 发表于 2019-4-12 23:39 | 显示全部楼层
  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.   
幸福小强 发表于 2019-4-15 23:20 | 显示全部楼层
串口非常棒。
643757107 发表于 2019-4-15 23:42 | 显示全部楼层
单片机最重要的一种通信接口。
玛尼玛尼哄 发表于 2019-4-16 00:28 | 显示全部楼层
最好用的51,没有之一。
jiekou001 发表于 2019-4-16 16:24 | 显示全部楼层
有2个串口?
幸福小强 发表于 2019-4-16 19:09 | 显示全部楼层
含双串口、SPI、I2C、6通道PWM输出
您需要登录后才可以回帖 登录 | 注册

本版积分规则

71

主题

308

帖子

1

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