Results 1 to 3 of 3
  1. #1

    Default how to edit this program using MPLAB IDE


    how to edit this program? commands that could change the default password and save a new password through the matrix keypad..we're using 4x3 keypad..please..even just a hint..give us a clue..we need it..THANKS!!!

    //================================================== ================================
    // Project description :PIC18F877A + 4x3 keypad + LCD are used to build a keypad door
    // security system which will activate the relay and buzzer after
    // a preset 6-digit password is entered.
    // LCD will display ****** when keypad is pressed.
    // preset password for this program is 123456
    //================================================== ======================================


    //================================================== ======================================
    // include
    //================================================== =======================================
    #include <pic.h>

    //================================================== =======================================
    // configuration
    //================================================== =======================================
    __CONFIG ( 0x3F32 );

    //================================================== ========================================
    // define
    //================================================== ========================================
    #define rs RC0
    #define e RC1
    #define led_red RC3
    #define led_yellow RC2
    #define lcd_data PORTD
    #define relay RB1
    #define buzzer RB2

    //================================================== =========================================
    // function prototype
    //================================================== =========================================
    void delay(unsigned long data);
    void send_config(unsigned char data);
    void send_char(unsigned char data);
    void e_pulse(void);
    void lcd_goto(unsigned char data);
    void lcd_clr(void);
    void send_string(const char *s);
    void clearrow1(void);
    void clearrow2(void);
    void clearrow3(void);
    void clearrow4(void);
    void scancolumn1(void);
    void scancolumn2(void);
    void scancolumn3(void);
    void beep_once(void);
    void beep_twice(void);

    //================================================== ==========================================
    // global variable
    //================================================== ==========================================
    unsigned char password_count=0;
    unsigned char keyin_char[6]; // Declare an array to stall the 6-digit key in password
    unsigned char stalled_char[6]="123456"; // Declare an array to stall the 6-digit desired password

    //================================================== ==========================================
    // main function
    //================================================== ==========================================
    void main(void)
    {
    ADCON1=0b00000110; //set all portA pins as digital I/O
    TRISA=0b11001111; //clear bit 4&5 portA as output and set the rest as input
    TRISB=0b00000000; //set portB as output
    TRISD=0b00000000; //set portD as output
    TRISC=0b11110000; //set bit4-7 portC as input(connected to 4 row of keypad)
    TRISE=0b00000000; //set portE as output

    PORTC=0;
    PORTD=0;
    relay=0;
    buzzer=0;
    led_yellow=0;
    led_red=0;

    send_config(0b00001001); //clear display at lcd
    send_config(0b00000010); //Lcd Return to home
    send_config(0b00000110); //entry mode-cursor increase 1
    send_config(0b00001100); //diplay on, cursor off and cursor blink off
    send_config(0b00111000); //function

    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==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
    {
    lcd_clr(); //clear lcd
    lcd_goto(0);
    send_string("SUCCESS!"); //display SUCCESS
    led_yellow=1; //yellow light on
    relay=1; //relay on
    beep_once(); //beep one time
    while(1); //infinity loop
    }
    else
    {
    lcd_clr(); //clear lcd
    lcd_goto(0);
    send_string("ERROR!"); //display ERROR!
    led_red=1; //red light on
    beep_twice(); //beep two time
    while(1); //infinity loop
    }
    }
    }
    }

    //================================================== =====================================
    // scanning functions
    //================================================== =====================================
    void clearrow1(void) //clear the 1st row and set the others
    {
    RE1=0; //RE1,RE0, and s RA5 are the output pins from PIC which connect to 4 pins of keypad
    RE0=1;
    RA5=1;
    }

    void clearrow2(void) //clear the 2nd row and set the others
    {
    RE1=1;
    RE0=0;
    RA5=1;
    }

    void clearrow3(void) //clear the 3rd row and set the others
    {
    RE1=1;
    RE0=1;
    RA5=0;
    }

    void clearrow4(void) //clear the 4th row and set the others
    {
    RE1=1;
    RE0=1;
    RA5=1;
    }

    void scancolumn1(void)
    {
    if(RA0==0) //if key '*' is being pressed
    {
    while(RA0==0)continue; //waiting the key to be released
    if(password_count==0)lcd_clr(); //Clear the LCD if the key is the 1st password
    lcd_goto(password_count); //The cursor of LCD points to the column equivalent to the value of password_count variable
    send_char('*'); //Display the symbol '*' at LCD
    keyin_char[password_count]='*'; //Stall the '*' value at the keyin_char array
    password_count+=1; //increase the Password_count variable's value by 1 and the result stall back to the variable
    }
    else if(RA1==0) //if key '7' is being pressed
    {
    while(RA1==0)continue; //waiting the key to be released
    if(password_count==0)lcd_clr(); //Clear the LCD if the key is the 1st password
    lcd_goto(password_count); //The cursor of LCD points to the column equivalent to the value of password_count variable
    send_char('*'); //Display the symbol '*' at LCD
    keyin_char[password_count]='7'; //Stall the '7' value at the keyin_char array
    password_count+=1; //increase the Password_count variable's value by 1 and the result stall back to the variable
    }
    else if(RA2==0) //if key '4' is being pressed
    {
    while(RA2==0)continue; //waiting the key to be released
    if(password_count==0)lcd_clr(); //Clear the LCD if the key is the 1st password
    lcd_goto(password_count); //The cursor of LCD points to the column equivalent to the value of password_count variable
    send_char('*'); //Display the symbol '*' at LCD
    keyin_char[password_count]='4'; //Stall the '4' value at the keyin_char array
    password_count+=1; //increase the Password_count variable's value by 1 and the result stall back to the variable
    }
    else if(RA3==0) //if key '1' is being pressed
    {
    while(RA3==0)continue; //waiting the key to be released
    if(password_count==0)lcd_clr(); //Clear the LCD if the key is the 1st password
    lcd_goto(password_count); //The cursor of LCD points to the column equivalent to the value of password_count variable
    send_char('*'); //Display the symbol '*' at LCD
    keyin_char[password_count]='1'; //Stall the '1' value at the keyin_char array
    password_count+=1; //increase the Password_count variable's value by 1 and the result stall back to the variable
    }
    }

    void scancolumn2(void)
    {
    if(RA0==0) //if key '0' is being pressed
    {
    while(RA0==0)continue; //waiting the key to be released
    if(password_count==0)lcd_clr(); //Clear the LCD if the key is the 1st password
    lcd_goto(password_count); //The cursor of LCD points to the column equivalent to the value of password_count variable
    send_char('*'); //Display the symbol '*' at LCD -+
    keyin_char[password_count]='0'; //Stall the '0' value at the keyin_char array
    password_count+=1; //increase the Password_count variable's value by 1 and the result stall back to the variable
    }
    else if(RA1==0) //if key '8' is being pressed
    {
    while(RA1==0)continue; //waiting the key to be released
    if(password_count==0)lcd_clr(); //Clear the LCD if the key is the 1st password
    lcd_goto(password_count); //The cursor of LCD points to the column equivalent to the value of password_count variable
    send_char('*'); //Display the symbol '*' at LCD
    keyin_char[password_count]='8'; //Stall the '8' value at the keyin_char array
    password_count+=1; //increase the Password_count variable's value by 1 and the result stall back to the variable
    }
    else if(RA2==0) //if key '5' is being pressed
    {
    while(RA2==0)continue; //waiting the key to be released
    if(password_count==0)lcd_clr(); //Clear the LCD if the key is the 1st password
    lcd_goto(password_count); //The cursor of LCD points to the column equivalent to the value of password_count variable
    send_char('*'); //Display the symbol '*' at LCD
    keyin_char[password_count]='5'; //Stall the '5' value at the keyin_char array
    password_count+=1; //increase the Password_count variable's value by 1 and the result stall back to the variable
    }
    else if(RA3==0) //if key '2' is being pressed
    {
    while(RA3==0)continue; //waiting the key to be released
    if(password_count==0)lcd_clr(); //Clear the LCD if the key is the 1st password
    lcd_goto(password_count); //The cursor of LCD points to the column equivalent to the value of password_count variable
    send_char('*'); //Display the symbol '*' at LCD
    keyin_char[password_count]='2'; //Stall the '2' value at the keyin_char array
    password_count+=1; //increase the Password_count variable's value by 1 and the result stall back to the variable
    }
    }

    void scancolumn3(void)
    {
    if(RA0==0) //if key '#' is being pressed
    {
    while(RA0==0)continue; //waiting the key to be released
    if(password_count==0)lcd_clr(); //Clear the LCD if the key is the 1st password
    lcd_goto(password_count); //The cursor of LCD points to the column equivalent to the value of password_count variable
    send_char('*'); //Display the symbol '*' at LCD
    keyin_char[password_count]='#'; //Stall the '#' value at the keyin_char array
    password_count+=1; //increase the Password_count variable's value by 1 and the result stall back to the variable
    }
    else if(RA1==0) //if key '9' is being pressed
    {
    while(RA1==0)continue; //waiting the key to be released
    if(password_count==0)lcd_clr(); //Clear the LCD if the key is the 1st password
    lcd_goto(password_count); //The cursor of LCD points to the column equivalent to the value of password_count variable
    send_char('*'); //Display the symbol '*' at LCD
    keyin_char[password_count]='9'; //Stall the '9' value at the keyin_char array
    password_count+=1; //increase the Password_count variable's value by 1 and the result stall back to the variable
    }
    else if(RA2==0) //if key '6' is being pressed
    {
    while(RA2==0)continue; //waiting the key to be released
    if(password_count==0)lcd_clr(); //Clear the LCD if the key is the 1st password
    lcd_goto(password_count); //The cursor of LCD points to the column equivalent to the value of password_count variable
    send_char('*'); //Display the symbol '*' at LCD
    keyin_char[password_count]='6'; //Stall the '6' value at the keyin_char array
    password_count+=1; //increase the Password_count variable's value by 1 and the result stall back to the variable
    }
    else if(RA3==0) //if key '3' is being pressed
    {
    while(RA3==0)continue; //waiting the key to be released
    if(password_count==0)lcd_clr(); //Clear the LCD if the key is the 1st password
    lcd_goto(password_count); //The cursor of LCD points to the column equivalent to the value of password_count variable
    send_char('*'); //Display the symbol '*' at LCD
    keyin_char[password_count]='3'; //Stall the '3' value at the keyin_char array
    password_count+=1; //increase the Password_count variable's value by 1 and the result stall back to the variable
    }
    }


    //================================================== =============================================
    // General Purpose functions
    //================================================== =============================================
    void delay(unsigned long data)
    {
    for( ;data>0;data-=1);
    }

    void beep_once(void)
    {
    buzzer=1; //buzzer on
    delay(8000);
    buzzer=0; //buzzer off
    }

    void beep_twice(void)
    {
    buzzer=1; //buzzer on
    delay(8000);
    buzzer=0; //buzzer off
    delay(13000);
    buzzer=1; //buzzer on
    delay(8000);
    buzzer=0; //buzzer off
    }

    //================================================== ======================================
    // LCD functions
    //================================================== ======================================
    void send_config(unsigned char data)
    {
    rs=0; //clear rs into config mode
    lcd_data=data;
    delay(50);
    e_pulse();
    }

    void send_char(unsigned char data)
    {
    rs=1; //set rs into write mode
    lcd_data=data;
    delay(50);
    e_pulse();
    }

    void e_pulse(void)
    {
    e=1;
    delay(50);
    e=0;
    delay(50);
    }

    void lcd_goto(unsigned char data)
    {
    if(data<16)
    {
    send_config(0x80+data);
    }
    else
    {
    data=data-20;
    send_config(0xc0+data);
    }
    }

    void lcd_clr(void)
    {
    send_config(0x01);
    delay(50);
    }

    void send_string(const char *s)
    {
    unsigned char i=0;
    while (s && *s)send_char (*s++);

    }

  2. #2

    Default Re: how to edit this program using MPLAB IDE

    HighTech-C man guro ni...

  3. #3
    Elite Member
    Join Date
    Aug 2008
    Posts
    1,053
    Blog Entries
    1

    Default Re: how to edit this program using MPLAB IDE

    DECLARATION
    unsigned char stalled_char[6]="123456"; // Declare an array to stall the 6-digit desired password

    CONDITION
    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

    hope u get what i mean. halatang di nagbabasa

  4.    Advertisement

Similar Threads

 
  1. Replies: 18
    Last Post: 02-27-2011, 08:45 AM
  2. how to delete this rose.exe ?
    By amazer in forum Software & Games (Old)
    Replies: 0
    Last Post: 10-23-2006, 04:08 PM
  3. HOW TO EDIT SETTINGS
    By tisoyon in forum Support Center
    Replies: 0
    Last Post: 05-11-2006, 02:41 AM
  4. how to edit the profile????????
    By corn_gal in forum Support Center
    Replies: 1
    Last Post: 01-25-2006, 11:57 AM
  5. HOW TO CONNECT SQL SERVER USING SQL AUTHENTICATION
    By edshark in forum Software & Games (Old)
    Replies: 13
    Last Post: 09-02-2005, 04:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top