Saturday, 17 September 2016

Token Display

Token Display:


Code:


#include<lpc214x.h>
#define PLLE 0
#define PLLC 1
#define PLOCK 10
#define rs 16
#define rw 17
#define en 18
#define lcdport IO0SET
#define lcdportclr IO0CLR
void daten(void);
void cmnd(void);
void pllinit(void);
void delay(int);
void convert(unsigned long int);
void lcdcmd(char);
void lcddata(char);
void lcdinit(void );
void lcdstring(char *);
int main()
{
 IO0DIR=IO0DIR|(0x7f<<16);
 pllinit();
 lcdinit();
 //PINSEL0=PINSEL0|0x20

IO0DIR=IO0DIR|(0xff<<19);
PINSEL0=PINSEL0|(2<<4);//select CAP0.0
T0CTCR=0x01;
T0TC=0;
T0PC=0;
T0TCR=0x02;
T0TCR=0x01;
lcdstring("wainting for pulse or event");
while(1)
{
lcdcmd(0x01);lcdcmd(0x80);
convert(T0TC);
}
return 0;
}

void lcdstring(char *p)
{
lcdcmd(0x8f);
while(*p)
{
lcddata(*p);
lcdcmd(0x1c);
p++;
}
}

void lcdinit()
{
lcdcmd(0x02);
lcdcmd(0x28);
lcdcmd(0x01);
lcdcmd(0x0e);
lcdcmd(0x80);
}
void lcdcmd(char ch)
{
lcdport = ((ch&0xf0)<<15);
cmnd();
lcdportclr = ((ch&0xf0)<<15);

lcdport = (((ch<<4)&0xf0)<<15);
cmnd();
lcdportclr = (((ch<<4)&0xf0)<<15);
}

void lcddata(char ch)
{
lcdport = ((ch&0xf0)<<15);
daten();
lcdportclr = ((ch&0xf0)<<15);

lcdport = (((ch<<4)&0xf0)<<15);
daten();
lcdportclr = (((ch<<4)&0xf0)<<15);
}
void cmnd()
{
lcdportclr = (1<<rs);
lcdportclr = (1<<rw);
lcdport = (1<<en);
delay(1);
lcdportclr = (1<<en);
delay(2);
}
void daten()
{
lcdport = (1<<rs);
lcdportclr = (1<<rw);
lcdport = (1<<en);
delay(1);
lcdportclr = (1<<en);
delay(5);
}
void convert(unsigned long int a) //say a=678
{
int i;int a1;
char pos=0xcd;
for(i=0;i<=9;i++)
{
  lcdcmd(pos);
a1=a%10; //a1=8//7//6//0
a=a/10; //a=67//6//0//0
lcdstring("EVENT NO:");
lcddata(0x30+a1);
pos--;
}

}
void delay(int ms)
{
T1CTCR=0x00;
T1TC=0;
T1PC=0;
T1PR=59999;
T1TCR=0x02;
T1TCR=0x01;
while( T1TC != ms);
T1TCR=0;
}
void pllinit()
{
 PLL0CFG=0x24;
 PLL0CON=PLL0CON|(1<<PLLE);
 PLL0FEED=0xAA;
 PLL0FEED=0x55;
 //PLL0CON=PLL0CON|(1<<PLLC);
 while( (PLL0STAT & (1<<PLOCK))==0);
 PLL0CON=PLL0CON|3;
 PLL0FEED=0xAA;
 PLL0FEED=0x55;
 VPBDIV=0x01;
}
*/



#include<lpc214x.h>
#include<stdio.h>
#define PLLE 0
#define PLLC 1
#define PLOCK 10
#define rs 16
#define rw 17
#define en 18
#define lcdport IO0SET
#define lcdportclr IO0CLR
void daten(void);
void cmnd(void);
void pllinit(void);
void delay(int);
void convert(unsigned long int);
void lcdcmd(char);
void lcddata(char);
void lcdinit(void );
void lcdstring(char *);
char result[4];
int main()
{
 IO0DIR=IO0DIR|(0x7f<<16);
 IO0DIR=IO0DIR|(0xff<<19);
 PINSEL0=PINSEL0|(2<<4);//select CAP0.0
 pllinit();
 lcdinit();
 lcdcmd(0x80);
 lcdstring("EVENT COUNTING");

 delay(200);
 lcdcmd(1);
 lcdstring("EVENT NO:");
 delay(200);
 sprintf(result,"%d",T0TC);
 lcdcmd(0x8A);
 lcdstring(result);
 //PINSEL0=PINSEL0|0x20


T0CTCR=0x01;
T0TC=0;
T0PC=0;
T0TCR=0x02;
T0TCR=0x01;
//lcdstring("wainting for pulse or event");
//lcdcmd(0x80);
//lcdstring("EVENT NO:");
while(1)
{
lcdcmd(0x01);lcdcmd(0x80);
convert(T0TC);
}
return 0;
}

