Sunteți pe pagina 1din 9

#include <16F877A.

h>
#fuses NOWDT,PUT,HS,NOPROTECT
#use delay(clock=20M)
#include <LCD_4bit.c>
#byte PORTB=0x06
#byte portc=0x07
#byte portd=0x08
#byte porte=0x09
#define LCD_ENABLE_PIN portd.0 ////
#define LCD_RS_PIN portd.1 ////
#define LCD_RW_PIN portd.2 ////
#define LCD_DATA4 portd.4 ////
#define LCD_DATA5 portd.5 ////
#define LCD_DATA6 portd.6 ////
#define LCD_DATA7 portd.7
#bit RB0=PORTB.0
#bit RB1=PORTB.1
#bit RB2=PORTB.2
#bit RB3=PORTB.3
#bit RB4=PORTB.4
#bit RB5=PORTB.5
#bit RB6=PORTB.6
#bit RB7=PORTB.7
#bit RC0=portc.0
#bit RC1=portc.1
#bit RC2=portc.2
#bit RC3=portc.3
#bit RC4=portc.4
#bit RC5=portc.5
#bit RC6=portc.6
#bit RC7=portc.7
int8 a[8],b[8];
int8 m=0,j=0,i=0;
void sairoi();
void kiemtra();
void quetphimthaydoi();
void quetphimsosanh();
void quetphim();
void sairoi()
{
LCD_PutCmd(Clear_Scr);
printf(LCD_PutChar,"nhap sai roi");
if(read_eeprom(0x09)==3)
{
RB5=1;
lcd_putcmd(line_2);
printf(LCD_PutChar,"ban la ke xau");
delay_ms(2000);delay_ms(2000);delay_ms(2000);delay_ms(2000);
RB5=0;write_eeprom(0x09,0);
reset_cpu();
}
else
{
lcd_putcmd(line_2);
printf(LCD_PutChar,"nhap lai");
delay_ms(1000);
reset_cpu();
}
}
void kiemtra()
{
lcd_putcmd(line_1);
printf(LCD_PutChar,"vui long dois");
delay_ms(600);
for(j=0;j<=7;j++)
if(read_eeprom(0x00+j)-b[j]!=0)
{
write_eeprom(0x09,read_eeprom(0x09)+1);
sairoi();
}
else
{
lcd_putcmd(line_2);
RB6=1;RB7=0;;i=0;
write_eeprom(0x09,0);
printf(LCD_PutChar,"dang mo cua");
}
}
void quetphimthaydoi()
{
portc=0xfe;
if(RC4==0)
{
write_eeprom(0x00+j,7);
j++;
LCD_PutChar('*');
while(RC4==0){;}
}
if(RC5==0)
{
write_eeprom(0x00+j,8);
j++;
LCD_PutChar('*');
while(RC5==0){;}
}
if(RC6==0)
{
write_eeprom(0x00+j,9);
j++;
LCD_PutChar('*');
while(RC6==0){;}
}
if(RC7==0)
{
while(RC7==0){;}
}
portc=0xfd;
if(RC4==0)
{
write_eeprom(0x00+j,4);
j++;
LCD_PutChar('*');
while(RC4==0){;}
}
if(RC5==0)
{
write_eeprom(0x00+j,5);
j++;
LCD_PutChar('*');
while(RC5==0){;}
}
if(RC6==0)
{
write_eeprom(0x00+j,6);
j++;
LCD_PutChar('*');
while(RC6==0){;}
}
if(RC7==0)
{
while(RC7==0){;}
}
portc=0xfb;
if(RC4==0)
{
write_eeprom(0x00+j,1);
j++;
LCD_PutChar('*');
while(RC4==0){;}
}
if(RC5==0)
{
write_eeprom(0x00+j,2);
j++;
LCD_PutChar('*');
while(RC5==0){;}
}
if(RC6==0)
{
write_eeprom(0x00+j,3);
j++;
LCD_PutChar('*');
while(RC6==0){;}
}
if(RC7==0)
{
while(RC7==0){;}
}
portc=0xf7;
if(RC4==0)
{
LCD_PutChar('#');
while(RC4==0){;}
}
if(RC5==0)
{
write_eeprom(0x00+j,0);
j++;
LCD_PutChar('*');
while(RC5==0){;}
}
if(RC6==0)
{
LCD_PutChar(' ');
while(RC6==0){;}
}
if(RC7==0)
{
LCD_PutCmd(Clear_Scr);
lcd_putcmd(line_1);
printf(LCD_PutChar,"da thay doi");
delay_ms(1000);
while(RC7==0){;}
reset_cpu();
}
}
void quetphimsosanh()
{
portc=0xfe;
if(RC4==0)
{
a[j]=7;
j++;
LCD_PutChar('*');
while(RC4==0){;}
}
if(RC5==0)
{
a[j]=8;
j++;
LCD_PutChar('*');
while(RC5==0){;}
}
if(RC6==0)
{
a[j]=9;
j++;
LCD_PutChar('*');
while(RC6==0){;}
}
if(RC7==0)
{
while(RC7==0){;}
}
portc=0xfd;
if(RC4==0)
{
a[j]=4;
j++;
LCD_PutChar('*');
while(RC4==0){;}
}
if(RC5==0)
{
a[j]=5;
j++;
LCD_PutChar('*');
while(RC5==0){;}
}
if(RC6==0)
{
a[j]=6;
j++;
LCD_PutChar('*');
while(RC6==0){;}
}
if(RC7==0)
{
while(RC7==0){;}
}
portc=0xfb;
if(RC4==0)
{
a[j]=1;
j++;
LCD_PutChar('*');
while(RC4==0){;}
}
if(RC5==0)
{
a[j]=2;
j++;
LCD_PutChar('*');
while(RC5==0){;}
}
if(RC6==0)
{
a[j]=3;
j++;
LCD_PutChar('*');
while(RC6==0){;}
}
if(RC7==0)
{
while(RC7==0){;}
}
portc=0xf7;
if(RC4==0)
{
LCD_PutChar('#');
while(RC4==0){;}
}
if(RC5==0)
{
a[j]=0;
j++;
LCD_PutChar('*');
while(RC5==0){;}
}
if(RC6==0)
{
LCD_PutChar(' ');
while (RC6==0){;}
}
if(RC7==0)
{
j=0;
LCD_PutCmd(Clear_Scr);
printf(LCD_PutChar,"vui long dois");delay_ms(1000);
for(j=0;j<=7;j++)
if(read_eeprom(0x00+j)-a[j]!=0)
{
lcd_putcmd(line_2);
printf(LCD_PutChar,"nhap sai pass");delay_ms(2000);
reset_cpu();
}
else
{
LCD_PutCmd(Clear_Scr);
printf(LCD_PutChar,"nhap pass moi");
lcd_putcmd(line_2);
}
j=0;
while(RC7!=0)
{
quetphimthaydoi();
}
}
}
void quetphim()
{
portc=0xfe;
if(RC4==0)
{
b[j]=0x07;
j++;
LCD_PutChar('*');
while(RC4==0){;}
}
if(RC5==0)
{
b[j]=0x08;
j++;
LCD_PutChar('*');
while(RC5==0){;}
}
if(RC6==0)
{
b[j]=0x09;
j++;
LCD_PutChar('*');
while(RC6==0){;}
}
if(RC7==0)
{
kiemtra();
while(RC7==0)
{
;
}
}
portc=0xfd;
if(RC4==0)
{
b[j]=0x04;
j++;
LCD_PutChar('*');
while(RC4==0){;}
}
if(RC5==0)
{
b[j]=0x05;
j++;
LCD_PutChar('*');
while(RC5==0){;}
}
if(RC6==0)
{
b[j]=0x06;
j++;
LCD_PutChar('*');
while(RC6==0){;}
}
if(RC7==0)
{
//LCD_putc('*');
while(RC7==0)
{
RB6=0;RB7=1;
LCD_PutCmd(Clear_Scr);
lcd_putcmd(line_1);
printf(LCD_PutChar,"dang khoa cua");
}
}
portc=0xfb;
if(RC4==0)
{
b[j]=0x01;
j++;
LCD_PutChar('*');
while(RC4==0){;}
}
if(RC5==0)
{
b[j]=0x02;
j++;
LCD_PutChar('*');
while(RC5==0){;}
}
if(RC6==0)
{
b[j]=0x03;
j++;
LCD_PutChar('*');
while(RC6==0){;}
}
if(RC7==0)
{
LCD_PutCmd(Clear_Scr);
printf(LCD_PutChar,"doi mat khau");
lcd_putcmd(line_2);
printf(LCD_PutChar,"mat khau cu :");
delay_ms(1000);
delay_ms(1000);
LCD_PutCmd(Clear_Scr);
printf(LCD_PutChar,"mat khau moi :");
lcd_putcmd(line_2);
j=0;
while(RC7!=0)
{
quetphimsosanh();
}
}
portc=0xf7;
if(RC4==0)
{
LCD_PutChar('#');
while(RC4==0){;}
}
if(RC5==0)
{
b[j]=0x00;
j++;
LCD_PutChar('*');
while(RC5==0){;}
}
if(RC6==0)
{
for(i=0;i<=9;i++)
{ //chu y doan nay|=> rat qu
an trong de thay doi duoc pass
write_eeprom(0x00+i,0);//xoa eeprom ve 0 //chu y doan nay| muon doi
pass, va co bao dong thi xoa doan nay di
}
printf(LCD_PutChar,"reset pass");
delay_ms(1000);
while(RC6==0){;}
reset_cpu();
}
if(RC7==0)
{
while(RC7==0){;}
}
}

