//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)
{