void lcdstring(char *p)
{
//lcdcmd(0x8f);
while(*p)
{
lcddata(*p);
//lcdcmd(0x1c);
p++;
}
}
void convert(unsigned long int a) //say a=678
{
  sprintf(result,"%d",a);
  lcdcmd(0x80);
  lcdstring("EVENT NO:");
  lcdstring(result);
  delay(2000);
  return;

}
void lcdinit()
{
lcdcmd(0x02);
lcdcmd(0x28);
lcdcmd(0x01);
lcdcmd(0x0e);
lcdcmd(0x80);
}
void lcdcmd(char ch)
{
lcdport = ((ch&0xf0)<<15);
cmnd();
lcdportclr = ((ch&0xf0)<<15);

lcdport = (((ch<<4)&0xf0)<<15);
cmnd();
lcdportclr = (((ch<<4)&0xf0)<<15);
}

void lcddata(char ch)
{
lcdport = ((ch&0xf0)<<15);
daten();
lcdportclr = ((ch&0xf0)<<15);

lcdport = (((ch<<4)&0xf0)<<15);
daten();
lcdportclr = (((ch<<4)&0xf0)<<15);
}
void cmnd()
{
lcdportclr = (1<<rs);
lcdportclr = (1<<rw);
lcdport = (1<<en);
delay(1);
lcdportclr = (1<<en);
delay(2);
}
void daten()
{
lcdport = (1<<rs);
lcdportclr = (1<<rw);
lcdport = (1<<en);
delay(1);
lcdportclr = (1<<en);
delay(5);
}

void delay(int ms)
{
T1CTCR=0x00;
T1TC=0;
T1PC=0;
T1PR=59999;
T1TCR=0x02;
T1TCR=0x01;
while( T1TC != ms);
T1TCR=0;
}
void pllinit()
{
 PLL0CFG=0x24;
 PLL0CON=PLL0CON|(1<<PLLE);
 PLL0FEED=0xAA;
 PLL0FEED=0x55;
 //PLL0CON=PLL0CON|(1<<PLLC);
 while( (PLL0STAT & (1<<PLOCK))==0);
 PLL0CON=PLL0CON|3;
 PLL0FEED=0xAA;
 PLL0FEED=0x55;
 VPBDIV=0x01;
}

GSM Based System:

GSM Based System:

Code:


#include<lpc214x.h>
#include<string.h>
#define THRE 5
#define TEMT 6
#define RDR 0
#define PLOCK 10
#define DLAB 7

#define lcdport IO0SET
#define lcdportclr IOCLR0
#define rs 16
#define rw 17
#define en 18
void uart0_init()
{
PINSEL0|=5;
U0LCR=0x83;
U0DLL=97;
U0DLM=0x00;
U0LCR=U0LCR&~(1<<DLAB);
}
void delay(int ms)
{
T1CTCR=0x00;
T1TC=0;
T1PC=0;
T1PR=59999;
T1TCR=0x02;
T1TCR=0x01;
while( T1TC != ms);
T1TCR=0;
}

void cmnd()
{
lcdportclr=(1<<rs);
lcdportclr = (1<<rw);
lcdport = (1<<en);
delay(4);
lcdportclr=(1<<en);
}
void lcdcmd(char ch)
{
lcdport = ((ch&0xf0)<<15);
cmnd();
lcdportclr = ((ch&0xf0)<<15);

lcdport = (((ch<<4)&0xf0)<<15);
cmnd();
lcdportclr = (((ch<<4)&0xf0)<<15);
}

void daten()
{
lcdport=(1<<rs);
lcdportclr = (1<<rw);
lcdport = (1<<en);
delay(4);
lcdportclr=(1<<en);
}

void lcddata(char ch)
{
lcdport = ((ch&0xf0)<<15);
daten();
lcdportclr = ((ch&0xf0)<<15);

lcdport = (((ch<<4)&0xf0)<<15);
daten();
lcdportclr = (((ch<<4)&0xf0)<<15);
}

