我正在尝试使用C在ATMEGA328上配置ADC,然后进入以下一行:
FILE usart0_str = FDEV_SETUP_STREAM(USART0SendByte, NULL, _FDEV_SETUP_WRITE);
以下错误:
sorry, unimplemented: non-trivial designated initializers not supported
FILE usart0_str = FDEV_SETUP_STREAM(USART0SendByte, NULL, _FDEV_SETUP_WRITE);
^
我真的不理解该错误,我尝试在Google上搜索该错误,但未发现与此类似的错误,并且我确信这种情况会发生,因为我不理解此错误。
这是整个代码:
#ifndef F_CPU
#define F_CPU 16000000UL
#endif
#include <stdio.h>
#include <avr/io.h>
#include <util/delay.h>
#define USART_BAUDRATE 9600
#define UBRR_VALUE ( ( ( F_CPU / ( USART_BAUDRATE * 16UL ) ) ) - 1 )
#define VREF 5
#define POT 10000
void initADC( void );
uint16_t readADC( uint8_t ADCchannel );
void USART0Init(void);
int USART0SendByte( char u8Data, FILE *stream );
void setUpLED ( void );
FILE usart0_str = FDEV_SETUP_STREAM( USART0SendByte, NULL, _FDEV_SETUP_WRITE );
int main( void )
{
double vbg, potval;
initADC();
USART0Init();
stdout = &usart0_str;
setUpLED ();
while ( 1 )
{
potval = (double)POT / 1024 * readADC(0);
printf("Potentiometer value = %u Ohm\n", (uint16_t)potval);
vbg = (double)VREF / 1024 * readADC(14);
printf("Vbg = %4.2fV\n", vbg);
_delay_ms(1000);
}
}
void setUpLED ( void )
{
DDRB |= ( 1 << PB0 );
PORTB |= ( 1 << PB0 );
}
void initADC( void )
{
ADMUX |= ( 1 << REFS0 );
ADCSRA |= ( 1 << ADPS2 ) | ( 1 << ADPS1 ) | ( 1 << ADPS0 ); ///16000000/128=125kHz
ADCSRA |= ( 1 << ADEN );
}
uint16_t readADC( uint8_t ADCchannel )
{
ADMUX = ( ADMUX & 0xF0 ) | ( ADCchannel & 0x0F );
ADCSRA |= ( 1 << ADSC );
while ( ADCSRA & ( 1 << ADSC ) );
return ADC;
}
int USART0SendByte( char u8Data, FILE *stream )
{
if ( u8Data == '\n' )
{
USART0SendByte( '\r', stream );
}
while ( !( UCSR0A & ( 1 << UDRE0 ) ) ) { };
UDR0 = u8Data;
return 0;
}
void USART0Init(void)
{
UBRR0H = (uint8_t)(UBRR_VALUE >> 8);
UBRR0L = (uint8_t)UBRR_VALUE;
UCSR0C |= (1 << UCSZ01) | (1 << UCSZ00);
UCSR0B |= (1 << RXEN0) | (1 << TXEN0);
}`
如果我使用codeblocks
进行编译,则一切正常,但我使用arduino板作为程序员,也使用arduino IDE。
为什么会出现此错误?