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.

[PIC] door Lock using pic16f877a problem , Plz help

Status
Not open for further replies.

last_samurai

Newbie level 5
Joined
May 7, 2014
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
74
hi.

I'm using pic16f877a ,lcd , keypad 4x4,
i wrote a code for door lock
but I'm facing such a problem , i don't know exactly what is that mistake ,

Kindly help me if you can ,
thanks
-----------------------------------------------------------

#define press keypad_key_press()

#define click keypad_key_click()

sbit LCD_RS at RB0_bit;

sbit LCD_EN at RB1_bit;

sbit LCD_D4 at RB4_bit;

sbit LCD_D5 at RB5_bit;

sbit LCD_D6 at RB6_bit;

sbit LCD_D7 at RB7_bit;

sbit LCD_RS_Direction at TRISB0_bit;

sbit LCD_EN_Direction at TRISB1_bit;

sbit LCD_D4_Direction at TRISB4_bit;

sbit LCD_D5_Direction at TRISB5_bit;

sbit LCD_D6_Direction at TRISB6_bit;

sbit LCD_D7_Direction at TRISB7_bit;

char keypadPort at PORTd;

char kb;

char x;

char key_value;

char fromuser[4];

char password[4]={1,2,3,4};

char check;

char *ptr;

char i=0;


void show(char,char);

void init()

{

adcon1=7;

portc=0;

trisc=0;

lcd_init();

lcd_cmd(12);

keypad_init();

}


void startup()

{

portc=0b11111111;

delay_ms(100);

portc=0b00000000;

delay_ms(100);

lcd_out(1,1,"welcome");

delay_ms(200);

lcd_cmd(1);

ptr=&fromuser[0];

}

void main() {

init();

startup();

x=0;


while(kb!=4)

{ // 4 it mean the ON/c button

kb=keypad_key_press();

while(!kb);

fromuser[x]=kb;

show(kb,x);

x++;

}//end while





for(x=0;x<4;x++){lcd_chr(1,2,fromuser[x]+48);} //show saved pass

check=memcmp(fromuser,password,4);

if(check==0)lcd_out(2,2,"matching");

else

lcd_out(2,2,"not matching");


} //end main



void show(char key,char pos)

{

switch(key)

{

case 1:key_value=7;break;

case 2:key_value=4;break;

case 3:key_value=1;break;

case 4:key_value=30;break;

case 5:key_value=8;break;

case 6:key_value=5;break;

case 7:key_value=2;break;

case 8:key_value=0;break;

case 9:key_value=9;break;

case 10:key_value=6;break;

case 11:key_value=3;break;


}

lcd_chr(1,1+pos,key_value+48);





}
 

Does this mikroC Code really Compile? I don't think so.


Code C - [expand]
1
lcd_cmd(12);

This will give error. See help file on using LCD_Cmd() function.
 

Does this mikroC Code really Compile? I don't think so.


Code C - [expand]
1
lcd_cmd(12);

This will give error. See help file on using LCD_Cmd() function.


Hello Milan

lcd_cmd(12) is same as lcd_cmd(_lcd_cursor_off)
u can type Number 12 or _lcd_curosr_off

if u wanna clear the screen u can type lcd_cmd(1) or lcd_cmd(_lcd_clear)

- - - Updated - - -

