#define F_CPU 20000000L
#define FOSC 20000000UL //system clock speed
#define BAUD 9600UL
#define MYUBRR FOSC/16/(BAUD-1)
#include <avr/io.h>
#include <util/delay.h>
void USART_init(unsigned int ubrr);
void USART_Transmit(unsigned char data);
unsigned char USART_Receive(void);
int main(void)
{
USART_init(MYUBRR);
while(1)
{
int i;
for(i=0x30; i<0x3A; i++)
{
USART_Transmit(i);
_delay_ms(20);
}
}
return(0);
}
void USART_init(unsigned int ubrr)
{
//set baud rate
UBRRH = (unsigned char)(ubrr>>8);
UBRRL = (unsigned char)ubrr;
//Enable receiver and transmitter
UCSRB = (1<<RXEN)|(1<<TXEN);
//set frame format: 8 data, 1 stop bit
UCSRC = (1<<URSEL)|(1<<UCSZ1)|(1<<UCSZ0);
}
void USART_Transmit(unsigned char data)
{
//wait for empty transmit buffer
while(!(UCSRA & (1<<UDRE)));
//put data into buffer, sends the data
UDR = data;
}
unsigned char USART_Receive(void)
{
//wait for data to be received
while(!(UCSRA & (1<<RXC)));
//get and return received data from buffer
return UDR;
}
thefear@thefear:~/flshit$ avr-gcc -mmcu=atmega168 ./fshit_IMU.c -o fshit.o
In file included from ./fshit_IMU.c:7:
/usr/lib/gcc/avr/4.3.5/../../../avr/include/util/delay.h:90:3: warning: #warning "Compiler optimizations disabled; functions from <util/delay.h> won't work as designed"
./fshit_IMU.c: In function ‘USART_init’:
./fshit_IMU.c:32: error: ‘UBRRH’ undeclared (first use in this function)
./fshit_IMU.c:32: error: (Each undeclared identifier is reported only once
./fshit_IMU.c:32: error: for each function it appears in.)
./fshit_IMU.c:33: error: ‘UBRRL’ undeclared (first use in this function)
./fshit_IMU.c:35: error: ‘UCSRB’ undeclared (first use in this function)
./fshit_IMU.c:35: error: ‘RXEN’ undeclared (first use in this function)
./fshit_IMU.c:35: error: ‘TXEN’ undeclared (first use in this function)
./fshit_IMU.c:37: error: ‘UCSRC’ undeclared (first use in this function)
./fshit_IMU.c:37: error: ‘URSEL’ undeclared (first use in this function)
./fshit_IMU.c:37: error: ‘UCSZ1’ undeclared (first use in this function)
./fshit_IMU.c:37: error: ‘UCSZ0’ undeclared (first use in this function)
./fshit_IMU.c: In function ‘USART_Transmit’:
./fshit_IMU.c:43: error: ‘UCSRA’ undeclared (first use in this function)
./fshit_IMU.c:43: error: ‘UDRE’ undeclared (first use in this function)
./fshit_IMU.c:45: error: ‘UDR’ undeclared (first use in this function)
./fshit_IMU.c: In function ‘USART_Receive’:
./fshit_IMU.c:50: error: ‘UCSRA’ undeclared (first use in this function)
./fshit_IMU.c:50: error: ‘RXC’ undeclared (first use in this function)
./fshit_IMU.c:52: error: ‘UDR’ undeclared (first use in this function)