void lcdstring(char *str)
{
int j;
for(j=0;str[j]!='\0';j++)
{
lcddata(str[j]);
}
}
void lcd_init()
{
lcdcmd(0x02);
lcdcmd(0x28);
lcdcmd(0x01);
lcdcmd(0x0e);
}
void clk_init()
{
PLL0CON=0x01;
PLL0CFG=0x24;
PLL0FEED=0xAA;
PLL0FEED=0x55;
while(!(PLL0STAT & (1<<PLOCK)));
PLL0CON=0x3;
PLL0FEED=0xAA;
PLL0FEED=0x55;
VPBDIV=0x00;
}
void txdata(char ch)
{
U0THR=ch;
while(!(U0LSR & (1<<TEMT)));
}
void txstring(char *str)
{
while(*str)
{
txdata(*str);
U0FCR=0x07;
str++;
}
}


int main()
{
PINSEL0=0x05;
PINSEL2=0x00;

IODIR0=0xfffffff<<2;
clk_init();
lcd_init();
  uart0_init();
//while(1)
{
 lcdcmd(0x01);
 lcdstring("GSM APPLICATION");
txstring("AT\r\n");
delay(100);
txstring("AT+CMGF=1\r\n");
delay(100);
txstring("AT+CMGS=");
txdata(0x22);
txstring("+918888888888");
 delay(10);
txdata(0x22);
txdata('\r');
delay(100);
txstring("welcome to all");
txdata(0x1a);
while(1);
}
}


Simulation:





RFID Attendence System

RFID Attendence System:


Code:


#include<lpc214x.h>
#include<string.h>
#define PLLE 0
#define PLLC 1
#define PLOCK 10
#define DLAB 7
#define TEMT 6
#define DR 0
#define rs 16
#define rw 17
#define en 18
#define lcdport IO0SET
#define lcdportclr IO0CLR
void pll_init(void);
void delay(int);
void uart0_init(void);
void lcd_init(void );
void daten(void);
void cmnd(void);
void delay(int);
void lcdcmd(char);
void lcddata(char);
void lcdstring(char *);
char emp1[]="1600669C55B0";
char emp2[]="160066C78555";
char emp3[]="160055083149";
char emp4[]="110000342F04";
char id[12];
int i;
int main()
{
pll_init();
uart0_init();
lcd_init();
xyz: lcdcmd(0x01);lcdcmd(0x80);
  lcdstring("PLACE CARD");delay(100);
  while(1)
{
for(i=0;i<=11;i++)
{
   while( (U0LSR & (1<<DR)) ==0);
      id[i]=U0RBR;
    }
      id[i]='\0';

if((strcmp(id,emp1)==0))
{
lcdcmd(0x01);lcdcmd(0xc0);
lcdstring("U R EMP1");delay(500);
}
else if((strcmp(id,emp2)==0))
{
lcdcmd(0x01);lcdcmd(0xc0);
lcdstring("U R EMP2");delay(500);
}
else if((strcmp(id,emp3)==0))
{
lcdcmd(0x01);lcdcmd(0xc0);
lcdstring("U R EMP3");delay(500);
}
else if((strcmp(id,emp4)==0))
{
lcdcmd(0x01);lcdcmd(0xc0);
lcdstring("U R EMP4");delay(500);
}
else{
  lcdcmd(0x01);lcdcmd(0xc0);
lcdstring("WORONG ENTRY");delay(500);
}
  goto xyz;
  }
return 0;
}
void uart0_init()
{
PINSEL0|=5;
U0LCR=0x83;
U0DLL=97;
U0DLM=0x00;
U0LCR=U0LCR&~(1<<DLAB);
}
void pll_init()
{
 PLL0CFG=0x24;
 PLL0CON=PLL0CON|(1<<PLLE);
 PLL0FEED=0xAA;
 PLL0FEED=0x55;
 //PLL0CON=PLL0CON|(1<<PLLC);
 while( (PLL0STAT & (1<<PLOCK))==0);
 PLL0CON=PLL0CON|3;
 PLL0FEED=0xAA;
 PLL0FEED=0x55;
 VPBDIV=0x00;
}
void delay(int ms)
{
T1CTCR=0x00;
T1TC=0;
T1PC=0;
T1PR=59999;
T1TCR=0x02;
T1TCR=0x01;
while( T1TC != ms);
T1TCR=0;
}
void lcd_init()
{
IO0DIR=IO0DIR|(0x7f<<16);
lcdcmd(0x02);
lcdcmd(0x28);
lcdcmd(0x01);
lcdcmd(0x0e);
lcdcmd(0x80);
}
void lcdcmd(char ch)
{
lcdport = ((ch&0xf0)<<15);
cmnd();
lcdportclr = ((ch&0xf0)<<15);

lcdport = (((ch<<4)&0xf0)<<15);
cmnd();
lcdportclr = (((ch<<4)&0xf0)<<15);
}

