gauravkothari23
Advanced Member level 2
Hi all...
i need a small help from you all...
i am trying to make a electronic locker...
code is
the working is somewhat like....
at initial stage when you start the system... it enters idle mode...
so now when you press on button connected at INT0 it exits the idle mode and prints "ENTER NEW 4 DIGIT USER ID".
once you enter the new user id it again enters the idle mode.
so now when you again press the on button (INT0) it display "USER ID:"
but at that stage if i press "A" (assigned as off button) from Keypad it again enter the idle mode... and then again if i press on button it displays "USER ID"(which he has to) and if againi press off button it enters idle mode... if i go on doing this for nearly 70 to 80 times... the system RESETS and displays "ENTER NEW 4 DIGIT USER ID".which he asked at initail stage...
why is this happeining...
please help me....
i need a small help from you all...
i am trying to make a electronic locker...
code is
Code:
#include<reg51.h>
#include<stdio.h>
sbit row0=P0^4; //assigning PORT-0 to read rows
sbit row1=P0^5; //assigning PORT-0 to read rows
sbit row2=P0^6; //assigning PORT-0 to read rows
sbit row3=P0^7; //assigning PORT-0 to read rows
sfr COL=0xA0; //assigning PORT-2 to read colomns
sfr ldata=0x90; //assigning PORT-1 for LCD data
sbit rs=P0^0;
sbit rw=P0^1;
sbit en=P3^0;
sbit busy=P1^7;
sbit batind = P0^3;
sbit syslock=P3^7;
sbit buzzer=P3^1;
sbit stepup=P0^2;
sbit dc0=P3^4;
sbit dc1=P3^5;
sbit l293d=P3^6;
void timer(unsigned int msec);
void lcdcmd(unsigned char value) ;
void lcddata(unsigned char value);
void lcdready(void) ;
void printstring(unsigned char ch[]) ;
void lcdclear(void);
void msdelay(unsigned int value) ;
int keypad();
void door_open();
void lock();
void door_close();
void setpassprog();
void newpassword();
void newpasswordlong();
void userpassprog();
void counting();
void systemlock();
unsigned char userid[5]={"0000"};
unsigned char password[5]={"0000"};
unsigned char chanuser[5]={"0000"};
unsigned char chanpass[5]={"0000"};
unsigned char syspass[17]={"0000000000000000"};
unsigned char sysupt[17]= {"0000000000000000"};
unsigned char x;
unsigned char cancel[2]={"0"};
unsigned char count[2]={"0"};
unsigned char fig[2]={"3"};
unsigned char ex0_isr_counter = 0; // interrupt
void ex0_isr (void) interrupt 0
{
ex0_isr_counter++;
}
void timer(unsigned int msec) // Function for timer
{
unsigned int i;
for(i=0;i<msec;i++)
{
TMOD=0x20; // Mode2
TH1=0xD1;
TL1=0xFF;
TR1=1;
while(TF1==0);
TF1=0;
TR1=0;
}
}
void lcdcmd(unsigned char value) //LCD command
{
lcdready();
ldata=value;
rs=0;
rw=0;
en=1;
msdelay(10);
en=0;
}
/* sending commnad to LCD to display characters*/
void lcddata(unsigned char value) // LCD data
{
lcdready();
ldata=value;
rs=1;
rw=0;
en=1;
msdelay(20);
en=0;
}
/* checking LCD buffer for free */
void lcdready(void) // LCD ready
{
busy=1;
rs=0;
rw=1;
if(busy==1)
{
en=0;
msdelay(1);
en=1;
}
}
void printstring(unsigned char ch[]) // Print to LCD
{
unsigned int i;
for(i=0;ch[i]!='\0';i++)
lcddata(ch[i]);
}
/* generating delay*/
void msdelay(unsigned int value) // Delay
{
unsigned int i,j;
for(i=0;i<value;i++)
for(j=0;j<100;j++);
}
void LCDclear(void)
{
lcdcmd(0x01);
}
int keypad()
{
unsigned char dat[4][4]={'1','2','3','A', // assigning key matrix
'4','5','6','B',
'7','8','9','-',
'C','0','=','+',
};
unsigned char colloc,rowloc;
COL=0xFF;
row0=0;
row1=0;
row2=0;
row3=0;
rs=0;
rw=0;
en=0;
busy=0;
/* setting LCD screen*/
ldata=0x00;
lcdcmd(0x38);
lcdcmd(0x0E);
lcdcmd(0x06);
while(1)
{
/* reading character from keyboard */
do
{
row0=0;
row1=0;
row2=0;
row3=0;
colloc=COL;
colloc&=0x0F;
}while(colloc!=0x0F);
do
{
do
{
msdelay(10);
colloc=COL;
colloc&=0x0F;
}while(colloc==0x0F);
msdelay(10);
colloc=COL;
colloc&=0x0F;
}while(colloc==0x0F);
while(1)
{
row0=0;
row1=1;
row2=1;
row3=1;
msdelay(5);
colloc=COL;
colloc&=0x0F;
if(colloc!=0x0F)
{
rowloc=0;
break;
}
row0=1;
row1=0;
row2=1;
row3=1;
msdelay(5);
colloc=COL;
colloc&=0x0F;
if(colloc!=0x0F)
{
rowloc=1;
break;
}
row0=1;
row1=1;
row2=0;
row3=1;
msdelay(5);
colloc=COL;
colloc&=0x0F;
if(colloc!=0x0F)
{
rowloc=2;
break;
}
row0=1;
row1=1;
row2=1;
row3=0;
msdelay(5);
colloc=COL;
colloc&=0x0F;
if(colloc!=0x0F)
{
rowloc=3;
break;
}
}
if(colloc==0x0E)
return(dat[rowloc][0]);
else if(colloc==0x0D)
return(dat[rowloc][1]);
else if(colloc==0x0B)
return(dat[rowloc][2]);
else
return(dat[rowloc][3]);
}
}
void main(void)
{
unsigned int i;
lcdcmd(0x38);
lcdcmd(0x0F);
lcdcmd(0x06);
lcdcmd(0x01);
while(1)
{
batind=1;
syslock=1;
stepup=1;
l293d=1;
IT0=0;
EX0 = 1;
EA = 1;
PCON |= 0x01;
lcdcmd(0x80);
printstring("ENTER NEW 4 DIGIT");
lcdcmd(0xC0);
printstring("USER-ID:");
do
{
userid[i]=keypad();
if
(userid[i]=='A')
{
return;
}
lcddata(userid[i]);
i++;
}
while(i!=4);
i=0;
msdelay(1000);
userpassprog();
}
}
void userpassprog() // User Pass Prog
{
unsigned int i;
lcdcmd(0x38);
lcdcmd(0x0F);
lcdcmd(0x06);
lcdcmd(0x01);
while(1)
{
batind=1;
syslock=1;
stepup=1;
l293d=1;
IT0=0;
EX0 = 1;
EA = 1;
PCON |= 0x01;
lcdcmd(0x80);
printstring("USER ID:");
do
{
chanuser[i]=keypad();
if
(chanuser[i]=='C')
{
userpassprog();
}
if
(chanuser[i]=='A')
{
lcdclear();
userpassprog();
}
lcddata(chanuser[i]);
i++;
}
while(i!=4);
i=0;
if(chanuser[0]==userid[0] && chanuser[1]==userid[1] && chanuser[2]==userid[2] && chanuser[3]==userid[3] )
{
printstring("PASSWORD");
}
}
}
at initial stage when you start the system... it enters idle mode...
so now when you press on button connected at INT0 it exits the idle mode and prints "ENTER NEW 4 DIGIT USER ID".
once you enter the new user id it again enters the idle mode.
so now when you again press the on button (INT0) it display "USER ID:"
but at that stage if i press "A" (assigned as off button) from Keypad it again enter the idle mode... and then again if i press on button it displays "USER ID"(which he has to) and if againi press off button it enters idle mode... if i go on doing this for nearly 70 to 80 times... the system RESETS and displays "ENTER NEW 4 DIGIT USER ID".which he asked at initail stage...
why is this happeining...
please help me....