already can compile , as i mention u can type the number according to the function
u can type lcd_cmd( and press ctrl and space u can see the menu
thanks
 

Yes. you are right. I never had tried that.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
void init()
 
{
 
adcon1=7;
 
cmcon = 0x07;
 
trisa = 0xff;
 
trisb = 0x00;
 
trisd = 0xff;
 
porta = 0x00;
portb = 0x00;
portc = 0x00;
 
portc=0;
 
trisc=0;
 
lcd_init();
 
lcd_cmd(12);
 
keypad_init();
 
}
 
void startup()
 
{
 
portc=0b11111111;
 
delay_ms(100);
 
portc=0b00000000;
 
delay_ms(100);
 
lcd_out(1,1,"welcome");
 
delay_ms(200);
 
lcd_cmd(1);
 
ptr=&fromuser;
 
}
 
 
 
 
while(1) {
 
 
 
    kp = 0;                                
 
  while(kp != 4)  {
    do      
      kp = Keypad_Key_Click();             
    while (!kp);
 
    }
 
    kp = 0;
 
    while(i < pwdLen) {
 
        
        do      
      kp = Keypad_Key_Click();             
    while (!kp);
 
        
        switch(kp)
 
{
 
case 1:key_value=7;break;
 
case 2:key_value=4;break;
 
case 3:key_value=1;break;
 
case 4:key_value=30;break;
 
case 5:key_value=8;break;
 
case 6:key_value=5;break;
 
case 7:key_value=2;break;
 
case 8:key_value=0;break;
 
case 9:key_value=9;break;
 
case 10:key_value=6;break;
 
case 11:key_value=3;break;
 
 
}
 
userPwd[i] = key_value;
 
lcd_chr(1,1+i,'*');
 
++i;
 
 
 
    }
 
 
Delay_ms(2000);
 
i = 0;
 
while(i < pwdLen) {
 
    if(userPwd[i] == password[i])
        matchCounter++;
 
    ++i;
}
 
if(matchCounter == pwdLen) {
 
    //PWD matches
}
else {
 
    //Wrong PWD
}
 
 
 
}

 

thanks my friend for your help ,
i would like to ask about the statement
while(kp != 4) {
do

i ever saw the word do only with out loop
lik do while

I'm did not catch the meaning yet about Do
what is the meaning of it ,
thanks in advance
 

You said ON/C button returns value 4. So, unless you enter 4 (press ON/C) button you will not be allowed to enter password. You don't need switch() { ... } to test ON/C button press because KeyPad_Click() returns 4 if ON/C button is pressed (that is what I assumed). So unless you press ON/C button it will be looping and once 4 is detected then loop breaks and comes to next loop which reads 4 key presses. And after 4 key presses the 2nd loop breaks and goes to third loop where user entered password is compared with stored password. The comparing loop loops length of password times. pwdlen is defined else where in code.

If it doesn't work for you then zip and post mikroC project files and also Proteus file if you have any.
 

yes it show many errors, i gonna attach the mikron and protues files
kindly check the attached zip file.
thanks
 

Attachments

  • keypad.zip
    50.2 KB · Views: 104

It works fine. You have to press ON key and KP unlocks. Then it asks to enter password. Your password is 1234. If 1234 is entered then it shows Password OK message. It shows Wrong Password message on the detection of 1st unmatched password character during password entering process itself that is if you enter 16 then as soon as you enter 6 it shows Wrong Password message. It doesn't wait for you to enter all characters of password to test if it matches with stored password.
 

Attachments

  • keypad.rar
    81 KB · Views: 119
It works fine. You have to press ON key and KP unlocks. Then it asks to enter password. Your password is 1234. If 1234 is entered then it shows Password OK message. It shows Wrong Password message on the detection of 1st unmatched password character during password entering process itself that is if you enter 16 then as soon as you enter 6 it shows Wrong Password message. It doesn't wait for you to enter all characters of password to test if it matches with stored password.


Could u plz attach the mikroc. File
There is many error
Thanks milan
 

its ok now , I'm sorry , I'm did not see the attached file , i tried it right now , its work fine , so later i can compare the enter value with the value of epprom stored password ,

it will by fine , I'm too appreciate for u help , u r too helpful ,

but there is one question , i wanna ask in the code , there is single word do
in the loop

while(kp != 4) {
do
kp = Keypad_Key_Click();
while (!kp);

}


what is the meaning of this word since there is not do while loop as i know should be
do{


}while(condition);

this single word Do , what is the meaning of it in the code
 

it is the small mistack bro always create
do{
}while(condition);

there is no meaning use only do .
 
i got the meaning , its basic of c language (feel shy).

appreciate for all your help thanks again
 

A modified file.

Code:
do 
kp = Keypad_Key_Click(); 
while (!kp);

It is not any mistake. As there is only one statement inside do while loop you don't need the braces. You need braces only if there is more than one statement inside the loop.
 

Attachments

  • keypad_877a.c.txt
    4 KB · Views: 89
thanks Millan

- - - Updated - - -

the code is Quit professional ,
for me as a beginner i feel i need to learn much
because the code is too difficult for me ,

what is u suggestion to write a good code ,
any Book do u suggest for me ?
 

but that depends on compiler or not !!!!!!!!!!!!
 

I'm using mikroc

- - - Updated - - -

and learning pic16f series with mikroc and protues
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top