NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » Simple "Hello World" Using UART

August 15, 2009
by Nerdful_com
Nerdful_com's Avatar

Here is an AVR "Hello World" demonstration that writes "Hello World" to your PC VIA serial to USB every 1 second (open hyper terminal to see).

/* 
Made by www.Nerdful.com
Prints HELLO WORLD to the PC VIA serial RS232 (terminal)
*/

#define F_CPU 14745600
#include <avr/io.h>
#include <avr/pgmspace.h>
#include "../libnerdkits/delay.h"
#include "../libnerdkits/uart.h"

int main() {
uart_init();
FILE uart_stream = FDEV_SETUP_STREAM(uart_putchar, uart_getchar, _FDEV_SETUP_RW);
stdin = stdout = &uart_stream;
while(1) {
printf_P(PSTR("HELLO WORLD from www.Nerdful.com\r\n"));
delay_ms(1000);
} 
return 0;
}
March 20, 2010
by brian
brian's Avatar

What pins does it output the serial data to?

March 20, 2010
by mongo
mongo's Avatar

It returns the test through the USB adapter to the computer.

March 20, 2010
by mongo
mongo's Avatar

ummm TEXT - not test...DUHH, Dyslexic fingers.

March 20, 2010
by brian
brian's Avatar

Hmm...doesn't seem to be working for me. Maybe I did something wrong?

March 21, 2010
by brian
brian's Avatar

Nevermind - the code works fine on the pins 2/3 with the included serial adapter...you just have to remember to set the baud rate to 115200 in PuTTY ;)

Post a Reply

Please log in to post a reply.

Did you know that interrupts can cause problems if you're not careful about timing and memory access? Learn more...