共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 跳转至页
回复
我要赚赏金打赏帖 |
|
|---|---|
| 【S32DS】S32K3 RTD7.0.1 HSE 组件配置报错问题解决被打赏¥27元 | |
| 【S32K3XX】MCME 启动 CORE1被打赏¥23元 | |
| AG32VH407下温度大气压传感器及其检测被打赏¥20元 | |
| AG32VH407下光照强度传感器BH1750及其检测被打赏¥22元 | |
| AT32VH407下使用温湿度传感器DHT22进行检测被打赏¥20元 | |
| DIY一个婴儿澡盆温度计被打赏¥34元 | |
| 【FreeRtos】FreeRtos+MPU region 配置规则被打赏¥23元 | |
| 【分享开发笔记,赚取电动螺丝刀】三分钟快速上手驱动墨水屏(ArduinoIDE)被打赏¥28元 | |
| 【S32K3XX】LIN 通讯模块使用被打赏¥31元 | |
| 【FreeRtos】FreeRtos + MPU模块的配置使用被打赏¥32元 | |
我要赚赏金
