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.

Simple Combination lock Project with keypad and LCD

Status
Not open for further replies.

nuwakaka22

Newbie level 5
Joined
Feb 8, 2012
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,402
PIC16F628A Simple Combination lock Project with keypad and LCD

Hello, I have problems in my programming for my diploma project. Please correct my program for me to achieve build succeeded in MPLAB IDE. It comes success to be in Proteus simulation but for hardware. The errors must be fixed. **broken link removed**

this is my programming.

unsigned char var1, var2, kp;
char attempts=0;
char state = 1;//start from state 1
char txt[4];

char text[] = "Combination Lock" ;//message text
char text1[]= " *Door1 On*";
char text2[]= " *Door2 On*";
char text3[]= "*Door1&2 On*";

char table[17] = {0,1,2,3,0,4,5,6,0,7,8,9,0,10,0,11,0};

void main(void) {

CMCON = 0x07 ;//PORTA to digital mode
LCD_Config(&PORTA,7,6,5,3,2,1,0) ;//Pin assignment
;//RS,E,RW,D7,D6,D5,D4
LCD_Cmd(LCD_CLEAR) ;//Clear display
LCD_Cmd(LCD_CURSOR_OFF) ;//Turn cursor off
LCD_Cmd(LCD_SECOND_ROW) ;//Move to ROW2 for rest of program
//Seup Keypad on PORTB
Keypad_Init(&PORTB) ;// Initialize Keypad on PORTB
LCD_OUT(1,1,text) ;//Print welcome message
while(1) { //while ever loop
switch(state){ //check the current state
case 1:
LCD_Cmd(LCD_CLEAR) ;
LCD_out(1,1,text);
LCD_out(2,1,"EnterPass:");
while(!keypad_Read()){} //wait for key1 press
Delay_ms(10) ;//debounce time
kp = Keypad_Released() ;//wait for release
var1=kp; //store var1 into kp
var1=table[kp];
ByteToStr(var1,txt);
Lcd_Out_Cp(txt);
state = 2;
break;
case 2:
if(kp==15) state=1; //go back state 1 when kp = # (enter key)
else if(kp==13) state=1;//go back state 1 when kp = * (clear key)
else
state = 3;//go to state 3 get key2
break;
case 3:
while(!keypad_Read()){} //wait for key2 press
Delay_ms(10) ;//debounce time
kp = Keypad_Released() ;//wait for release
var2=kp;//store var2 into kp
var2=table[kp];
ByteToStr(var2,txt);
Lcd_Out_Cp(txt);
state=4;
break;
case 4:
if(kp==15) state=1;//enter key goes back state 1
else if(kp==13) state=1;//clear key goes back state 1
else
state = 5;//continue goes to state 4
break;
case 5:
while(!keypad_Read()){} //wait for enter key press
Delay_ms(10) ;//debounce time
kp = Keypad_Released() ;//wait for release
state = 6;
break;
case 6:
if(kp==13)
state =1; //clear goes back to s1
else if(kp==15)
state = 7;//enter key goes to state 7
else state = 5;
break;
case 7:
if (var1==0 && var2==5)//comparing for door1
state = 12; //goes state 11 open door1
else state =8;
break;
case 8:
if (var1==2 && var2 == 8)//comparing for door2
state = 13;//goes to state 9 for door 2
else state=9;
break;
case 9:
if(var1==8 && var2 == 2) //comparing foor door3
state = 14; //goes to state 15 for door 3
else state =10;//goes next state
break;
case 10:
if (var1==3 && var2 == 3)
state = 15;//goes to state 14 for door1 & 2
else
state =11;
break;
case 11:
LCD_OUT(2,1,"**Invalid Code**") ;
attempts++; //increment attempts
kp+=attempts;//kp = kp + attempts
if(attempts < 3) //attempts less than 3 times
state=1; //go state 1
else
state=16;
while(!keypad_Read()){} //wait for enter key press
Delay_ms(10) ;//debounce time
kp = Keypad_Released() ;//wait for release
LCD_Cmd(LCD_CLEAR);
break;
case 12://open door1 for 5secs
LCD_Cmd(LCD_CLEAR);
Lcd_out(2,1,text1) ;
Lcd_out(1,1,text);
//turn door1 led on
PORTA.F4=1;
PORTB.f4=1;
PORTB.F7 = 0;
PORTB.F6 = 0;
PORTB.F5 = 0 ;
Delay_ms(5000); //delay 5secs
//turn door1 led off
PORTA.F4 = 0;
LCD_Cmd(LCD_CLEAR) ;
attempts=0;
state=1;
break;
case 13: //open door2 for 5secs
LCD_Cmd(LCD_CLEAR);//clear display
LCD_OUT(2,1,text2);
Lcd_out(1,1,text) ;
//turn door2 led on
PORTA.F4=1;
PORTB.F5=1;
PORTB.f4=0;
PORTB.f6=0;
PORTB.f7=0;
Delay_ms(5000);
PORTA.F4 = 0 ;//turn door2 led off
LCD_Cmd(LCD_CLEAR);
attempts=0;
state =1;
break;
case 14: //open door3
LCD_Cmd(LCD_CLEAR);
LCD_OUT(2,1," *Door3 On*");
Lcd_out(1,1,text) ;
PORTA.F4=1;
PORTB.F4=0;
PORTB.F5=0;
PORTB.f6=1;
PORTB.f7=0;
Delay_ms(5000);
PORTA.F4 =0;
LCD_Cmd(LCD_CLEAR);
attempts=0;
state =1;
break;
case 15: //open door1 and door2
LCD_Cmd(LCD_CLEAR);
LCD_OUT(2,1,text3);
Lcd_out(1,1,text) ;
PORTA.F4=1;
PORTB.F4=1;
PORTB.F5=1;
PORTb.f6=0;
PORTb.f7=0;
Delay_ms(5000);
PORTA.F4 = 0 ;
LCD_Cmd(LCD_CLEAR);
attempts=0;
state =1;
break;
default:// must be a bad attempts
LCD_OUT(2,1," **Alarm On**");
LCD_OUT(1,1,text);
PORTA.F4=1;
PORTB.F4=0;
PORTB.F5=0;
PORTb.f6=0;
PORTb.f7=1;
Delay_ms(5000);
PORTA.F4=0;
LCD_Cmd(LCD_CLEAR);
attempts=0;
state = 1; //goes to state 1
break;
}
}
}View attachment pic-combination-lock.zip
 