void lcddata(char ch)
{
lcdport = ((ch&0xf0)<<15);
daten();
lcdportclr = ((ch&0xf0)<<15);

lcdport = (((ch<<4)&0xf0)<<15);
daten();
lcdportclr = (((ch<<4)&0xf0)<<15);
}
void cmnd()
{
lcdportclr = (1<<rs);
lcdportclr = (1<<rw);
lcdport = (1<<en);
delay(1);
lcdportclr = (1<<en);
delay(2);
}
void daten()
{
lcdport = (1<<rs);
lcdportclr = (1<<rw);
lcdport = (1<<en);
delay(1);
lcdportclr = (1<<en);
delay(2);
}

void lcdstring(char  *x)
{
while( *x != '\0')
{
lcddata(*x);
x++;
}
}

Simulation:




Friday, 16 September 2016

LINE_FOLLOWER

LINE_FOLLOWER:


Code:



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

void main()
{
DDRD=0b00000000;   //set PORTC as input port
DDRC=0b00111100;  //PB1, PB2, PB3, PB4 as output port
int ls=0, rs=0;   // define & initialize ls, rs integer as 0 to
// acquire the left sensor status in ls and right sensor
// status in rs
PORTD=0XFF;
while(1)          // create infinite loop
{
ls=(PIND&0b0000001);   //acquire only left sensor status connected at PC0
rs=(PIND&0b0000010);   // acquire only right sensor status connected at PC3

if((ls==0b0000000)&(rs==0b0000000)) //check sensor status for both sensor OFF
{
PORTC=0b00000000;  //stop
_delay_ms(1000);
PORTC=0b00101000;
_delay_ms(500);
PORTC=0b00000100;
_delay_ms(500);
ls=0;              //set sensor status off
rs=0;              //set sensor status off
}

else if((ls==0b0000001)&(rs==0b0000000))  //check sensor status for left sensor=ON and
// right sensor=OFF
{

PORTC=0b00000000;
_delay_ms(200);
PORTC=0b00101000;
_delay_ms(500);
PORTC=0b00000100;    //turn right
_delay_ms(400);
ls=0;                //set sensor status off
rs=0;                //set sensor status off
}

else if((ls==0b0000000)&(rs==0b00000010))  //check sensor status for left sensor=OFF and
// right sensor=ON
{
PORTC=0b00000000;
_delay_ms(200);
PORTC=0b00101000;
_delay_ms(500);
PORTC=0b00010000;   //turn left
_delay_ms(400);
ls=0;               //set sensor status off
rs=0;               //set sensor status off
}

else if((ls==0b0000001)&(rs==0b0000010)) //check sensor status for both sensor ON
{
PORTC=0b00010100;  //move forward
ls=0;              //set sensor status off
rs=0;              //set sensor status off
}
}
}



Simulation:







Mobile_Controlled_Robot

 Mobile_Controlled_Robot:


Code:


#include <avr/io.h>

#define key2 0xfd
#define key4 0xfb
#define key6 0xf9
#define key8 0xf7
#define key5 0xfa

#define left 0x01
#define right 0x02
#define forward 0x03
#define reverse 0x0c
#define stop 0x00

#define key PINA
#define direction PORTC

int main(void)
{
DDRA=0xf0;
DDRC=0xff;
    while(1)
    {
PORTA=0xff;
      if(key==key2)
 direction=forward;

 else if(key==key4)
 direction=left;

 else if(key==key6)
 direction=right;

 else if(key==key8)
 direction=reverse;

 else if(key==key5)
 direction= stop;
    }
}


Circuit Diagram:




Layout:







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:






Voting_Machine:

Voting_Machine:

 Code:


#include <avr/io.h>
#include"lcd_header.h"

#define bjp PD3
#define aap PD4
#define cong PD5
#define oth PD6
#define results PD2
#define party PIND
#define vote PORTC

#define buzzer PA7

