这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 综合技术 » 基础知识 » WinAVR,printf 在WinAVR中调用printf

共4条 1/1 1 跳转至

WinAVR,printf 在WinAVR中调用printf

院士
2006-09-17 18:14:16     打赏
WinAVR,printf 在WinAVR中调用printf



关键词: WinAVR     printf     调用    

院士
2006-12-22 22:43:00     打赏
2楼
问   请教详细的在WinAVR中调用printf函数的方法。先谢过! 1: 需要设置输入输出数据接口流在
C:\WinAVR\examples\twitest
例子下有说明

贴一下我的调试例子程序
是以串行口作为流处理。


#include <io.h>
#include <stdio.h>
//#include <inttypes.h>
//#include <stdlib.h>

#define SYSCLK 14745600UL

void ioinit(void)
{

  //UCSRB = _BV(TXEN);        /* tx enable */
  //UCSRB = _BV(RXEN);

  UCSRB=UCSRB|0X18;

  //UBRRL = (SYSCLK / (16 * 9600UL)) - 1; /* 9600 Bd */
  UBRRH=0;
  UBRRL=71;
  /* initialize TWI clock: 100 kHz clock, TWPS = 0 => prescaler = 1 */
#if defined(TWPS0)
  /* has prescaler (mega128 & newer) */
  TWSR = 0;
#endif
  TWBR = (SYSCLK / 100000UL - 16) / 2;
}


int uart_putchar(char c)
{

  if (c == '\n')
    uart_putchar('\r');
  loop_until_bit_is_set(UCSRA, UDRE);
  UDR = c;
  return 0;
}

unsigned char uart_getchar(void)
{
volatile unsigned char ret;
//loop_until_bit_is_set(UCSRA,RXC);
while ((UCSRA&0X80)==0);
//UCSRA=UCSRA&(~0X80);
ret=UDR;
return ret;
}

int main (void)
{
volatile static int i=5;
ioinit();
fdevopen(uart_putchar,uart_getchar, 0);
for (i=0;i<5;i++)
{
printf("abc\r");
}
i=5;
for (;;)
  {
//   uart_putchar(uart_getchar());
   sCANf("%d",&i);
   printf("Get in data =%d \r",i);
  }
} 2: printf很好用,但它的代码开销很大。 3: 不建议用printf,代码开销太大。建议自己编写串口程序。 4: 多谢指点,我想调试一下

高工
2023-01-30 22:44:05     打赏
3楼

感谢分享


专家
2023-01-31 00:53:34     打赏
4楼

谢谢分享


共4条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]