Last edited:

Can you tell us what error you are observing?

I'm using MPLAB IDEv8.80, when I build this program. lots of errors occurs. I will give you the errors.

errors.png
 

Can you ask specific question and point what is the error rather than just paste the code.
 

Sorry for my post. This is my first. Those errors are these. MikroC and MPLAB IDE gave me the same errors.

Error [192] C:\Users\Dell N5110\Downloads\Compressed\pic-combination-lock\Combination Lock\Combination_lock.c; 34.1 undefined identifier "CMCON"
Warning [361] C:\Users\Dell N5110\Downloads\Compressed\pic-combination-lock\Combination Lock\Combination_lock.c; 35.1 function declared implicit int
Error [192] C:\Users\Dell N5110\Downloads\Compressed\pic-combination-lock\Combination Lock\Combination_lock.c; 35.13 undefined identifier "PORTA"
Warning [361] C:\Users\Dell N5110\Downloads\Compressed\pic-combination-lock\Combination Lock\Combination_lock.c; 37.1 function declared implicit int
Error [192] C:\Users\Dell N5110\Downloads\Compressed\pic-combination-lock\Combination Lock\Combination_lock.c; 37.9 undefined identifier "LCD_CLEAR"
Error [192] C:\Users\Dell N5110\Downloads\Compressed\pic-combination-lock\Combination Lock\Combination_lock.c; 38.9 undefined identifier "LCD_CURSOR_OFF"
Error [192] C:\Users\Dell N5110\Downloads\Compressed\pic-combination-lock\Combination Lock\Combination_lock.c; 39.9 undefined identifier "LCD_SECOND_ROW"
Warning [361] C:\Users\Dell N5110\Downloads\Compressed\pic-combination-lock\Combination Lock\Combination_lock.c; 41.1 function declared implicit int
Error [192] C:\Users\Dell N5110\Downloads\Compressed\pic-combination-lock\Combination Lock\Combination_lock.c; 41.14 undefined identifier "PORTB"
Warning [361] C:\Users\Dell N5110\Downloads\Compressed\pic-combination-lock\Combination Lock\Combination_lock.c; 42.1 function declared implicit int
Warning [361] C:\Users\Dell N5110\Downloads\Compressed\pic-combination-lock\Combination Lock\Combination_lock.c; 47.1 function declared implicit int
Warning [361] C:\Users\Dell N5110\Downloads\Compressed\pic-combination-lock\Combination Lock\Combination_lock.c; 49.8 function declared implicit int
Warning [361] C:\Users\Dell N5110\Downloads\Compressed\pic-combination-lock\Combination Lock\Combination_lock.c; 50.1 function declared implicit int
Warning [361] C:\Users\Dell N5110\Downloads\Compressed\pic-combination-lock\Combination Lock\Combination_lock.c; 51.6 function declared implicit int
Warning [361] C:\Users\Dell N5110\Downloads\Compressed\pic-combination-lock\Combination Lock\Combination_lock.c; 54.1 function declared implicit int
Warning [361] C:\Users\Dell N5110\Downloads\Compressed\pic-combination-lock\Combination Lock\Combination_lock.c; 55.1 function declared implicit int
Warning [361] C:\Users\Dell N5110\Downloads\Compressed\pic-combination-lock\Combination Lock\Combination_lock.c; 129.1 function declared implicit int
Error [196] C:\Users\Dell N5110\Downloads\Compressed\pic-combination-lock\Combination Lock\Combination_lock.c; 132.9 struct/union required
Error [196] C:\Users\Dell N5110\Downloads\Compressed\pic-combination-lock\Combination Lock\Combination_lock.c; 133.9 struct/union required
Error [196] C:\Users\Dell N5110\Downloads\Compressed\pic-combination-lock\Combination Lock\Combination_lock.c; 134.10 struct/union required
Error [196] C:\Users\Dell N5110\Downloads\Compressed\pic-combination-lock\Combination Lock\Combination_lock.c; 135.10 struct/union required
Error [196] C:\Users\Dell N5110\Downloads\Compressed\pic-combination-lock\Combination Lock\Combination_lock.c; 136.10 struct/union required
Error [196] C:\Users\Dell N5110\Downloads\Compressed\pic-combination-lock\Combination Lock\Combination_lock.c; 139.10 struct/union required
Error [196] C:\Users\Dell N5110\Downloads\Compressed\pic-combination-lock\Combination Lock\Combination_lock.c; 149.9 struct/union required
Error [196] C:\Users\Dell N5110\Downloads\Compressed\pic-combination-lock\Combination Lock\Combination_lock.c; 150.9 struct/union required
Error [196] C:\Users\Dell N5110\Downloads\Compressed\pic-combination-lock\Combination Lock\Combination_lock.c; 151.9 struct/union required
Error [196] C:\Users\Dell N5110\Downloads\Compressed\pic-combination-lock\Combination Lock\Combination_lock.c; 152.9 struct/union required
Error [196] C:\Users\Dell N5110\Downloads\Compressed\pic-combination-lock\Combination Lock\Combination_lock.c; 153.9 struct/union required
Error [196] C:\Users\Dell N5110\Downloads\Compressed\pic-combination-lock\Combination Lock\Combination_lock.c; 155.10 struct/union required
Error [196] C:\Users\Dell N5110\Downloads\Compressed\pic-combination-lock\Combination Lock\Combination_lock.c; 164.9 struct/union required
Error [196] C:\Users\Dell N5110\Downloads\Compressed\pic-combination-lock\Combination Lock\Combination_lock.c; 165.9 struct/union required
Error [196] C:\Users\Dell N5110\Downloads\Compressed\pic-combination-lock\Combination Lock\Combination_lock.c; 166.9 struct/union required

