DTMF_controlled_home_appliances
Code:
#include <avr/io.h>
#define F_CPU 8000000ul
#include<util/delay.h>
#define key PINC
#define key1 PC4
#define key2 PC5
#define key3 PC6
#define out PORTA
#define out1 PA0
#define out2 PA1
#define out3 PA2
#define lcd PORTB
#define lcd_cmd PORTD
void lcdcmd(char ch)
{
lcd=ch;
lcd_cmd=0x04;
_delay_ms(50);
lcd_cmd=0x00;
}
void lcddata(char ch)
{
lcd=ch;
lcd_cmd=0x05;
_delay_ms(50);
lcd_cmd=0x01;
}
void lcdstring(char *str)
{
while(*str!='\0')
{
lcddata(*str);
str++;
_delay_ms(10);
}
}
void lcdinit()
{
lcdcmd(0x38);
lcdcmd(0x06);
lcdcmd(0x0e);
lcdcmd(0x01);
}
int main(void)
{
DDRA=0xff;
DDRC=0x00;
DDRB=0xff;
DDRD=0xff;
lcdinit();
PORTC=0xff;
lcdstring("Home Automation");
lcdcmd(0xc0);
lcdstring("Enter UR Choice");
_delay_ms(2000);
while(1)
{
if(!(key & (1<<key1)) && !(key & (1<<key2)) && !(key & (1<<key3)))
{
lcdcmd(1);
lcdstring("All OFF");
out=0x00;
}
else if((key & (1<<key1)) && (key & (1<<key2)) && (key & (1<<key3)))
{
lcdcmd(1);
lcdstring("All ON");
out=0xFF;
}
else if(!(key & (1<<key1)) && (key & (1<<key2)) && (key & (1<<key3))) // light on
{
lcdcmd(1);
lcdstring("LIGHT ON");
out|=1<<out1;
}
else if((key & (1<<key1)) && !(key & (1<<key2)) && (key & (1<<key3))) // light off
{
lcdcmd(1);
lcdstring("LIGHT OFF");
out&=~(1<<out1);
}
else if(!(key & (1<<key1)) && !(key & (1<<key2)) && (key & (1<<key3))) // FAN ON
{
lcdcmd(1);
lcdstring("FAN ON");
out|=1<<out2;
}
else if((key & (1<<key1)) && (key & (1<<key2)) && !(key & (1<<key3))) // FAN off
{
lcdcmd(1);
lcdstring("FAN OFF");
out&=~(1<<out2);
}
else if(!(key & (1<<key1)) && (key & (1<<key2)) && !(key & (1<<key3))) // TV ON
{
lcdcmd(1);
lcdstring("TV ON");
out|=1<<out2;
}
else if(!(key & (1<<key1)) && !(key & (1<<key2)) && (key & (1<<key3))) // TV off
{
lcdcmd(1);
lcdstring("TV OFF");
out&=~(1<<out3);
}
else
{
lcdcmd(1);
lcdstring("Invalid Key ");
lcdcmd(0xc0);
lcdstring("Try Again....");
}
}
return 0;
}
0 comments:
Post a Comment
if you have any doubt please let me know