Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

password access (PIC16F877A) using keypad

Status
Not open for further replies.

toto_na16

Member level 1
Joined
Feb 21, 2010
Messages
34
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,286
Location
Egypt
Activity points
1,478
Hi,

I want to make a password access system (user to input a password using 4*4 keypad )

but i would like to know how to store consecutive numbers and then restore them

example :

user input 1 , then input 5 , 9, 8

how to store this input as a one string "1598" ?

 

I don't know give us a clue
There is not a lot of info there for helping for starters what langauge your trying to do it in and where are you stuck
 

i am using MikroC

generally i don't know how to take this consecutive inputs and put them as a single string .

do you get it ?
 

well take this code as an example:

Code:
        #include "PIC_lcd_keyb.h" //my lib...
        
	#define relay  PORTA.F4

char pass[4];
const char truepass[4]={1,2,3,4};
char comparar();

	void main()
	{ char i;
		TRISB=0;
		TRISA=0x0F;
		CMCON=7; //no olvidarse!!!
		my_lcd_init();
		while(1)
		{		my_lcd_clear();
				my_lcd_print("Password:");
				my_lcd_cmd(0x80+0x40);	//segunda línea
				for(i=0;i<4;i++)
				{
					pass[i]=teclado();
					my_lcd_chr('*');
				}
				my_lcd_clear();
				my_lcd_print("comparando...");
				if (comparar())
				{
					my_lcd_clear();
					my_lcd_print("EXITO!!!");
					relay=1;
					delay_ms(5000);
				}
				else
				{
					my_lcd_clear();
					my_lcd_print("ERROR!!!");
					relay=0;
					delay_ms(5000);

				}
		}
	}


	char comparar()
	{
		char i;
		for (i=0;i<4;i++)
			if (pass[i]!=truepass[i]) break;
		if (i==4)
			return 1;
		else
			return 0;
	}

see how it has a default password, and an array for the input (which is done with the teclado() function) it's filled with a simple for(i) and then compared (comparar() at the bottom...)

maybe it helps something...
 

Kurenai_ryu said:
well take this code as an example:

Code:
        #include "PIC_lcd_keyb.h" //my lib...
        
	#define relay  PORTA.F4

char pass[4];
const char truepass[4]={1,2,3,4};
char comparar();

	void main()
	{ char i;
		TRISB=0;
		TRISA=0x0F;
		CMCON=7; //no olvidarse!!!
		my_lcd_init();
		while(1)
		{		my_lcd_clear();
				my_lcd_print("Password:");
				my_lcd_cmd(0x80+0x40);	//segunda línea
				for(i=0;i<4;i++)
				{
					pass[i]=teclado();
					my_lcd_chr('*');
				}
				my_lcd_clear();
				my_lcd_print("comparando...");
				if (comparar())
				{
					my_lcd_clear();
					my_lcd_print("EXITO!!!");
					relay=1;
					delay_ms(5000);
				}
				else
				{
					my_lcd_clear();
					my_lcd_print("ERROR!!!");
					relay=0;
					delay_ms(5000);

				}
		}
	}


	char comparar()
	{
		char i;
		for (i=0;i<4;i++)
			if (pass[i]!=truepass[i]) break;
		if (i==4)
			return 1;
		else
			return 0;
	}

see how it has a default password, and an array for the input (which is done with the teclado() function) it's filled with a simple for(i) and then compared (comparar() at the bottom...)

maybe it helps something...

ok i will try to use this method thanks for help , i will inform you what happened

Added after 18 minutes:

I wrote this code but i got an error
:
assigning to a non-Ivalue[] in the line
( Epass=Keypad_Released();)

Code:
const char Tpass[5] = {1,2,3,4,5};
const Epass[5];
char i;
char compare();
void main(){
     TRISD=0x00;
     TRISB=0xFF;
     Keypad_Init(&PORTB);
     Lcd_Custom_Config(&PORTD,7,6,5,4,&PORTD,2,0,3);
     Lcd_Custom_Out(1,3,"enter password :");
     delay_ms(1000);
     Lcd_Custom_Chr(3,4,':');
     while(1){
              for(i=0;i<5;i++){
                               Epass[i]=Keypad_Released();
                               Lcd_Custom_Chr_Cp('*');
                               }
              if(compare()){
                            LCD_Custom_Cmd(LCD_Clear);
                            Lcd_Custom_Out(1,3,"true");
                            }
              else          {
                            LCD_Custom_Cmd(LCD_Clear);
                            Lcd_Custom_Out(1,3,"false");
                            }
              }
}

char compare()
              {

               for (i=0;i<5;i++)
                                 if (Epass[i]!=Tpass[i]) break;
               if (i==5)
                     return 1;
               else
                     return 0;
   }
 

CHANGE

const Epass[5];

to

char Epass[5];

basically you can't change constant values...
 

Kurenai_ryu said:
CHANGE

const Epass[5];

to

char Epass[5];

basically you can't change constant values...

hahaha what a stupid error :D

Added after 19 minutes:

LCD is showing strange output :!:

this is my Proteus schematic
 

Saw your Proteus schematic.
You should give us your hex to simulate.
MCLR is not connected = constant reset?
No OSC as well.
 

Shinnster said:
Saw your Proteus schematic.
You should give us your hex to simulate.
MCLR is not connected = constant reset?
No OSC as well.

hex is attached .

MCLR and OSC is not required for simulation . (this is not the first time )
 

hi,

this can also be done with more simple way i think :)

Take user 1 in one varible and take his password in another variable.

use string concatinate to merge both the values.

use string compare function to see, if both are same or not.

I hope this should work..

What u say, correct me if i'm worng....
 

raviraj.jr said:
hi,

this can also be done with more simple way i think :)

Take user 1 in one varible and take his password in another variable.

use string concatinate to merge both the values.

use string compare function to see, if both are same or not.

I hope this should work..

What u say, correct me if i'm worng....

sorry, but i don't get what you are trying to say ?
 

it's a keypad issue,

i'm not sure if it's MikroC problem,
or just Proteus problem,

if you can build it, maybe it will work...

if it doesn't, just change the keypad functions...

Added after 7 minutes:

Code:
const char Teclas[4][4]={      {7,8,9,'/'},
                               {4,5,6,'*'},
                               {1,2,3,'-'},
                               {'c',0,'=','+'}};
char Leer_Teclado()
{char i,j,l;
  PORTB=0xE0;
  for (i=0;i<4;i++)
  {
  delay_ms(1);
  l=PORTB;
  if ((l & 0xf) != 0xf)
     {
        for(j=0;j<4;j++)
        {if(l.F0==0) return Teclas[j][i];
         l=l>>1;}
     }
  PORTB=(PORTB & 0xF0)<<1 | 0x10;
  }
  return 0xff;
}

char teclado()
{	char tecla;
   do
   {
   tecla=Leer_Teclado();
   } while (tecla ==0xff);     //wait here
   while(Leer_Teclado()!=0xff); //add debouncing here
   return tecla;
}

//keypad init is just TRISB=0x0F;
//and don't forget to set PULL-ups over RB0-RB3
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top