我用protues虚拟终端仿真,使用printf函数能够打印出整形数,但是不能打印出float型数,打出来是问号“?”,请高手帮忙解决!!!!!!!!
以下是我包含的uart.h文件
#include <stdio.h>
#include <stdint.h>
#include <avr/io.h>
#include "uart.h"
static int uart_putchar(char c, FILE *stream) ;
static unsigned char uart_getchar(void);
static FILE mystd = FDEV_SETUP_STREAM(uart_putchar, uart_getchar,_FDEV_SETUP_RW);
static int uart_putchar(char c, FILE *stream)
{
if (c == '\n') uart_putchar('\r', stream);
loop_until_bit_is_set(UCSRA, UDRE);
UDR = c;
return 0;
}
static 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;
}
//-----------------------------------------------------------------------------
// 串口初始化
//-----------------------------------------------------------------------------
void uart_ini(void)
{
unsigned char baud = 47; /*4800 U2X=0&Fosc=1MHz*/
UBRRH = (unsigned char) (baud>>8);
UBRRL = (unsigned char) baud;
UCSRB = (1<<RXEN)|(1<<TXEN);
UCSRC = (1<<URSEL)|(1<<USBS)|(3<<UCSZ0);/*8data 2stop !!!!实际测试为8data 1stop jy 2009.12.2*/
stdout = &mystd;
stdin = &mystd;
} |