Quick links
Latest articles
Internship
Members
New...
Algorithms
Discrete Mathematics
Big data
Languages
C
C++
C++ STL
Java
Data Structure
C#.Net
Android
Kotlin
SQL
Web
PHP
Python
JavaScript
CSS
Ajax
Node.js
Web prog.
Programs
C
C++
DS
Java
C#
Python
Aptitude
C
C++
Java
DBMS
Interview
C
Embedded C
Java
SEO
HR
CS Subjects
CS Basics
O.S.
Networks
DBMS
Embedded Systems
Cloud Computing
Machine learning
CS Organizations
Linux
DOS
More...
Articles
Puzzles
News/Updates

Home » Embedded Systems

AVR | USART Home Automation



In this article, we are going to learn about the Universal Synchronous and Asynchronous serial Receiver and Transmitter (USART) Home Automation.
Submitted by Suryaveer Singh, on August 08, 2018

The Universal Synchronous and Asynchronous serial Receiver and Transmitter (USART) is a highly flexible serial communication device. The main features are:

  • Full Duplex Operation (Independent Serial Receive and Transmit Registers)
  • Asynchronous or Synchronous Operation
  • Master or Slave Clocked Synchronous Operation
  • High-Resolution Baud Rate Generator
  • Supports Serial Frames with 5, 6, 7, 8, or 9 Data Bits and 1 or 2 Stop Bits
  • Odd or Even Parity Generation and Parity Check Supported by Hardware
  • Data Overrun Detection
  • Framing Error Detection
  • Noise Filtering Includes False Start Bit Detection and Digital Low Pass Filter
  • Three Separate Interrupts on TX Complete, TX Data Register Empty, and RX Complete
  • Multi-processor Communication Mode
  • Double Speed Asynchronous Communication Mode

These are some of the features of USART, we would now lean to create a program in which we would use Bluetooth technology to open and close a LED bulb. In our program, we would take a variable X, such that if X=A our bulb will glow and if X=B the bulb will stop glowing.

In the similar we can also use a fan instead of LED, then we would be controlling our Fan to start or stop.

Program:



#include <avr/io.h>

void usart_string(char*);

int main(void)
{
	char x;
	DDRA = 0x01;
	UBRRL= 51;
	UCSRB= 0x18;
	UCSRC= 0x86;

	usart_string("Sam");

	while(1)
	{
		while((UCSRA&(1<<RXC))==0);
		x=UDR;
		if(x=='A')
		{
			PORTA=0x01;
		}
		else if(x=='B')
		{
			PORTA=0x00;
		}		
	}
}

void usart_string(char*p)
{
	while(*p!='\0')
	{
		UDR=*p;
		while((UCSRA&(1<<TXC))==0);
		UCSRA|=1<<TXC;
		p++;
	}
}

Explanation:

  • Write all the header files as written above.
  • Take a variable X which will decide whether our bulb will be ON or OFF.
  • DDRA=0x01 indicates that the Led bulb is connected.
  • UBRRL=51; indicates that the baud rate is set to 9600.
  • UCSRB=0x18 means Rx and Tx are enabled.
  • The usart_string will print the word written inside it.
  • Inside the while loop, we have written our bulb glowing condition such that when A is received the LED will glow and when B is received the LED bulb will stop glowing.

BAUD RATE

It is the rate at which the information is processed/transferred to the communication channel.



Calculation of BAUD RATE

Calculation of BAUD RATE

Where, fOSC is "System Oscillator Clock Frequency".

Simulation:

USART Simulation

Explanation:

  • Select the following components:
    1. Atmega16
    2. LED Red
    3. From virtual instruments mode select a VIRTUAL TERMINAL
  • Add the components as shown in the figure.
  • Double click on ATmega16 and make its speed as 8000000 and upload the hex file in it.
  • When we will start the simulation a screen will appear that would be our simulation for a Bluetooth screen.
  • Typing A will glow the bulb and typing B will stop the bulb from glowing.





Quick links:
C FAQ(s) C Advance programs C/C++ Tips & Tricks Puzzles JavaScript CSS Python Linux Commands PHP Android Articles More...

Featured post:
Introduction to Linux (Its modes, Safety, Most popular Applications)
Linux Best Distribution Software (Distros) of 2018

Was this page helpful? Please share with your friends...

Are you a blogger? Join our Blogging forum.

Comments and Discussions



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com (2015-2018), Some rights reserved.