please see attachment.
 

Attachments

  • pic-combination-lock.zip
    70.3 KB · Views: 78

there's too many undefined and structure/union problems.
 

The code is incomplete. When i compile this code in mikroC, it says LCD_CLEAR, lcd_config(), keypad_read(), cursor_off, second row and etc are undefined. I think you have missed to add another file which is to complete the project.

By the way the hex file which you have uploaded is not created by u, because you are facing errors. Check whether you have missed any file to attach in your project

Thanks

---------- Post added at 11:06 ---------- Previous post was at 11:04 ----------

Or can you find out which compiler has been used to generate that hex file? because if that compiler has some predefined function for LCD, then either u have to use that compiler or you have to code the missing functions
 

Is it the header file that I'm missing? If so, how can I make a new one?

I downloaded this project and all files are in the attachment. But there is no header files.
 

I think this is not because of header files.

Some library files or program file is missing...
 

If those files were missing, what should I do to recover it or make a new one to compatible with my project?
 

as per my understanding you have LCD interfacing with PIC micro-controller and PORT based approach....

In my view what you should do is first devide your project in to small modules like LCD wirte function , PORT based function so that you can debug issues very fastly.....Currently there are many errors...may be header file is misssing , some of structure are not defined etc...... so first you try to bring-up one module and then remove all the errors in that module and add another module to it.....

Good Luck
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top