0% found this document useful (0 votes)
48 views

Program Flow

Uploaded by

brain stome
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

Program Flow

Uploaded by

brain stome
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

PROGRAM FLOW:-

#define CPU 12000000UL


#include<avr/io.h>
#include<util/delay.h>
#define BIT0 0x01
#define BIT1 0x02
#define BIT2 0x04
#define BIT3 0x08
#define BIT4 0x10
#define BIT5 0x20
#define BIT6 0x40
#define BIT7 0x80
#define CHECKBIT(x,b) (x&b)
#define SETBIT(x,b) x=x|b
#define CLEARBIT(x,b) x=x&(~b)
#define TOGGLEBIT(x,b) x=x^b

int i,j,a[7];
int y;
//function for swapping lsbyte and msbyte of data
unsigned char xch(unsigned char data1)
{
unsigned char temp,temp1;
temp=data1;
data1=data1>>4;
temp1=data1;
data1=temp;
data1=data1<<4;
data1=data1|temp1;
return(data1);
}

void datatr(unsigned char data1)


{
unsigned char c;
c=data1&0x01;
SETBIT(DDRC,BIT4);
if(CHECKBIT(c,BIT0))
SETBIT(PORTC,BIT4);
else
CLEARBIT(PORTC,BIT4);
c=data1&0x02;
SETBIT(DDRC,BIT5);
if(CHECKBIT(c,BIT1))
SETBIT(PORTC,BIT5);
else
CLEARBIT(PORTC,BIT5);
c=data1&0x04;
SETBIT(DDRC,BIT6);
if(CHECKBIT(c,BIT2))
SETBIT(PORTC,BIT6);
else
CLEARBIT(PORTC,BIT6);
c=data1&0x08;
SETBIT(DDRC,BIT7);
if(CHECKBIT(c,BIT3))
SETBIT(PORTC,BIT7);
else
CLEARBIT(PORTC,BIT7);
}

//function for sending command on lcd


void send_command(unsigned char data1)
{
unsigned char data2;
SETBIT(DDRC,BIT0);
CLEARBIT(PORTC,BIT0); //RS =0
SETBIT(DDRC,BIT1);
CLEARBIT(PORTC,BIT1); //RW =0
SETBIT(DDRC,BIT1);
SETBIT(PORTC,BIT2); //EN =1
_delay_us(10);
data2=xch(data1);
datatr(data2);
SETBIT(DDRC,BIT2);
CLEARBIT(PORTC,BIT2); //EN =0
_delay_us(10);
SETBIT(DDRC,BIT2);
SETBIT(PORTC,BIT2); //EN =1
datatr(data1);
_delay_us(10);
SETBIT(DDRC,BIT2);
CLEARBIT(PORTC,BIT2); //EN =0
_delay_us(10);
SETBIT(DDRC,BIT0);
SETBIT(PORTC,BIT0); //RS =1
}

//function for transmitting data on lcd

void clr_lcd()
{
send_command(0x01);
_delay_us(10);
send_command(0x02);
_delay_us(10);
}

//function for initializing of lcd


void lcdinit()
{
clr_lcd();
send_command(0x28);
send_command(0x28);
send_command(0x28);
send_command(0x06);
send_command(0x0e);
clr_lcd();
}

//function for displaying data on the lcd


void lcd_gotoxy(unsigned char x,unsigned char y)
{
unsigned char firstcharadr[]={0x80, 0xC0, 0x94, 0xD4};
send_command(firstcharadr[y-1] + x - 1);
_delay_us(10);
}

void senddata(unsigned char data1)


{
unsigned char data2;
SETBIT(DDRC,BIT0);
SETBIT(PORTC,BIT0); //RS =1
SETBIT(DDRC,BIT1);
CLEARBIT(PORTC,BIT1); //RW =0
SETBIT(DDRC,BIT1);
SETBIT(PORTC,BIT2); //EN =1
_delay_us(10);
data2=xch(data1);
datatr(data2);
SETBIT(DDRC,BIT2);
CLEARBIT(PORTC,BIT2); //EN =0
_delay_us(10);
SETBIT(DDRC,BIT2);
SETBIT(PORTC,BIT2); //EN =1
datatr(data1);
_delay_us(10);
SETBIT(DDRC,BIT2);
CLEARBIT(PORTC,BIT2); //EN =0
_delay_us(10);
SETBIT(DDRC,BIT0);
CLEARBIT(PORTC,BIT0); //RS =0
}
//function for print data on lcd
void lcd_print(char *str)
{
unsigned char i=0;
while(str[i] !=0)
{
senddata(str[i]);
i++;
}
}

