Lib4U

‎"Behind every stack of books there is a flood of knowledge."

Output

SERIAL COMMUNICATION TUTORIAL USING AVR ATMEGA8

Here is the code for serial communication using AVR ATmega 8 RISC controller.
The functions used in this tutorial are

  • uart_puts(“zzz”)       :-> sends a string of character from data memory (RAM)
  • uart_puts_P(“xxxx”):-> sends a string of character from program memory (FLASH memory)
  • uart_putc(‘x’)          :->  sends a single character

This has functions to transmit data from program memory also.

  • Click to download project files & Proteus demo.Click to download project files & Proteus demo.

/*******************************************************************************
SERIAL COMMUNICATION ATM8

This source code introduces you to the working of the USART Module
available in ATMEGA 8 @8MHz system clock.

This code does the task of preparing a menu driven user interface on
hyperterminal using the USART Module.

Here the USART Module is configured to operate in the Asychronous
mode. With a Frame format of 8-bit Data with 1 stop bit and no parity
bit the baud rate is fixed for 9600 bps.

***********************************ELECDUDE.COM*********************************/

#define F_CPU 8000000UL            //Define the MPU operating frequency

#include <avr/io.h>                //Header file for AVR device specific I/O Definitions.
#include <avr/interrupt.h>            //Header file for incorportaing interrupt handling faclity (not used here).
#include <util/delay.h>                //Header file for incorporating delay routines.
#include <avr/pgmspace.h>            //Header file for incorporating Program space string utilities.
#include <stdlib.h>                //ISO Standard library of C functions and macros.
#include “USART.h”                //Defines C functions for accessing USART Module.

#define BIT(x)            (1 << (x))    //Set a particular bit mask
#define CHECKBIT(x,b)     (x&b)        //Checks bit status
#define SETBIT(x,b)     x|=b;        //Sets the particular bit
#define CLEARBIT(x,b)     x&=~b;        //Sets the particular bit
#define TOGGLEBIT(x,b)     x^=b;        //Toggles the particular bit

void WaitMs(unsigned int ms);
void welcome_screen(void);

int main()
{
unsigned int ch;

uart_init(9600);        //Initialise the USART Module with the given Baudrate and
//Frame format.
uart_puts_P(“\r\n\t************************************************ “);
uart_puts_P(“\r\n\t             ATMEGA 8 DEVELOPMENT BOARD “);
uart_puts_P(“\r\n\t************************************************ “);
uart_puts(“\r\n\t\t  “);
uart_puts_P(“\rWelcome to ElecDude.  Press any to display…..”);
uart_puts(“\r\r\r\r”);

while(1)   //Enter into a uncoditional while loop..
{
ch=uart_getc();
uart_puts(“\n\n\t\t”);
uart_putc(‘<‘);
uart_putc(ch);
uart_putc(‘>’);
WaitMs(100);
}

return 0;
}

void WaitMs(unsigned int ms)    //Generate a delay of ms milli second.
{
unsigned int i;

for(i=0;i<=ms/10;i++)
{
_delay_ms(10);
}
}

Source:

http://www.elecdude.com/2012/05/serial-communication-using-avr-atmega8.html

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Information

This entry was posted on January 16, 2013 by in Electronic & Computer Engineering, Embedded System, Science & Technology.
Virtual Fashion Technology

Virtual Fashion Education

toitocuaanhem

"chúng tôi chỉ là tôi tớ của anh em, vì Đức Kitô" (2Cr 4,5b)

VentureBeat

News About Tech, Money and Innovation

digitalerr0r

Modern art using the GPU

Theme Showcase

Find the perfect theme for your blog.

lsuvietnam

Learn to Learn

Gocomay's Blog

Con tằm đến thác vẫn còn vương tơ

Toán cho Vật lý

Khoa Vật lý, Đại học Sư phạm Tp.HCM - ĐT :(08)-38352020 - 109

Maths 4 Physics & more...

Blog Toán Cao Cấp (M4Ps)

Bucket List Publications

Indulge- Travel, Adventure, & New Experiences

Lib4U

‎"Behind every stack of books there is a flood of knowledge."

The WordPress.com Blog

The latest news on WordPress.com and the WordPress community.

%d bloggers like this: