Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 2nd November 2008, 02:51 AM   #1
Default Need Help on a digital lock project using PIC16F877A

I'm currently working on a simple pic digital lock project, got most of it worked out but just can't work out the last part. Here's what I have atm;

Code:
//lock.c code to allow user to enter 4 characters on switches
//RC1,RC2,RC3,RC4 such that when RC1 is pressed 'A' is stored
//when RC2 is pressed 'B' is stored
//when RC3 is pressed 'C' is stored
//when RC4 is pressed 'D' is stored
//As soon as a set of 4 characters is stored in array key[]
//the program jumps out of the loop and loops continously
//doing nothing
//use watch window to view key[], i and PORTC
//use async stimulus to operate keys RC1-RC4
//use animated stepping
#include <pic.h>
void init(void);
void read_keys(void); 

unsigned char key[4]; //stores entered code
unsigned int i;

void init(void)
	{
	TRISC=0b00011110; //key inputs on RC4-RC1 = A,B,C,D
	i=0;
	}

void read_keys(void)
	{
	while(i<4)
		{
		while(PORTC==0){}; //wait until a key pressed
		if(RC1==1)
		{
		key[i]='A';
		i=i++;
		while(RC1==1){};
		}
		else 
		if(RC2==1)
		{
		key[i]='B';
		i=i++;
		while(RC2==1){};
		}
		else
		if(RC3==1)
		{
		key[i]='C';
		i=i++;
		while(RC3==1){};

		}
		else 
		if(RC4==1)
		{

		key[i]='D';
		i=i++;
		while(RC4==1){};

		}
	

	}

}
void main(void)
	{
	init();
	read_keys();
	while(1)
		{
Can someone help me out?

Last edited by redadonis; 2nd November 2008 at 03:35 AM.
redadonis is offline  
Old 2nd November 2008, 03:14 AM   #2
Default

You have only posted half of your code. Can you edit your post and include the rest of your code. Also, when entering code if you type [code] before it and [/code] after it then it will keep its formatting.

From a quick look at your code the problem may be lack of debounce.

Mike.
Pommie is online now  
Old 2nd November 2008, 03:34 AM   #3
Default

That's all I have actually, the comments are what it's supposed to do. I'm stuck after doing those parts.
redadonis is offline  
Old 2nd November 2008, 04:00 AM   #4
Default

Quote:
Originally Posted by redadonis View Post
That's all I have actually, the comments are what it's supposed to do. I'm stuck after doing those parts.
That can't be all you have as your main() is incomplete and therefore your code won't compile.

Code:
void main(void)
	{
	init();
	read_keys();
	while(1)
		{
    // something must go here or it won't compile. 
Mike.
Pommie is online now  
Old 2nd November 2008, 04:12 AM   #5
Default

Yeah, I know. But we were supposed to make the whole thing ourselves, I'm stuck at that part having no idea on how to continue.
redadonis is offline  
Old 2nd November 2008, 04:25 AM   #6
Default

To get it to compile you need 2 closing braces.
Code:
void main(void)
    {
    init();
    read_keys();
    while(1)
        {
    }
}
You should now be able to compile and simulate it in MPLAB.

Mike.
Pommie is online now  
Old 2nd November 2008, 04:28 AM   #7
Default

You mean I did everything in the comment?
redadonis is offline  
Old 2nd November 2008, 05:00 AM   #8
Default

Quote:
Originally Posted by redadonis View Post
You mean I did everything in the comment?
Did you simulate the code (Debugger->Select tool->MPLAB-SIM) and use a stimulus file to inject values into PORTC?

Mike.
Pommie is online now  
Old 25th October 2009, 11:11 AM   #9
Default

any update to this? currently im facing the same problem about the code. i have all the idea but problem with the code. im using MPLAB IDE...
reaver26 is offline  
Reply

Tags
digital, lock, pica, project

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
Need full schematic "Miniature digital pin number lock" using PIC16f877A chunei Micro Controllers 9 29th October 2009 02:53 AM
Hey do u have any digital clock using PIC16F877A pasanrobotics Micro Controllers 0 13th February 2007 01:06 AM
Thumbwheel lock project Lizo Electronic Projects Design/Ideas/Reviews 1 8th May 2004 03:38 PM
How to make a DIgital Lock? daiict Electronic Projects Design/Ideas/Reviews 2 30th October 2003 07:52 AM
Digital Combi Lock Lizo Electronic Projects Design/Ideas/Reviews 3 24th September 2003 12:03 AM



All times are GMT. The time now is 06:03 AM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker