Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Need Help on a digital lock project using PIC16F877A

Status
Not open for further replies.

redadonis

New Member
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:
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
after it then it will keep its formatting.

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

Mike.
 
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)
		{
    [COLOR="Red"]// something must go here or it won't compile.[/COLOR]

Mike.
 
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.
 
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.
 
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...
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top