gonewiththewind1312
Newbie level 4
- Joined
- Nov 27, 2012
- Messages
- 7
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,335
Hello Everyone
I've read some tutorial about Atmega8 USART.
I tried to write a simple program, which send a character 'a' to serial port.
I used Realterm to connect to MicroController, but received character was not direct (wrong text).
(I also tried to use Hyper Terminal, but sometime text is displayed in screen (wrong text), sometime nothing)
Realterm Text: https://i1275.photobucket.com/albums/y446/gonewiththewind1312/realtearm-config.jpg
(View in ascii mode)
Thank in advanced for anyone who help me to solve this problem.
Or, Any one can give me your code for this program (Send a character to serial port), and how can you run/test your program.
* Is there any error about character encoding ??
I've read some tutorial about Atmega8 USART.
I tried to write a simple program, which send a character 'a' to serial port.
I used Realterm to connect to MicroController, but received character was not direct (wrong text).
(I also tried to use Hyper Terminal, but sometime text is displayed in screen (wrong text), sometime nothing)
Realterm Text: https://i1275.photobucket.com/albums/y446/gonewiththewind1312/realtearm-config.jpg
(View in ascii mode)
Thank in advanced for anyone who help me to solve this problem.
Or, Any one can give me your code for this program (Send a character to serial port), and how can you run/test your program.
* Is there any error about character encoding ??
PHP:
#include <avr/io.h>
#include <util/delay.h>
#include <compat/twi.h>
#include <avr/interrupt.h>
#define FOSC 16000000UL
#define F_CPU 16000000
#define BAUD 9600
#define UBRR FOSC/16/BAUD-1
/* Init USART */
void init_USART0(unsigned int ubrr){
UBRR0H = (unsigned char) (ubrr>>8);
UBRR0L = (unsigned char) ubrr;
UCSR0C = (3<<UCSZ00); // 8-bit data. 1 stop bit
UCSR0B |= (1<<RXEN0) | (1<<TXEN0);
}
/* Transmit 1 byte Data */
void transmit_1byte_USART0(unsigned char data){
while(!(UCSR0A & (1<<UDRE0)));
UDR0 = data;
}
/* Main Program*/
int main()
{
init_USART0(UBRR);
while(1){
transmit_1byte_USART0('a');
_delay_ms(10);
}
return 0;
}