/* Program for transmitting a string serially at 9600 baud rate continously,
using 8 data bit, 1 stop bit , XTAL = 8MHz */
#define F_CPU 8000000UL
#define BAUD 9600
#define MYUBRR F_CPU/16/BAUD-1
#include <avr/io.h>
#include <util/setbaud.h>
#include <util/delay.h>
void USART_Init( unsigned int ubrr);
void USART_Transmit( unsigned char data );
unsigned char USART_receive(void);
void USART_putstring(char* StringPtr);
int main( void )
{
USART_Init(MYUBRR);
while(1)
{
// Chose an arbitrary character to test.
//char String[]="Hello world!!";
//USART_putstring(String);
USART_Transmit('1') ;
_delay_ms(1000);
}
}
void USART_Init( unsigned int ubrr)
{
/*Set baud rate */
/* UBRR0H contains the 4 most significant bits of the
baud rate. UBRR0L contains the 8 least significant
bits.*/
UBRR0H = (unsigned char)(ubrr>>8);
UBRR0L = (unsigned char)ubrr;
/*Enable transmitter */
UCSR0B = (1<<RXEN0) | (1<<TXEN0) ;
/* Set frame format: 8data */
UCSR0C = (1<<UCSZ01)|(1<<UCSZ00);
}
void USART_Transmit( unsigned char data )
{
/* Wait for empty transmit buffer */
while ( !( UCSR0A & (1<<UDRE0)) );
/* Put data into buffer, sends the data */
UDR0 = data;
}
unsigned char USART_receive(void){
while(!(UCSR0A & (1<<RXC0)));
return UDR0;
}
void USART_putstring(char* StringPtr){
while(*StringPtr != 0x00){
USART_Transmit(*StringPtr);
StringPtr++;}
}
when I try to run this code & see the received string using Teraterm terminal , the terminal shows different kind of characters ?