unsigned int count1,count2,count3,count4;
unsigned char result1[3],result2[3],result3[3],result4[3];
int temp=0;
char rfid[13];

void clear();
void serialinit()
{
UCSRB=0x18;
UCSRC=0x86;
UBRRL=0x33;
}

void beep()
{
PORTA|=1<<buzzer;
_delay_ms(200);
PORTA&=~(1<<buzzer);
}

void beep_long()
{
PORTA|=1<<buzzer;
_delay_ms(1000);
PORTA&=~(1<<buzzer);
}

int main(void)
{
DDRB=0xff;
DDRD=0x00;
DDRC=0xff;
DDRA=0xff;
lcd_init();
lcdstring("  Electronic  ");
lcdcmd(192);
lcdstring("Voting Machine");
beep_long();
beep();

_delay_ms(2000);
clear();
serialinit();
    while(1)
    {

lcdcmd(1);
lcdstring("Place UR Card:");
for(int i=0;i<12;i++)
{
while(!(UCSRA & (1<<RXC)));
rfid[i]=UDR;
}
rfid[12]='\0';
beep();
beep();
lcdcmd(1);
lcdstring("Your Card No is:");
lcdcmd(192);
lcdstring(rfid);
_delay_ms(2000);
if(strncmp(rfid, "1100006BB3C9",12)==0)
{
beep();
lcdcmd(1);
lcdstring("Authorized Voter");
lcdcmd(192);
lcdstring("Pls Cast UR Vote");
_delay_ms(2000);
//clear();
temp=1;
voting(temp);

}

else if(strncmp(rfid, "1600664C0E32",12)==0)
{
beep();
lcdcmd(1);
lcdstring("Authorized Voter");
lcdcmd(192);
lcdstring("Pls Cast ur Vote");
_delay_ms(2000);
//clear();
temp=1;
voting(temp);
}

else if(strncmp(rfid, "16006616C1A7",12)==0)
{

beep();
lcdcmd(1);
lcdstring("Please Press");
lcdcmd(192);
lcdstring("Result Button");
PORTD=0xFF;
while((party&(1<<results)));
if(!(party&(1<<results)))
{
beep();
if(count1 || count2 || count3 || count4)
{
if(count1 > count2 && count1>count3  && count1>count4)
Result("BJP Won");
else if(count2 > count1 && count2 > count3 && count2>count4)
Result("AAP Won");
else if(count3 > count2 && count3 > count1  && count3 > count4)
Result("Cong Won");
else if(count4 > count2 && count4 > count1  && count4 >count3)
Result("Oth Won");
else if(count1 == count2 || count3==count4  || count3 ==count1 || count2==count4)
Result("Tie");
}

else
{
beep_long();
lcdcmd(1);
lcdstring("No Voting...");
_delay_ms(2000);
clear();
}

beep();
}
_delay_ms(1000);

}

else
{
PORTA|=1<<PA7;
lcdcmd(1);
lcdstring("  UnAuthorised  ");
lcdcmd(192);
lcdstring("     Voter      ");
_delay_ms(2000);
PORTA&=~(1<<PA7);  // buzzer
}
}

}

void voting(int temp)
{
lcdcmd(1);
lcdstring("BJP AAP Cong OTH");
while(temp)
{
PORTD=0xff;
lcdcmd(0xc1);
lcdstring(result1);
lcdcmd(0xc5);
lcdstring(result2);
lcdcmd(0xc9);
lcdstring(result3);
lcdcmd(0xcd);
lcdstring(result4);
if(!(party&(1<<bjp)))
{
beep();
count1++;
sprintf(result1,"%d",count1);
while(!(party&(1<<bjp)));
temp=0;
}

else if(!(party&(1<<aap)))
{
beep();
count2++;
sprintf(result2,"%d",count2);
while(!(party&(1<<aap)));
temp=0;
}

else if(!(party&(1<<cong)))
{
beep();
count3++;
sprintf(result3,"%d",count3);
while(!(party&(1<<cong)));
temp=0;
}

else if(!(party&(1<<oth)))
{
beep();
count4++;
sprintf(result4,"%d",count4);
while(!(party&(1<<oth)));
temp=0;
}


}
_delay_ms(1000);
}


void Result(char *str)
{
lcdcmd(1);
lcdstring(str);
    clear();
}

void clear()
{
count1=0;
count2=0;
count3=0;
count4=0;
sprintf(result1, "%d", count1);
sprintf(result2, "%d", count2);
sprintf(result3, "%d", count3);
sprintf(result4, "%d", count4);
_delay_ms(2000);
lcdcmd(1);
lcdstring("BJP AAP Cong OTH");
}



