打印
[ZLG-MCU]

请问:如何在keil中运用printf函数

[复制链接]
6214|9
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
netmis9979|  楼主 | 2007-6-19 16:08 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
沙发
zlgmcu| | 2007-6-20 08:42 | 只看该作者

一般情况下,在keil中调试,我是直接观察相关变量

或相关地址中的数据.

这是最简单最有效的方法

使用特权

评论回复
板凳
masashinakayama| | 2007-6-29 12:30 | 只看该作者

什么乱七八糟的printf

给你个AT91SAM7S64的东西看看,自己改改把,用前初始化好串口

#include <stdarg.h> // va_list
#include <stdio.h> // vsprintf()
#include "..includeAT91SAM7S64.h"
#include "..includelib_AT91SAM7S64.h"

 
void SAM_Printf(char *fmt,...)
{
 va_list ap;
 char string[256],*pt;
 va_start(ap,fmt);
 vsprintf(string,fmt,ap);
 pt=string;
 while(*pt)
 {
  while(!AT91F_US_TxReady(AT91C_BASE_US0)); //block until TxReady
  AT91F_US_PutChar(AT91C_BASE_US0,*pt++);

 }
 va_end(ap);
}

使用特权

评论回复
地板
HQGBOY| | 2007-7-2 15:18 | 只看该作者

。。。。。

使用特权

评论回复
5
HQGBOY| | 2007-7-2 15:20 | 只看该作者

KEIL :HELLO

/*------------------------------------------------------------------------------
HELLO.C

Copyright 1995-2005 Keil Software, Inc.
------------------------------------------------------------------------------*/

#include <REG52.H>                /* special function register declarations   */
                                  /* for the intended 8051 derivative         */

#include <stdio.h>                /* prototype declarations for I/O functions */


#ifdef MONITOR51                         /* Debugging with Monitor-51 needs   */
char code reserve [3] _at_ 0x23;         /* space for serial interrupt if     */
#endif                                   /* Stop Exection with Serial Intr.   */
                                         /* is enabled                        */


/*------------------------------------------------
The main C function.  Program execution starts
here after stack initialization.
------------------------------------------------*/
void main (void) {

/*------------------------------------------------
Setup the serial port for 1200 baud at 16MHz.
------------------------------------------------*/
#ifndef MONITOR51
    SCON  = 0x50;                /* SCON: mode 1, 8-bit UART, enable rcvr      */
    TMOD |= 0x20;               /* TMOD: timer 1, mode 2, 8-bit reload        */
    TH1   = 221;                /* TH1:  reload value for 1200 baud @ 16MHz   */
    TR1   = 1;                  /* TR1:  timer 1 run                          */
    TI    = 1;                  /* TI:   set TI to send first char of UART    */
#endif

/*------------------------------------------------
Note that an embedded program never exits (because
there is no operating system to return to).  It
must loop and execute forever.
------------------------------------------------*/
  while (1) {
    P1 ^= 0x01;                 /* Toggle P1.0 each time we print */
    printf ("Hello World ");   /* Print "Hello World" */
  }
}

使用特权

评论回复
6
netmis9979|  楼主 | 2007-7-2 21:51 | 只看该作者

日了

这个keil中自带的hello world就是最简单的实现方法??
看的似懂非懂。。。
到现在也不是很明白
难道不能输出一次就停住

使用特权

评论回复
7
HQGBOY| | 2007-7-3 08:22 | 只看该作者

把死循环去掉,不就一次吗?

 //while (1) {
    P1 ^= 0x01;                 /* Toggle P1.0 each time we print */
    printf ("Hello World ");   /* Print "Hello World" */
 // }

使用特权

评论回复
8
su_mj000| | 2007-7-4 08:11 | 只看该作者

printf () 看起来很有用,似乎也很好用。

其实它的实现非常复杂,且代价昂贵。6楼给出的代码只能涵盖
printf()功能的一小部分而已。

建议采用2楼的思路自己写一个函数作为调试工具。

使用特权

评论回复
9
masashinakayama| | 2007-7-4 08:20 | 只看该作者

代价太大了

linux的printk就不支持浮点,我想有两种策略
1。仅打印字符串,最简单。楼主
2。支持打印整型数据,复杂些,库连接后可能多占1k左右代码,我的程序。
3。11楼printf,好像涉及semihost,反正是我是没搞懂,也不想去搞懂library里到底在倒腾个啥。semihost我是从来不用的。

使用特权

评论回复
10
MicroMMU| | 2007-7-5 10:36 | 只看该作者

一个Printf函数占了起码1-2K的空间。如果用浮点更厉害

使用特权

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

本版积分规则

5

主题

10

帖子

0

粉丝