共4条
1/1 1 跳转至页
WinAVR,printf 在WinAVR中调用printf
问
请教详细的在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: 多谢指点,我想调试一下
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: 多谢指点,我想调试一下
共4条
1/1 1 跳转至页
回复
| 有奖活动 | |
|---|---|
| 硬核工程师专属补给计划——填盲盒 | |
| “我踩过的那些坑”主题活动——第002期 | |
| 【EEPW电子工程师创研计划】技术变现通道已开启~ | |
| 发原创文章 【每月瓜分千元赏金 凭实力攒钱买好礼~】 | |
| 【EEPW在线】E起听工程师的声音! | |
| 高校联络员开始招募啦!有惊喜!! | |
| 【工程师专属福利】每天30秒,积分轻松拿!EEPW宠粉打卡计划启动! | |
| 送您一块开发板,2025年“我要开发板活动”又开始了! | |
我要赚赏金打赏帖 |
|
|---|---|
| Chaos-nano:专为低资源单片机设计的轻量级协作式异步操作系统(ATMEGA328P轻量级操作系统)—— 详细介绍被打赏¥16元 | |
| FPGA配置被打赏¥10元 | |
| Chaos-nano协作式异步操作系统:赋能MicrochipAVR8位单片机的革新之路被打赏¥15元 | |
| 基于esp32开发时串口工具的注意点被打赏¥24元 | |
| 基于FireBeetle2ESP32-C5开发板的舵机控制被打赏¥20元 | |
| 【分享开发笔记,赚取电动螺丝刀】MAX78000开发板制作的电子相册被打赏¥32元 | |
| 基于FireBeetle2ESP32-C5开发板的超声波测距及显示被打赏¥21元 | |
| FireBeetle2ESP32-C5上RTC电子时钟的实现被打赏¥25元 | |
| 【分享开发笔记,赚取电动螺丝刀】MAX78000开发板读取SD卡被打赏¥23元 | |
| 【S32K3XX】Standby RAM 重启后数据异常问题调查被打赏¥38元 | |
我要赚赏金