void PASB()
{
PORTD=0x10;
_delay_us(10);
PORTD=0x00;
_delay_us(10);
}
void C_lenth()
{
if(i>7)
{
clr_lcd();
lcd_gotoxy(1,1);
lcd_print("Pass too long");
lcd_gotoxy(1,2);
lcd_print("Press R");
}
}
void inc()
{
C_lenth();
i=i+1;
y=y+1;
_delay_ms(5);
}
int main()
{
int exit=0;
int m=0;
unsigned char k,b[7]={8,8,9,0,8,8,5};
DDRB=0x00;
PINB=0x00;
DDRD=0xF0;
PIND=0xF0;
PORTD=0x00;
//initialize lcd
lcdinit();
lcd_gotoxy(1,1);
lcd_print("P for Pass");
while(1)
{
while(PINB==0x40)
{
for(int n=0;n<=100;n++)
{
PASB();
}
clr_lcd();
lcd_gotoxy(1,1);
lcd_print("Enter pass");
i=0;
y=1;
for(;;)
{
if(PIND==0x02)
{
for(int n=0;n<=200;n++)
{
PASB();
}
i=i-1;
j=i;
goto exit;
}
if(PINB==0x01)
{
if(PINB==0x01)
{
PASB();
lcd_gotoxy(y,2);
lcd_print("1");
}
if(PINB==0x00)
{
a[i]=1;
inc();
}
}
if(PINB==0x02)
{
if(PINB==0x02)
{
PASB();
lcd_gotoxy(y,2);
lcd_print("5");
}
if(PINB==0x00)
{
a[i]=5;
inc();
}
}
if(PINB==0x04)
{
if(PINB==0x04)
{
PASB();
lcd_gotoxy(y,2);
lcd_print("9");
}
if(PINB==0x00)
{
a[i]=9;
inc();
}
}
if(PINB==0x08)
{
if(PINB==0x08)
{
PASB();
lcd_gotoxy(y,2);
lcd_print("0");
}
if(PINB==0x00)
{
a[i]=0;
inc();
}
}
if(PINB==0x10)
{
if(PINB==0x10)
{
PASB();
lcd_gotoxy(y,2);
lcd_print("6");
}
if(PINB==0x00)
{
a[i]=6;
inc();
}
}
if(PINB==0x20)
{
if(PINB==0x20)
{
PASB();
lcd_gotoxy(y,2);
lcd_print("2");
}
if(PINB==0x00)
{
a[i]=2;
inc();
}
}
if(PINB==0x80)
{
if(PINB==0x80)
{
PASB();
lcd_gotoxy(y,2);
lcd_print("7");
}
if(PINB==0x00)
{
a[i]=7;
inc();
}
}
if(PIND==0x01)
{
if(PIND==0x01)
{
PASB();
lcd_gotoxy(y,2);
lcd_print("3");
}
if(PIND==0x00)
{
a[i]=3;
inc();
}
}
if(PIND==0x04)
{
if(PIND==0x04)
{
PASB();
lcd_gotoxy(y,2);
lcd_print("8");
}
if(PIND==0x00)
{
a[i]=8;
inc();
}
}
if(PIND==0x08)
{
if(PIND==0x08)
{
PASB();
lcd_gotoxy(y,2);
lcd_print("4");
}
if(PIND==0x00)
{
a[i]=4;
inc();
}
}
}
exit:
for(k=0;k<=j;k++)
{
if(a[k]==b[k])
{
if(k==j)
{
clr_lcd();
lcd_gotoxy(0,0);
lcd_print("correct pass");
for(int n=0;n<500;n++)
{
PORTD=0x50;
_delay_us(500);
PORTD=0x40;
_delay_us(500);
}
PORTD=0x00;
_delay_ms(1000);
for(int n=0;n<500;n++)
{
PORTD=0x30;
_delay_us(500);
PORTD=0x20;
_delay_us(500);
}
m=1;
}
}
else
{
m=m+1;
if(m==1)
{
clr_lcd();
lcd_gotoxy(1,1);
lcd_print("incorrect pass");
lcd_gotoxy(1,2);
lcd_print("2time leftPRES P");
break;
}
if(m==2)
{
clr_lcd();
lcd_gotoxy(1,1);
lcd_print("incorrect pass");
lcd_gotoxy(1,2);
lcd_print("1time leftPRES P");
break;
}
if(m==3)
{
clr_lcd();
lcd_gotoxy(1,1);
lcd_print("Too many attempt");
lcd_gotoxy(1,2);
lcd_print("DOOR IS LOCKED");
_delay_ms(20);
for(int n=0;n<3;n++)
{
for(int s=0;s<=150;s++)
{
PORTD=0x10;
_delay_us(30);
PORTD=0x00;
_delay_us(30);
}
_delay_ms(70);
}
_delay_ms(10000);
}
}
}
}
}
}

You might also like