[牛人杂谈] N76E003 如何添加使用printf?

[复制链接]
3190|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()函数
 楼主| HXM1593 发表于 2019-3-4 15:22 | 显示全部楼层
N76E003重新下个包V1.06,里面有实例
天灵灵地灵灵 发表于 2019-3-4 16:57 | 显示全部楼层
楼上正解,BSP里面有的,楼主没下载,自己摸索啊?
天灵灵地灵灵 发表于 2019-3-4 16:58 | 显示全部楼层
建议看看BSP里的东西,还有好多头文件,那个串口的操作都在头文件实现了。
玛尼玛尼哄 发表于 2019-3-4 21:30 | 显示全部楼层
BSP里有例子,串口0和串口1,以及如何使用重定向。
643757107 发表于 2019-3-4 21:47 | 显示全部楼层
看看是不是里面有个弱函数,那个就是修改的。
dongnanxibei 发表于 2019-3-5 00:13 | 显示全部楼层
使用的哪个串口、》
稳稳の幸福 发表于 2019-3-5 22:52 | 显示全部楼层
  1. /*---------------------------------------------------------------------------------------------------------*/
  2. /*                                                                                                         */
  3. /* Copyright(c) 2017 Nuvoton Technology Corp. All rights reserved.                                         */
  4. /*                                                                                                         */
  5. /*---------------------------------------------------------------------------------------------------------*/

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

  11. //***********************************************************************************************************
  12. //  File Function: N76E003 GPIO demo code
  13. //***********************************************************************************************************
  14. #include "N76E003.h"
  15. #include "SFR_Macro.h"
  16. #include "Function_define.h"
  17. #include "Common.h"
  18. #include "Delay.h"


  19. unsigned char temp _at_ 0x08;
  20. unsigned char idata itemp _at_ 0x80;
  21. unsigned char xdata xtemp _at_ 0x80;

  22. /*==========================================================================*/
  23. void main (void)
  24. {
  25.                 InitialUART0_Timer3(115200);
  26.           TI = 1;                                                                                                                        // Important, use prinft function must set TI=1;
  27.        
  28.                 while(1)
  29.                 {
  30.                         printf("\n Hello world");
  31.                         Timer0_Delay1ms(300);
  32.                 }
  33. }
稳稳の幸福 发表于 2019-3-5 22:52 | 显示全部楼层
  1. /***********************************************************************/
  2. /*  This file is part of the C51 Compiler package                      */
  3. /*  Copyright KEIL ELEKTRONIK GmbH 1990 - 2002                         */
  4. /***********************************************************************/
  5. /*                                                                     */
  6. /*  PUTCHAR.C:  This routine is the general character output of C51.   */
  7. /*  You may add this file to a uVision2 project.                       */
  8. /*                                                                     */
  9. /*  To translate this file use C51 with the following invocation:      */
  10. /*     C51 PUTCHAR.C <memory model>                                    */
  11. /*                                                                     */
  12. /*  To link the modified PUTCHAR.OBJ file to your application use the  */
  13. /*  following Lx51 invocation:                                         */
  14. /*     Lx51 <your object file list>, PUTCHAR.OBJ <controls>            */
  15. /*                                                                     */
  16. /***********************************************************************/

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

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

  24. /*
  25. * putchar (mini version): outputs charcter only
  26. */
  27. #if 0
  28. char putchar (char c)
  29. {
  30.                 while (!TI_1);  /* wait until transmitter ready */
  31.                 TI_1 = 0;
  32.                 SBUF_1 = c;      /* output character */
  33.                 return (c);
  34. }
  35. #else
  36. char putchar (char c)  {
  37.   while (!TI);
  38.   TI = 0;
  39.   return (SBUF = c);
  40. }
  41. #endif
稳稳の幸福 发表于 2019-3-5 22:52 | 显示全部楼层
  1. /*---------------------------------------------------------------------------------------------------------*/
  2. /*                                                                                                         */
  3. /* Copyright(c) 2017 Nuvoton Technology Corp. All rights reserved.                                         */
  4. /*                                                                                                         */
  5. /*---------------------------------------------------------------------------------------------------------*/

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

  11. //***********************************************************************************************************
  12. //  File Function: N76E003 GPIO demo code
  13. //***********************************************************************************************************
  14. #include "N76E003.h"
  15. #include "SFR_Macro.h"
  16. #include "Function_define.h"
  17. #include "Common.h"
  18. #include "Delay.h"


  19. unsigned char temp _at_ 0x08;
  20. unsigned char idata itemp _at_ 0x80;
  21. unsigned char xdata xtemp _at_ 0x80;

  22. /*==========================================================================*/
  23. void main (void)
  24. {
  25.                 InitialUART1_Timer3(115200);
  26.                 TI_1 = 1;
  27.                 while(1)
  28.                 {
  29.                         printf("\n hello world");
  30.                         Timer0_Delay1ms(300);
  31.                 }
  32. }
稳稳の幸福 发表于 2019-3-5 22:53 | 显示全部楼层
  1. /***********************************************************************/
  2. /*  This file is part of the C51 Compiler package                      */
  3. /*  Copyright KEIL ELEKTRONIK GmbH 1990 - 2002                         */
  4. /***********************************************************************/
  5. /*                                                                     */
  6. /*  PUTCHAR.C:  This routine is the general character output of C51.   */
  7. /*  You may add this file to a uVision2 project.                       */
  8. /*                                                                     */
  9. /*  To translate this file use C51 with the following invocation:      */
  10. /*     C51 PUTCHAR.C <memory model>                                    */
  11. /*                                                                     */
  12. /*  To link the modified PUTCHAR.OBJ file to your application use the  */
  13. /*  following Lx51 invocation:                                         */
  14. /*     Lx51 <your object file list>, PUTCHAR.OBJ <controls>            */
  15. /*                                                                     */
  16. /***********************************************************************/

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

  19. /****************************************************************************/
  20. /* Define putchar send from UART1, printf function will send from P1.6(TXD_1)
  21. /* NOTICE: Since UART1 pin is multi-function with OCD DATA/CLK pin.
  22. /* Suggest download than use run with realchip but not OCD mode.
  23. /****************************************************************************/
  24. #if 1
  25. char putchar (char c)                                //for UART1_printf
  26. {
  27.                 while (!TI_1);  /* wait until transmitter ready */
  28.                 TI_1 = 0;
  29.                 SBUF_1 = c;      /* output character */
  30.                 return (c);
  31. }
  32. #else
  33. /*
  34. * putchar (mini version): outputs charcter only
  35. */
  36. char putchar (char c)                          //for UART0_printf
  37. {                               
  38.   while (!TI);
  39.   TI = 0;
  40.   return (SBUF = c);
  41. }

  42. #endif
稳稳の幸福 发表于 2019-3-5 22:54 | 显示全部楼层
其实实现这个putchar就可以了。
dongnanxibei 发表于 2019-4-9 23:04 | 显示全部楼层
使用重定向的人还真不少。
wanduzi 发表于 2019-4-10 23:43 | 显示全部楼层
默认是使用的串口1
您需要登录后才可以回帖 登录 | 注册

本版积分规则

36

主题

851

帖子

2

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