[技术问答] N76E616串口

[复制链接]
1230|10
 楼主| WUZHIXIONG23 发表于 2020-5-27 09:52 | 显示全部楼层 |阅读模式
官网例程烧录进去串口读不到数据?
    #if DEBUG_PORT == 0
        InitialUART0_Timer1_Type1(9600);            /* 9600 Baud Rate*/
    #elif DEBUG_PORT == 1
        InitialUART1_Timer3(9600);                  /* 9600 Baud Rate*/
    #endif

    Show_FW_Version_Number_To_PC();
jasontu 发表于 2020-5-27 14:36 | 显示全部楼层
检查线是否有接好,可以拿示波器,看波型是否有打出来
zhuomuniao110 发表于 2020-5-27 19:55 | 显示全部楼层
用的什么板子啊。
wanduzi 发表于 2020-5-27 20:44 | 显示全部楼层
看起来怪怪的。
643757107 发表于 2020-5-27 23:24 | 显示全部楼层
你用的串口1还是0?
gejigeji521 发表于 2020-5-29 09:56 | 显示全部楼层
这会是官方例子?
捉虫天师 发表于 2020-5-29 11:32 | 显示全部楼层
确认用的哪个串口。
幸福小强 发表于 2020-5-29 21:06 | 显示全部楼层
不是用printf吗
小灵通2018 发表于 2020-5-29 21:26 | 显示全部楼层
没用过这种,printf重定向看看
huahuagg 发表于 2020-5-30 12:31 | 显示全部楼层
没看明白咋回事。
mintspring 发表于 2020-5-30 19:38 | 显示全部楼层
  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   : Sep/1/2015
  11. //***********************************************************************************************************

  12. //***********************************************************************************************************
  13. //  File Function: N76E616 UART-0 Mode1 demo code
  14. //***********************************************************************************************************

  15. #include <stdio.h>
  16. #include "N76E616.h"
  17. #include "Version.h"
  18. #include "Typedef.h"
  19. #include "Define.h"
  20. #include "SFR_Macro.h"
  21. #include "Common.h"
  22. #include "Delay.h"

  23. /*
  24. //-------- <<< Use Configuration Wizard in Context Menu >>> ------------------
  25. //
  26. //<e0> System Clock Source Configuration
  27. // <o1> System Clock Source Selection
  28. //      <0=> 2~16MHz    XTAL
  29. //      <1=> 32.768KHz  XTAL
  30. //      <2=> 11.0592MHz Internal
  31. //      <3=> 10KHz      Internal
  32. //      <4=> OSC-In     External
  33. //</e>
  34. //
  35. //<e2> Clock Divider Configuration
  36. //     <o3.0..7>  System Clock Source Devider  <1-255>
  37. //                     <i> Fsys = (System Clock Source) / (2 * Devider)
  38. //</e>
  39. //
  40. //-------- <<< end of configuration section >>> ------------------------------
  41. */

  42. #define SYS_CLK_EN      0
  43. #define SYS_SEL         2
  44. #define SYS_DIV_EN      0                   //0: Fsys=Fosc, 1: Fsys = Fosc/(2*CKDIV)
  45. #define SYS_DIV         1

  46. #define u8Receive_Buffer_Size 4 // Receive Buffer Size. (0 - 255)
  47. BIT Receive_Get = 0,Transmit_Busy;
  48. UINT8 u8Receive_Buffer_Index = 0;
  49. UINT8 xdata Receive_Buffer[u8Receive_Buffer_Size] = {0}; // Receive_Buffer.
  50. bit BIT_TMP;
  51. /******************************************************************************
  52. * FUNCTION_PURPOSE: Serial interrupt, echo received data.
  53. * FUNCTION_INPUTS : P2.0(RXD) serial input
  54. * FUNCTION_OUTPUTS: P0.3(TXD) serial output
  55. ******************************************************************************/
  56. void Serial0_ISR (void) interrupt 4
  57. {
  58.     if (RI == 1)
  59.     {
  60.         if (Receive_Get == 0)                   // If Receive_Buffer Not Full.
  61.         {
  62.             Receive_Buffer[u8Receive_Buffer_Index] = SBUF;
  63.             u8Receive_Buffer_Index++;
  64.             
  65.             if (u8Receive_Buffer_Index == u8Receive_Buffer_Size)
  66.             {
  67.                 Receive_Get = 1;
  68.             }
  69.         }
  70.         
  71.         clr_RI;                                 // Clear RI (Receive Interrupt).
  72.     }
  73.     if (TI == 1)
  74.     {
  75.         Transmit_Busy = 0;                      // Mark Transmit Not Busy.
  76.         clr_TI;                                 // Clear TI (Transmit Interrupt).
  77.     }      
  78. }


  79. /*******************************************************************************
  80. * FUNCTION_PURPOSE: Main function
  81. ******************************************************************************/
  82. void main (void)
  83. {
  84.     /* Note
  85.        MCU power on system clock is HIRC (11.0592MHz), so Fsys = 11.0592MHz
  86.     */
  87.    
  88.     Set_All_GPIO_Quasi_Mode();                 //Set all GPIO are Quasi Mode
  89.    
  90.     #if DEBUG_PORT == 0
  91.         InitialUART0_Timer1_Type1(9600);            /* 9600 Baud Rate*/
  92.     #elif DEBUG_PORT == 1
  93.         InitialUART1_Timer3(9600);                  /* 9600 Baud Rate*/
  94.     #endif

  95.     //InitialUART0_Timer1_Type1(9600);            //UART0 Baudrate initial,T1M=0,SMOD=0
  96.     //InitialUART0_Timer1_Type2(57600);           //UART0 Baudrate initial,T1M=0,SMOD=1
  97.     //InitialUART0_Timer1_Type3(345600);          //UART0 Baudrate initial,T1M=1,SMOD=0
  98.     //InitialUART0_Timer1_Type4(115200);          //UART0 Baudrate initial,T1M=1,SMOD=1
  99.     //InitialUART0_Timer3_Type5(345600);          //UART0 Baudrate initial,SMOD=0, Prescale=0
  100.     //InitialUART0_Timer3_Type6(691200);          //UART0 Baudrate initial,SMOD=1, Prescale=0
  101.     //InitialUART0_Timer3_Type6(9600);            //UART0 Baudrate initial,SMOD=1, Prescale=0

  102.   /* Change system closk source */  
  103.   #if SYS_CLK_EN == 1
  104.         #if   SYS_SEL == 0
  105.             System_Clock_Select(E_HXTEN);   //Fosc = 2~16MHz XTAL
  106.         #elif SYS_SEL == 1
  107.             System_Clock_Select(E_LXTEN);   //Fosc = 32.768KHz XTAL
  108.         #elif SYS_SEL == 2
  109.             System_Clock_Select(E_HIRCEN);  //Fosc = 11.0592MHz Internal RC
  110.         #elif SYS_SEL == 3
  111.             System_Clock_Select(E_LIRCEN);  //Fosc = 10KHz Internal RC
  112.         #elif SYS_SEL == 4
  113.             System_Clock_Select(E_OSCEN);   //Fosc = OSC-In External OSC
  114.         #endif
  115.   #endif
  116.    
  117.     #if SYS_DIV_EN == 1
  118.         CKDIV = SYS_DIV;                    //Fsys = Fosc / (2* CLKDIV) = Fcpu
  119.     #endif

  120. #if 1
  121.     /* Use this function to check the baudrate */
  122.     while(1)
  123.         Send_Data_To_UART1(0x55);
  124. #else
  125.     {
  126.         UINT8 i;
  127.         while(1)
  128.         {
  129.             /* Get the PC data to Buffer */
  130.             u8Receive_Buffer_Index = 0;
  131.             IE = 0x90;                                  //EA=1, ES=1, UART interrupt and global interrupt enable
  132.             while(Receive_Get == 0);                    //waiting the PC data
  133.             Receive_Get = 0;
  134.             
  135.             /* Send the Buffer data to PC */
  136.             IE = 0;                                     //disable interrupt
  137.             for(i=0;i<u8Receive_Buffer_Size;i++)
  138.             {
  139.                 //P2 = Receive_Buffer[i];                 //show receive data to Port2
  140.                 Send_Data_To_UART0(Receive_Buffer[i]);     //show receive data to PC
  141.                 //Delay1ms(20);
  142.             }
  143.         }
  144.     }
  145. #endif
  146. }

您需要登录后才可以回帖 登录 | 注册

本版积分规则

70

主题

233

帖子

2

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