打印
[技术问答]

N76E616串口

[复制链接]
676|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 | 只看该作者
看起来怪怪的。

使用特权

评论回复
5
643757107| | 2020-5-27 23:24 | 只看该作者
你用的串口1还是0?

使用特权

评论回复
6
gejigeji521| | 2020-5-29 09:56 | 只看该作者
这会是官方例子?

使用特权

评论回复
7
捉虫天师| | 2020-5-29 11:32 | 只看该作者
确认用的哪个串口。

使用特权

评论回复
8
幸福小强| | 2020-5-29 21:06 | 只看该作者
不是用printf吗

使用特权

评论回复
9
小灵通2018| | 2020-5-29 21:26 | 只看该作者
没用过这种,printf重定向看看

使用特权

评论回复
10
huahuagg| | 2020-5-30 12:31 | 只看该作者
没看明白咋回事。

使用特权

评论回复
11
mintspring| | 2020-5-30 19:38 | 只看该作者
/*---------------------------------------------------------------------------------------------------------*/
/*                                                                                                         */
/* Copyright(c) 2015 Nuvoton Technology Corp. All rights reserved.                                         */
/*                                                                                                         */
/*---------------------------------------------------------------------------------------------------------*/

//***********************************************************************************************************
//  Nuvoton Technoledge Corp.
//  Website: http://www.nuvoton.com
//  E-Mail : MicroC-8bit@nuvoton.com
//  Date   : Sep/1/2015
//***********************************************************************************************************

//***********************************************************************************************************
//  File Function: N76E616 UART-0 Mode1 demo code
//***********************************************************************************************************

#include <stdio.h>
#include "N76E616.h"
#include "Version.h"
#include "Typedef.h"
#include "Define.h"
#include "SFR_Macro.h"
#include "Common.h"
#include "Delay.h"

/*
//-------- <<< Use Configuration Wizard in Context Menu >>> ------------------
//
//<e0> System Clock Source Configuration
// <o1> System Clock Source Selection
//      <0=> 2~16MHz    XTAL
//      <1=> 32.768KHz  XTAL
//      <2=> 11.0592MHz Internal
//      <3=> 10KHz      Internal
//      <4=> OSC-In     External
//</e>
//
//<e2> Clock Divider Configuration
//     <o3.0..7>  System Clock Source Devider  <1-255>
//                     <i> Fsys = (System Clock Source) / (2 * Devider)
//</e>
//
//-------- <<< end of configuration section >>> ------------------------------
*/

#define SYS_CLK_EN      0
#define SYS_SEL         2
#define SYS_DIV_EN      0                   //0: Fsys=Fosc, 1: Fsys = Fosc/(2*CKDIV)
#define SYS_DIV         1

#define u8Receive_Buffer_Size 4 // Receive Buffer Size. (0 - 255)
BIT Receive_Get = 0,Transmit_Busy;
UINT8 u8Receive_Buffer_Index = 0;
UINT8 xdata Receive_Buffer[u8Receive_Buffer_Size] = {0}; // Receive_Buffer.
bit BIT_TMP;
/******************************************************************************
* FUNCTION_PURPOSE: Serial interrupt, echo received data.
* FUNCTION_INPUTS : P2.0(RXD) serial input
* FUNCTION_OUTPUTS: P0.3(TXD) serial output
******************************************************************************/
void Serial0_ISR (void) interrupt 4
{
    if (RI == 1)
    {
        if (Receive_Get == 0)                   // If Receive_Buffer Not Full.
        {
            Receive_Buffer[u8Receive_Buffer_Index] = SBUF;
            u8Receive_Buffer_Index++;
            
            if (u8Receive_Buffer_Index == u8Receive_Buffer_Size)
            {
                Receive_Get = 1;
            }
        }
        
        clr_RI;                                 // Clear RI (Receive Interrupt).
    }
    if (TI == 1)
    {
        Transmit_Busy = 0;                      // Mark Transmit Not Busy.
        clr_TI;                                 // Clear TI (Transmit Interrupt).
    }      
}


/*******************************************************************************
* FUNCTION_PURPOSE: Main function
******************************************************************************/
void main (void)
{
    /* Note
       MCU power on system clock is HIRC (11.0592MHz), so Fsys = 11.0592MHz
    */
   
    Set_All_GPIO_Quasi_Mode();                 //Set all GPIO are Quasi Mode
   
    #if DEBUG_PORT == 0
        InitialUART0_Timer1_Type1(9600);            /* 9600 Baud Rate*/
    #elif DEBUG_PORT == 1
        InitialUART1_Timer3(9600);                  /* 9600 Baud Rate*/
    #endif

    //InitialUART0_Timer1_Type1(9600);            //UART0 Baudrate initial,T1M=0,SMOD=0
    //InitialUART0_Timer1_Type2(57600);           //UART0 Baudrate initial,T1M=0,SMOD=1
    //InitialUART0_Timer1_Type3(345600);          //UART0 Baudrate initial,T1M=1,SMOD=0
    //InitialUART0_Timer1_Type4(115200);          //UART0 Baudrate initial,T1M=1,SMOD=1
    //InitialUART0_Timer3_Type5(345600);          //UART0 Baudrate initial,SMOD=0, Prescale=0
    //InitialUART0_Timer3_Type6(691200);          //UART0 Baudrate initial,SMOD=1, Prescale=0
    //InitialUART0_Timer3_Type6(9600);            //UART0 Baudrate initial,SMOD=1, Prescale=0

  /* Change system closk source */  
  #if SYS_CLK_EN == 1
        #if   SYS_SEL == 0
            System_Clock_Select(E_HXTEN);   //Fosc = 2~16MHz XTAL
        #elif SYS_SEL == 1
            System_Clock_Select(E_LXTEN);   //Fosc = 32.768KHz XTAL
        #elif SYS_SEL == 2
            System_Clock_Select(E_HIRCEN);  //Fosc = 11.0592MHz Internal RC
        #elif SYS_SEL == 3
            System_Clock_Select(E_LIRCEN);  //Fosc = 10KHz Internal RC
        #elif SYS_SEL == 4
            System_Clock_Select(E_OSCEN);   //Fosc = OSC-In External OSC
        #endif
  #endif
   
    #if SYS_DIV_EN == 1
        CKDIV = SYS_DIV;                    //Fsys = Fosc / (2* CLKDIV) = Fcpu
    #endif

#if 1
    /* Use this function to check the baudrate */
    while(1)
        Send_Data_To_UART1(0x55);
#else
    {
        UINT8 i;
        while(1)
        {
            /* Get the PC data to Buffer */
            u8Receive_Buffer_Index = 0;
            IE = 0x90;                                  //EA=1, ES=1, UART interrupt and global interrupt enable
            while(Receive_Get == 0);                    //waiting the PC data
            Receive_Get = 0;
            
            /* Send the Buffer data to PC */
            IE = 0;                                     //disable interrupt
            for(i=0;i<u8Receive_Buffer_Size;i++)
            {
                //P2 = Receive_Buffer[i];                 //show receive data to Port2
                Send_Data_To_UART0(Receive_Buffer[i]);     //show receive data to PC
                //Delay1ms(20);
            }
        }
    }
#endif
}

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

69

主题

230

帖子

2

粉丝