void main()
{
set_tris_b(0x03);RB6=0;RB7=0;
set_tris_d(0x00);
set_tris_e(0x00);porte=0x00;
set_tris_c(0xf0);
portc=0xff;
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
ext_int_edge(H_TO_L);
lcd_init();delay_ms(100);
lcd_putcmd(line_1);
/*for(i=0;i<=9;i++)
{
write_eeprom(0x00+i,0);//xoa eeprom ve 0
}*/
printf(LCD_PutChar,"xin nhap pass");
lcd_putcmd(line_2);
while(true)
{
quetphim();
if(RB0==0)
{
LCD_PutCmd(Clear_Scr);
lcd_putcmd(line_2);
RB6=0;RB7=0;
printf(LCD_PutChar,"da khoa xong");
delay_ms(500);
LCD_PutCmd(Clear_Scr);
lcd_putcmd(line_1);
printf(LCD_PutChar,"xin nhap pass");
lcd_putcmd(line_2);
while(RB0==0)
{
quetphim();
while(RB0!=0)
{
if(RB1==0)
{
reset_cpu();
while(RB1!=0) {reset_cpu();}
}
}
}
}
if(RB1==0)
{
lcd_putcmd(line_2);
RB6=0;RB7=0;
for(m=0;m<=7;m++)
{
b[m]=0;
}
printf(LCD_PutChar,"da mo xong");
delay_ms(500);
LCD_PutCmd(Clear_Scr);
printf(LCD_PutChar,"xin nhap pass");
lcd_putcmd(line_2);
while(RB1==0)
{
quetphim();
while(RB1!=0)
{
if(RB0==0)
{
reset_cpu();
while(RB0!=0) {reset_cpu();}
}
}
}
}
}
}

S-ar putea să vă placă și