打印
[牛人杂谈]

N76E003 如何添加使用printf?

[复制链接]
2487|16
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
HXM1593|  楼主 | 2019-3-4 11:20 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
N76E003 第一次使用,编译完例程,想试试printf,不能用,不知道该如何重定义?
沙发
二九结狐六体| | 2019-3-4 13:05 | 只看该作者
等着大佬来啊!

使用特权

评论回复
板凳
jasontu| | 2019-3-4 13:20 | 只看该作者
sample code path:
\N76E003_BSP_Keil_C51_V1.0.6\Sample_Code\UART0_Printf

#include "N76E003.h"
#include "SFR_Macro.h"
#include "Function_define.h"
#include "Common.h"
#include "Delay.h"

char putchar (char c)  {
  while (!TI);
  TI = 0;
  return (SBUF = c);
}


void main (void)
{
                InitialUART0_Timer3(115200);
          TI = 1;                                                                                                                        // Important, use prinft function must set TI=1;
       
                while(1)
                {
                        printf("\n Hello world");
                }

使用特权

评论回复
地板
whtwhtw| | 2019-3-4 14:30 | 只看该作者
楼上正解,需要重定向putchar()函数

使用特权

评论回复
5
HXM1593|  楼主 | 2019-3-4 15:22 | 只看该作者
N76E003重新下个包V1.06,里面有实例

使用特权

评论回复
6
天灵灵地灵灵| | 2019-3-4 16:57 | 只看该作者
楼上正解,BSP里面有的,楼主没下载,自己摸索啊?

使用特权

评论回复
7
天灵灵地灵灵| | 2019-3-4 16:58 | 只看该作者
建议看看BSP里的东西,还有好多头文件,那个串口的操作都在头文件实现了。

使用特权

评论回复
8
玛尼玛尼哄| | 2019-3-4 21:30 | 只看该作者
BSP里有例子,串口0和串口1,以及如何使用重定向。

使用特权

评论回复
9
643757107| | 2019-3-4 21:47 | 只看该作者
看看是不是里面有个弱函数,那个就是修改的。

使用特权

评论回复
10
dongnanxibei| | 2019-3-5 00:13 | 只看该作者
使用的哪个串口、》

使用特权

评论回复
11
稳稳の幸福| | 2019-3-5 22:52 | 只看该作者
/*---------------------------------------------------------------------------------------------------------*/
/*                                                                                                         */
/* Copyright(c) 2017 Nuvoton Technology Corp. All rights reserved.                                         */
/*                                                                                                         */
/*---------------------------------------------------------------------------------------------------------*/

//***********************************************************************************************************
//  Website: http://www.nuvoton.com
//  E-Mail : MicroC-8bit@nuvoton.com
//  Date   : Jan/21/2017
//***********************************************************************************************************

//***********************************************************************************************************
//  File Function: N76E003 GPIO demo code
//***********************************************************************************************************
#include "N76E003.h"
#include "SFR_Macro.h"
#include "Function_define.h"
#include "Common.h"
#include "Delay.h"


unsigned char temp _at_ 0x08;
unsigned char idata itemp _at_ 0x80;
unsigned char xdata xtemp _at_ 0x80;

/*==========================================================================*/
void main (void)
{
                InitialUART0_Timer3(115200);
          TI = 1;                                                                                                                        // Important, use prinft function must set TI=1;
       
                while(1)
                {
                        printf("\n Hello world");
                        Timer0_Delay1ms(300);
                }
}

使用特权

评论回复
12
稳稳の幸福| | 2019-3-5 22:52 | 只看该作者
/***********************************************************************/
/*  This file is part of the C51 Compiler package                      */
/*  Copyright KEIL ELEKTRONIK GmbH 1990 - 2002                         */
/***********************************************************************/
/*                                                                     */
/*  PUTCHAR.C:  This routine is the general character output of C51.   */
/*  You may add this file to a uVision2 project.                       */
/*                                                                     */
/*  To translate this file use C51 with the following invocation:      */
/*     C51 PUTCHAR.C <memory model>                                    */
/*                                                                     */
/*  To link the modified PUTCHAR.OBJ file to your application use the  */
/*  following Lx51 invocation:                                         */
/*     Lx51 <your object file list>, PUTCHAR.OBJ <controls>            */
/*                                                                     */
/***********************************************************************/

//#include <reg51.h>
#include "N76E003.h"

/****************************************************************************/
/* Define putchar send from UART1, printf function will send from P1.6(TXD_1)
/* NOTICE: Since UART1 pin is multi-function with OCD DATA/CLK pin.
/* Suggest download than use run with realchip but not OCD mode.
/****************************************************************************/

/*
* putchar (mini version): outputs charcter only
*/
#if 0
char putchar (char c)
{
                while (!TI_1);  /* wait until transmitter ready */
                TI_1 = 0;
                SBUF_1 = c;      /* output character */
                return (c);
}
#else
char putchar (char c)  {
  while (!TI);
  TI = 0;
  return (SBUF = c);
}
#endif

使用特权

评论回复
13
稳稳の幸福| | 2019-3-5 22:52 | 只看该作者
/*---------------------------------------------------------------------------------------------------------*/
/*                                                                                                         */
/* Copyright(c) 2017 Nuvoton Technology Corp. All rights reserved.                                         */
/*                                                                                                         */
/*---------------------------------------------------------------------------------------------------------*/

//***********************************************************************************************************
//  Website: http://www.nuvoton.com
//  E-Mail : MicroC-8bit@nuvoton.com
//  Date   : Jan/21/2017
//***********************************************************************************************************

//***********************************************************************************************************
//  File Function: N76E003 GPIO demo code
//***********************************************************************************************************
#include "N76E003.h"
#include "SFR_Macro.h"
#include "Function_define.h"
#include "Common.h"
#include "Delay.h"


unsigned char temp _at_ 0x08;
unsigned char idata itemp _at_ 0x80;
unsigned char xdata xtemp _at_ 0x80;

/*==========================================================================*/
void main (void)
{
                InitialUART1_Timer3(115200);
                TI_1 = 1;
                while(1)
                {
                        printf("\n hello world");
                        Timer0_Delay1ms(300);
                }
}

使用特权

评论回复
14
稳稳の幸福| | 2019-3-5 22:53 | 只看该作者
/***********************************************************************/
/*  This file is part of the C51 Compiler package                      */
/*  Copyright KEIL ELEKTRONIK GmbH 1990 - 2002                         */
/***********************************************************************/
/*                                                                     */
/*  PUTCHAR.C:  This routine is the general character output of C51.   */
/*  You may add this file to a uVision2 project.                       */
/*                                                                     */
/*  To translate this file use C51 with the following invocation:      */
/*     C51 PUTCHAR.C <memory model>                                    */
/*                                                                     */
/*  To link the modified PUTCHAR.OBJ file to your application use the  */
/*  following Lx51 invocation:                                         */
/*     Lx51 <your object file list>, PUTCHAR.OBJ <controls>            */
/*                                                                     */
/***********************************************************************/

//#include <reg51.h>
#include "N76E003.h"

/****************************************************************************/
/* Define putchar send from UART1, printf function will send from P1.6(TXD_1)
/* NOTICE: Since UART1 pin is multi-function with OCD DATA/CLK pin.
/* Suggest download than use run with realchip but not OCD mode.
/****************************************************************************/
#if 1
char putchar (char c)                                //for UART1_printf
{
                while (!TI_1);  /* wait until transmitter ready */
                TI_1 = 0;
                SBUF_1 = c;      /* output character */
                return (c);
}
#else
/*
* putchar (mini version): outputs charcter only
*/
char putchar (char c)                          //for UART0_printf
{                               
  while (!TI);
  TI = 0;
  return (SBUF = c);
}

#endif

使用特权

评论回复
15
稳稳の幸福| | 2019-3-5 22:54 | 只看该作者
其实实现这个putchar就可以了。

使用特权

评论回复
16
dongnanxibei| | 2019-4-9 23:04 | 只看该作者
使用重定向的人还真不少。

使用特权

评论回复
17
wanduzi| | 2019-4-10 23:43 | 只看该作者
默认是使用的串口1

使用特权

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

本版积分规则

33

主题

718

帖子

2

粉丝