lisud man sabton ang code but murag kani nga code ang imo interesan bai.
unsigned char stalled_char[6]="123456"
then, since 4 characters raman imong code, modify lang pud ni nimo diri
if(password_count==6)
{
password_count=0;
if((keyin_char[0]==stalled_char[0])&&(keyin_char[1]==stalled_char[1])&&
(keyin_char[2]==stalled_char[2])&&(keyin_char[3]==stalled_char[3])&&
(keyin_char[4]==stalled_char[4])&&(keyin_char[5]==stalled_char[5])) //compare the keyin value with stalled value to test whether password is correct
change the password count from 6 to 4. then change the array items checked. skip the 4 & 5 indices. sulayi lang ha kay wa pud kaayo nako gibasa ang code. maglibog ko kay kadlawon na unya hanaphanap na akong pananaw, wa pa jud klaro ang nesting sa logic blocks...
good luck! agi na pud ko ani. pure PIC assembly lang to akoa sa una (hambog gamay....)
Post the schematics ... its hard to understand where you assigned which ports to what peripheral and how its being connected, whether you have de-bouncing circuit built in or what keypad are you using. The LCD also has several varieties, are you using character based LCD's or graph based?
Post lang schematics, ang importante if possible specs also of your LCD.
Then that's the time masabtan nato imo program.
Simple raman ni.
Move the keyboard scanning logic into anther function which will read the keyboard input:
That is just a code snippet above, you do the rest.Code:#define MAXPASSWORDLEN 6 void scan_keyboard(unsigned char * read_data) { lcd_clr(); //clear LCD delay(1000); //delay lcd_goto(0); //initial display send_string("PLEASE ENTER"); //Display "PLEASE ENTER" on lcd lcd_goto(20); //Display on 2nd line send_string("6-DIGIT PASSWORD"); //Display "6-DIGIT PASSWORD" on lcd while(1) { //keypad scanning algorithm clearrow1(); //Clear 1st output pin and set the others scancolumn1(); //scan column 1-3 clearrow2(); //Clear 2nd output pin and set the others scancolumn2(); //scan column clearrow3(); //Clear 3rd output pin and set the others scancolumn3(); //scan column clearrow4(); //Clear 4th output pin and set the others if(password_count==MAXPASSWORDLEN) { password_count=0; // transfer the password to buffer (input array), do this in a loop or copy byte by byte // since std library for PIC is limited (no memcpy, etc.) for (int i=0; i<MAXPASSWORDLEN; i++) buffer[i] = keyin_char[i]; return; //break; } } } /* Checks the contents of passbuffer if it matches stalled_char, the stored password */ bool check_password(unsigned char * passbuffer) { for (int i=0; i<MAXPASSWORDLEN; i++) if (passbuffer[i] != stalled_char[i]) return false; return true; } /* Ask the user for a new password and store it to stalled_char, the stored password */ bool change_password() { // Instruct the user to input the old password unsigned char newpassword[6]; scan_keyboard(&newpassword); for (int i=0; i<MAXPASSWORDLEN; i++) stalled_char[i] = newpassword[i]; // Store the new password }
For storage of the password to persist (even after reboot/power off). You must have an external storage such as NVRAM
or somewhere and store it there. I'm not sure if you use a PIC which already has an NVRAM storage (there should be). The
last time I was working on PIC was more than 10 years ago (PIC16F84), that one has its own NVRAM storage which I forgot the offset address.
There is no MPLAB IDE command, it doesn't matter if you code it through an IDE or a simple text editor. Inputing chars from your 4x3 keyboard is not done by the IDE, its done by your program code when you compile and download the executable to your PIC.
The code snippet I gave already has a function called scan_keyboard() which is responsible for clearing the registers and reading the keys of your 4x3 keyboard through scancolumn1(), scancolumn2(), etc. I don't even know which registers and port addresses are used, i based it on the original code and schematics.
Sabta usa ang program brod, especially how it relates to the the schematics.
There is no MPLAB IDE command, it doesn't matter if you code it through an IDE or a simple text editor. Inputing chars from your 4x3 keyboard is not done by the IDE, its done by your program code when you compile and download the executable to your PIC.
The code snippet I gave already has a function called scan_keyboard() which is responsible for clearing the registers and reading the keys of your 4x3 keyboard through scancolumn1(), scancolumn2(), etc. Each key pressed is stored in keyin_char buffer (which is global). From this you can deduce how to change the password in the change_password() function, all that needs to be done is replace the data contained in stalled_char buffer.
I don't even know which registers and port addresses are used, i based it on the original code and schematics. I believe I had an error on the line:
Sabta usa ang program brod, especially how it relates to the the schematics. When we did this in USC-TC more than 10 years ago, we were doing it in assembly language, we don't have a luxury of a C compiler back then. But for you guys, since you have a C compiler already, its now very easy.Code:for (int i=0; i<MAXPASSWORDLEN; i++) read_data[i] = keyin_char[i]; //buffer[i] = keyin_char[i];
Naa lang ko question, did you design the circuit schematics yourself?
Similar Threads |
|