I'm a bit confused as to how Arduino finds my include files. These are from Winavr
I copied my program from AVR Studio and pasted into a sketch and away it runs.
I have inserted my code
#define F_CPU 16E6 // ATMEGA328P 16 Mhz
#define USART_BAUDRATE 38400
#define F_BAUD_PRESCALE (((F_CPU/(USART_BAUDRATE*16UL)))-1)
#include <avr/io.h>
#include <util/delay.h>
void init_ports()
{
DDRB = 0x20; // set PB5 LED as output
}
void serial_init(unsigned int BAUD_PRESCALE)
{
UBRR0H = (unsigned char)(BAUD_PRESCALE >> 8); //Upper 8-bits baud rate, Shift Right 8 times
UBRR0L = (unsigned char)(BAUD_PRESCALE); //lower 8-bits.
UCSR0B = (1 << RXEN0) | (1 << TXEN0); // Turn on the transmission and reception circuitry
UCSR0C = (0 << USBS0) | (3 << UCSZ00); // Stop Bits =1 8-bit
}
void serial_send(unsigned char data)
{
while( !(UCSR0A & (1<<UDRE0))); // wait for empty transmit buffer.
UDR0 = data ; // Send data
}
int main(void)
{
init_ports();
serial_init(F_BAUD_PRESCALE);
while(1)
{
PORTB = 0x20;
_delay_ms(500);
PORTB = 0x00;
_delay_ms(500);
serial_send('A');
}
}