![]() | ![]() | ![]() |
| |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
![]() |
| | Tools |
| | #1 |
|
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)
{
Last edited by redadonis; 2nd November 2008 at 03:35 AM. | |
| |
| | #2 |
|
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. | |
| |
| | #3 |
|
That's all I have actually, the comments are what it's supposed to do. I'm stuck after doing those parts.
| |
| |
| | #4 | |
| Quote:
Code: void main(void)
{
init();
read_keys();
while(1)
{
// something must go here or it won't compile. | ||
| |
| | #5 |
|
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.
| |
| |
| | #6 |
|
To get it to compile you need 2 closing braces. Code: void main(void)
{
init();
read_keys();
while(1)
{
}
}
Mike. | |
| |
| | #7 |
|
You mean I did everything in the comment?
| |
| |
| | #8 |
| | |
| |
| | #9 |
|
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...
| |
| |
|
| 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 |