Friday, 16 September 2016

Home_security_system

Home_security_system:


Code:



#define F_CPU 8000000UL
#include <avr/io.h>
#include <util/delay.h>

void lcdcmd(char);
void lcddata(char);
void lcdcmdwrite();
void lcddatawrite();
void lcdstring(char *);

void serial_init()
{
  UCSRB=0x18;
  UCSRC=UCSRC|(1<<URSEL)|(1<<UCSZ1)|(1<<UCSZ0);
  UBRRL= 0x33;
}

void send(char item)
{
UDR=item;
while(!(UCSRA & (1<<UDRE)));
UCSRA|=1<<UDRE;
}

void serial_tx(char *str)
{
while(*str)
{
send(*str);
str++;
}
}

void lcd_init()
{
  lcdcmd(2);
  lcdcmd(0x28);
  lcdcmd(0x0e);
  lcdcmd(0x06);
}

void defualt()
{
_delay_ms(5000);
lcdcmd(1);
lcdstring("System Ready");
}

int main()
{
DDRA=0xff;
int j=0,k=0;
DDRB=0xff;
serial_init();
lcd_init();
// serial_tx("ATE0");
// send(0x0d);
// _delay_ms(300);
serial_tx("AT+CMGF=1");
send(0x0d);
_delay_ms(300);
serial_tx("AT+CNMI=2,2,0,0,0");
send(0x0d);
_delay_ms(300);
lcdcmd(1);
lcdstring("GSM Project");
_delay_ms(2000);
serial_tx("AT+CMGS=\"+918826387380\"");
send(0x0d);
_delay_ms(200);
serial_tx("System Ready....");
send(0x0d);
_delay_ms(500);
send(26);
lcdcmd(0xc0);
lcdstring("system Ready");
lcdcmd(0x01);
    while(1)
    {
do
{
lcdcmd(0x80);
lcdstring("System Ready....");
}
while(!(PIND &(1<<7)));
 {
     PORTC|=(1<<2);
 PORTC|=(1<<1);
 lcdcmd(1);
 lcdstring("Someone in your");
 lcdcmd(0xc0);
 lcdstring("     Place    ");
 serial_tx("at+cmgf=1");
 send(0x0d);
 _delay_ms(200);
 PORTC&=~(1<<2);
 serial_tx("AT+CMGS=\"+918888888888\"");
 send(0x0d);
 _delay_ms(200);
 PORTC|=(1<<2);
 serial_tx("Someone in your place........");
 send(0x0d);
 _delay_ms(200);
 PORTC&=~(1<<2);
 serial_tx("Please secure your place soon.... Thank You... ");
 send(0x0d);
 _delay_ms(200);
 send(26);
 PORTC|=(1<<2);
 _delay_ms(500);
 PORTC&=~(1<<2);
 PORTC&=~(1<<1);
 PORTC&=~(1<<0);
 _delay_ms(10000);
 lcdcmd(1);
 }
     }
 }

void lcdstring(char *str)
{
while(*str)
{
lcddata(*str);
_delay_ms(10);
str++;
}
}
void lcdcmd(char x)
{
PORTB=x & 0xf0;
lcdcmdwrite();
PORTB=(x<<4) & 0xf0;
lcdcmdwrite();
}
void lcdcmdwrite()
{
PORTB=PORTB&~(1<<0);
PORTB=PORTB&~(1<<1);
PORTB=PORTB|(1<<2);
_delay_ms(1);
PORTB=PORTB&~(1<<2);
_delay_ms(1);
}
void lcddata(char x)
{
PORTB=x & 0xf0;
lcddatawrite();
PORTB=(x<<4) & 0xf0;
lcddatawrite();
}
void lcddatawrite()
{
PORTB=PORTB|(1<<0);
PORTB=PORTB&~(1<<1);
PORTB=PORTB|(1<<2);
_delay_ms(1);
PORTB=PORTB&~(1<<2);
_delay_ms(1);
}


Simulation:






1 comment:

  1. This is a great post. I like this topic.This site has lots of advantage.I found many interesting things from this site. It helps me in many ways.Thanks for posting this again. local alarm companies alice

    ReplyDelete

if you have any doubt please let me know