Hi, everybody
I'm new to this forum and to AVR too.
I'm having a problem with an exercise that i'm doing to learn start programming.
Could anyone help me? Or try to?
I have a code that was already corrected by a friend(teacher for me), but i don't know what is going wrong here.
My code is the this:
#define F_CPU 7372800UL
//#define F_CPU 8000000UL
#include
#include
#include
#include
#define USART_BAUDRATE 57600
#define MYUBRRN ((F_CPU/(USART_BAUDRATE<<4))-1)
void initUsart (uint16_t MY_UBBR);
void sendChar (uint8_t data);
void sendString ( char *data);
void initUsart(uint16_t MY_UBBR)
{
UBRR0H = (unsigned char )(MY_UBBR>>8);
UBRR0L = (unsigned char )MY_UBBR;
UCSR0B = (1<<TXEN0) | (1<<RXEN0) | (1<<RXCIE0) |(1<<UDRIE0);
UCSR0C = (1<<UCSZ01)|(1<<UCSZ00);
}
//////////////////////////////////
//Function : send char to the usart
////////////////////////////////////
void sendChar(uint8_t data)
{
while ( !( UCSR0A & (1<<UDRE0)) );
UDR0 = data;
}
////////////////////////////////////
//Function : write string to the usart
////////////////////////////////////
void sendString(char *data)
{
int len, i;
len = strlen(data);
for (i=0; i
{
return;
}
else
{
sendChar(*data+i);
}
}
// tambem podes ser ainda mais simples
//while(*data !=0x00){
// sendChar(*data);
// data++;
//}
}
////////////////////////////////////
//Function : main cicle
////////////////////////////////////
int main(void)
{
char nome[] ="Nelson Macieira";
DDRB |= (1<<PINB0);
CLKPR |= (1<<CLKPCE);
CLKPR |= (0);
OSCCAL=0xDD; //Do i really need this?
initUsart(MYUBRRN);
//sei(); //Enable allactivated interruptions
//PORTB = 0xff;
while(1)
{
sendChar('a');
//sendString (nome); //Escreve String
PORTB ^=(1<<PINB0);
_delay_ms(500);
}
}
Thanks for any help