Thông báo

Collapse
No announcement yet.

Cần giúp - giúp mình về chương trình khóa pass của dùng pic 16f877a

Collapse
X
 
  • Lọc
  • Giờ
  • Show
Clear All
new posts

  • Cần giúp - giúp mình về chương trình khóa pass của dùng pic 16f877a

    #include <16f877a.h>
    #include <def_877A.h>
    #fuses NOWDT,NOLVP,NOPROTECT,HS
    #use delay(clock=20000000)
    /////////khai bao ngo vao ra
    #define RS RD5
    #define RW RD6
    #define E RD7
    #define LCD PORTB

    #define door RA0///khoa
    #define alarm RA1///den bao
    #define loa RA2 ///loa bao
    //////////khai bao su dung port dung de xuat nhap du lieu
    #use fast_io(b)
    #use fast_io(d)
    //////khai bao bien.....
    int8 i,j,ss;
    int8 a[7],y[7],b[7]={1,1,1,1,1,1},t[7];//bien luu gtri nhap vao
    int8 test,dem,mp,alert;
    const char st0[17]={" MOI NHAP PASS "};//0-15
    const char st1[17]={"SAI PASS "};//0-15
    const char st2[17]={"OK DA MO KHOA "};//0-15
    const char st3[17]={" Nhap pass moi "};//0-15
    const char st4[17]={"*you got new pw*"};//0-15
    const char st5[17]={"*you got old pw*"};//0-15
    const char s1[17]={"Enter pass cu "};//0-15
    const char s2[17]={"Xac nhan pass "};//0-15

    /*xxxxxxxxxxxxxxxxxxxxxxxxxx*/
    /* procedures and functions */
    /*xxxxxxxxxxxxxxxxxxxxxxxxxx*/
    ////////khai bao cac chuong trinh con//////////////
    void con_wrt(int8);
    void data_wrt(int8);
    void setup_lcd();

    void scan_keyPress();//chuong trinh con quet phim
    void erase();//chuong trinh con xoa
    void write_PW();//chuong trinh con ghi
    void display_error();//chuong trinh con hien thi khi nhap sai pass
    void sub_main();
    void display_ok();//ham hien thi khi nhap pass 0k
    void compare();
    void display();// hien thi
    void confirm_pw();//xac nhan pass moi
    void new_pw();//pass moi
    void old_pw();//pass cu

    void main()///ham chuong trinh chinh
    {

    trisc=0x0f;//C[7:4] xuat;C[3:0] vao bthuong cao
    trisb=trisd=trisa=0;
    setup_lcd();
    alert=0;
    write_PW();
    for(i=0;i<6;i++) a=t=0;


    n: door=0;alarm=0; loa=0;//turn off
    con_wrt(0x01);//con tro dau dong 1
    for(i=0;i<=15;i++) data_wrt(st0); //hien thi moi nhap pass
    erase();
    k1: if(alert==3) { alarm = 1; loa = 1;}//turn on alarm
    scan_keypress(); //kiem tra phim matrix
    if (mp==0xff) goto k1;
    else
    {
    display();
    if(j==6)
    { while((mp!=10)&&(mp!=11))//wait for pushing 10 or 11
    {
    scan_keypress();
    }
    if(mp==10) {erase(); goto k1;}
    display(); goto n;
    }
    else goto k1;//if j is not 5 then turn back
    }
    }

    //xxxxxxxxxxxxxxxx functions & procedures xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    void con_wrt(int8 dat)
    {
    lcd=dat;
    RS=0;// instruction
    RW=0;
    E=1;delay_ms(3);
    E=0;
    delay_ms(5);
    }
    void data_wrt(int8 dat)
    {
    lcd=dat;
    RS=1;// du lieu
    RW=0;
    E=1;delay_ms(3);
    E=0;
    DELAY_ms(5);
    }
    void setup_lcd()///ham hien thi ki tu tren lcd
    {
    delay_ms(100);
    con_wrt(0x38);
    con_wrt(0x0c);
    con_wrt(0x01);
    con_wrt(0x06);
    }

    //Program of Scanning KeyPress:
    void scan_keyPress()///chuong trinh con quet phim matran
    {
    dem=4;
    mp=0;
    portc=0b11101111;
    kat: test=portc&0x0f;
    switch(test)
    {
    case 0b00001111: {
    mp=mp+4;
    portc=(portc<<1)+0;
    dem--;
    if(dem!=0) goto kat;//keep testing
    else mp=0xff;//no pushing button
    }
    break;
    case 0b00001110: {
    delay_ms(20);while(!rc0); loa=1; delay_ms(20);//wait for leaving button
    mp=mp+0;//nhan phim 0; 4; 8; 12
    }
    break;
    case 0b00001101: {
    delay_ms(20);while(!rc1);loa=1; delay_ms(20);//wait for leaving button
    mp=mp+1;//nhan phim 1; 5; 9; 13
    //display();
    }
    break;
    case 0b00001011: {
    delay_ms(20);while(!rc2);loa=1; delay_ms(20);//wait for leaving button
    mp=mp+2;//nhan phim 2; 6; 10; 14
    }
    break;
    case 0b00000111: {
    delay_ms(20);while(!rc3);loa=1; delay_ms(20);//wait for leaving button
    mp=mp+3;//nhan phim 3; 7; 11; 15
    }
    }
    delay_ms(30); loa = 0;////thoi gian loa keu
    }

    void erase()///chuong trinh con xoa khi ta nhan sai pass
    {
    ss=j=0;
    con_wrt(0xc0);
    for (i=0;i<16;i++)
    {
    if(i<6) a=0;
    data_wrt(0x20);// ' ' character
    }
    con_wrt(0xc0);
    }

    void write_PW()///ghi pass
    {
    for(i=0;i<6;i++) write_eeprom(i,b);
    }
    void display_error()
    {
    alert++;
    erase();
    for(i=0;i<=15;i++) data_wrt(st1);
    delay_ms(1500);
    erase();
    }

    //Program of control while you get in
    void sub_main()
    {
    door=1; delay_ms(2000); door=0;//door=o thi khoa,door=1 thi mo khoa
    k2: scan_keypress();
    switch(mp)
    {
    case 12: door = 1;delay_ms(2000); door=0;;goto k2;
    case 13: alarm = ~alarm;goto k2;
    case 14: old_pw();goto k2;
    case 15: break;
    default: goto k2;
    }
    }
    void display_ok()///man hinh hien thi luc nhap 0k
    {
    alert=0;
    erase();
    con_wrt(0x01);
    for(i=0;i<=15;i++) data_wrt(st2);
    con_wrt(0xc0);//con tro dau dong 2
    sub_main();
    }
    void compare()//TH nhan phim OK
    {
    for(i=0;i<6;i++) if(a==read_eeprom(i)) ss++;////doc du lieu tu eeprom
    if (ss==6) display_ok();
    else display_error();
    }

    void display()///hien thi
    {
    switch(mp)
    {
    case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9:
    {
    if(j==6) break;
    a[j]=mp;
    data_wrt(mp+0x30);
    delay_ms(10);
    con_wrt(0xc0+j);
    data_wrt('*');
    j++;
    }
    break;
    case 10: erase();break;
    case 11: compare();break;
    default: break;
    }
    }

    void old_pw(void)///ham nhap pass cu
    {
    erase();
    con_wrt(0x01);
    for(i=0;i<=15;i++) data_wrt(s1);
    k5: scan_keypress();///quet phim matrix
    switch(mp)
    {
    case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9:
    {
    if(j==6) goto k5;
    y[j]=mp;
    data_wrt(mp+0x30);
    delay_ms(100);
    con_wrt(0xc0+j);
    data_wrt( '*');
    j++;
    } goto k5;
    case 10: erase(); goto k5;
    case 11: if(j==0) goto k5;
    else new_pw();
    case 15: erase();con_wrt(1);for(i=0;i<=15;i++) data_wrt(st2);break;
    default: goto k5;
    }
    }

    void new_pw(void)///ham nhap pass moi
    {
    erase();
    con_wrt(0x01);
    for(i=0;i<=15;i++) data_wrt(st3);
    k3: scan_keypress();
    switch(mp)
    {
    case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9:
    {
    if(j==6) goto k3;
    b[j]=mp;
    data_wrt(mp+0x30);
    delay_ms(100);
    con_wrt(0xc0+j);
    data_wrt('*');
    j++;
    } goto k3;
    case 10: erase(); goto k3;
    case 11: confirm_pw();
    case 15: break;
    default: goto k3;
    }
    }

    void confirm_pw(void)///ham nhap lai pass cu
    {
    erase();
    con_wrt(0x01);
    for(i=0;i<=15;i++) data_wrt(s2);
    k4: scan_keypress();
    switch(mp)///mp tu viet tat MA PHIM MATRIX
    {
    case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9:
    {
    if(j==6) goto k4;
    t[j]=mp;
    data_wrt(mp+0x30);
    delay_ms(100);
    con_wrt(0xc0+j);
    data_wrt('*');
    j++;
    } goto k4;
    case 10: erase(); goto k4;
    case 11: for(i=0;i<6;i++) if( (y==read_eeprom(i)) && (b==t) ) ss++;

    if(ss==6) {write_PW(); erase();for(i=0;i<=15;i++) data_wrt(st4);delay_ms(1200);}
    else {erase(); for(i=0;i<=15;i++) data_wrt(st5);delay_ms(1200);}
    erase(); break;
    case 15: break;
    default: goto k4;
    }
    }
    CODE CỦA MÌNH ĐÂY MÌNH ĐÃ KHÓA ĐƯỢC 1 CƯA
    BÂY GIỜ MÌNH MUỐN QUẢN LÝ 2 CỬA CÓ NGHĨA TA THÊM 1 MẢNG PASS CHO CỬA THỨ 2
    BẤM PHÍM ĐÚNG PASS CỬA NÀO THÌ CỬA ĐÓ MỞ
    CÁC BẠN GIÚP MÌNH VỚI MÌNH ĐANG RẤT CẦN
    THANKS

Về tác giả

Collapse

chelseaboy Tìm hiểu thêm về chelseaboy

Bài viết mới nhất

Collapse

Đang tải...
X