lcd_header:



#define F_CPU 8000000UL
#include <util/delay.h>
#define rs 0
#define rw 1
#define en 2
void cmnd()
{
PORTB&=(~(1<<rs));
PORTB&=(~(1<<rw));
PORTB|=(1<<en);
_delay_ms(5);
PORTB&=(~(1<<en));
}
void lcdcmd(char ch)
{
PORTB=ch & 0xf0;
cmnd();
PORTB=(ch<<4) & 0xf0;
cmnd();
}
void lcd_init()
{
lcdcmd(0x02);
lcdcmd(0x28);
lcdcmd(0x01);
lcdcmd(0x0e);
}
void data()
{
PORTB|=(1<<rs);
PORTB&=(~(1<<rw));
PORTB|=(1<<en);
_delay_ms(5);
PORTB&=(~(1<<en));
}
void lcddata(char ch)
{
PORTB=ch & 0xf0;
data();
PORTB=(ch<<4) & 0xf0;
data();
}
void lcdstring(char *str)
{
while(*str)
{
lcddata(*str);
str++;
}
}


Simulation:


DTMF_controlled_home_appliances

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;
}


Simulation:





Digital_Thermometer

Digital_Thermometer:


Code:


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

unsigned char arr1[10]={0X3F,0X06,0X5B,0X4F,0X66,0X6D,0X7D,0X07,0X7F,0X6F};
#include <inttypes.h>
unsigned int i,j;
void initadc()
{
ADMUX=(1<<REFS0);
ADCSRA=(1<<ADEN) | (1<<ADPS2) | (1<<ADPS1) | (1<<ADPS0);
}

uint16_t ReadADC(uint8_t ch)
{
//Select ADC Channel ch must be 0-7
//ch=ch&0b00000111;
ADMUX=0xc0;
//Start Single conversion
ADCSRA|=(1<<ADSC);
//Wait for conversion to complete
while(!(ADCSRA & (1<<ADIF)));
//Clear ADIF by writing one to it
ADCSRA|=(1<<ADIF);
return(ADC);
}

void show(int k)
{
switch(k)
{
case 0:
PORTB=0x01;
PORTD=~arr1[i];
_delay_us(20);
break;

case 1:
PORTB=0x02;
PORTD=~arr1[j];
_delay_us(10);
break;

}
}

void convert(int k)
{
   i=k/10;
   j=k%10;
   for(int l=0;l<50;l++)
   {
    for(int k=0;k<2;k++)
    {
     show(k);
_delay_us(100);
    }
   }  
}

int main(void)
{
int temp=0;
int result=0;
DDRB=0xff;
DDRD=0xff;
   // DDRC=0xff;
uint16_t adc_result[10];
initadc();
while(1)
{
for(int n=0;n<10;n++)
adc_result[n]=ReadADC(0);
for(int n=0;n<10;n++)
temp=temp+adc_result[n];
result=temp/40;
convert(result);
result=0;
temp=0;
//_delay_ms(1);
}
}


Simulation:




Bluetooth_controlled_robot

 Bluetooth_controlled_robot:


Code:


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

#define forward 0x14
#define backward 0x28
#define left 0x10
#define right 0x04
#define stop 0x00;

#define motor PORTC

char str[3],i=0;

void serialinit()
{
UCSRB=0x18;
UCSRC=0x86;
UBRRL=0x33;
}

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

void txstring(char *ptr)
{
  while(*ptr)
  {
 send(*ptr);
 ptr++;
  }
}

void rxdata()
{
   while(!(UCSRA & (1<<RXC)));
   char temp=UDR;
   str[i++]=temp;
}

int main(void)
{
DDRC=0xff;
serialinit();
    while(1)
    {
        rxdata();
if(str[i-1]=='1')
{
motor=forward;
txstring("Moving Forward\r\n");
i=0;
}

else if(str[i-1]=='2')
{
motor=left;
txstring("Moving left\r\n");
i=0;
}

else if(str[i-1]=='3')
{
motor=right;
txstring("Moving right\r\n");
i=0;
}

else if(str[i-1]=='4')
{
motor=backward;
txstring("Moving Reverse\r\n");
i=0;
}

else if(str[i-1]=='5')
{
motor=stop;
txstring("Stop\r\n");
i=0;
}
    }
}


Simulation: