pic used here is PIC16F876A
basic issue here is comparing process
- CODE: SELECT_ALL_CODE
-------------------------------------------------------------------
int kp=0,oldkp=0,xx=0;
char i=0,oldi=0;
// LCD module connections
sbit LCD_RS at RC2_bit;
sbit LCD_EN at RC3_bit;
sbit LCD_D4 at RC4_bit;
sbit LCD_D5 at RC5_bit;
sbit LCD_D6 at RC6_bit;
sbit LCD_D7 at RC7_bit;
sbit LCD_RS_Direction at TRISC2_bit;
sbit LCD_EN_Direction at TRISC3_bit;
sbit LCD_D4_Direction at TRISC4_bit;
sbit LCD_D5_Direction at TRISC5_bit;
sbit LCD_D6_Direction at TRISC6_bit;
sbit LCD_D7_Direction at TRISC7_bit;
// End LCD module connections
char txt[5]; // Declare an array to stall the 4-digit key in password
char txt3[5]="1234"; // Declare an array to stall the 4-digit desired password
void main()
{ trisa=0;
trisb=240;
portb=0;
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_off);
lcd_out(1,10,"Welcome");
for(;;)
{
for(i=0; i<9; i++)
{
Lcd_Cmd(_LCD_SHIFT_RIGHT);
delay_ms(100);
}
for(i=0; i<9; i++)
{
Lcd_Cmd(_LCD_SHIFT_LEFT);
delay_ms(100);
}
portb=2;
if(portb.f7==1) goto vv;
}
vv:
Lcd_Cmd(_LCD_CLEAR);
lcd_out(1,1,"prs1 entr code");
lcd_out(2,1,"prs2 chng code");
oo:
do
{
;
portb=4;
if(portb==132) kp=13;
portb=8;
if(portb==136) kp=12;
}while(!kp);
if(kp==12)
{
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,"entr code");
goto said;
}
if(kp=13)
{
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,"chng code");
goto said;
}
goto oo;
said:
do
{
portb=1;
if(portb==17) kp=7;
if(portb==33) kp=8;
if(portb==65) kp=9;
if(portb==129) kp=15;
portb=2;
if(portb==18) kp=4;
if(portb==34) kp=5;
if(portb==66) kp=6;
if(portb==130) kp=14;
portb=4;
if(portb==20) kp=1;
if(portb==36) kp=2;
if(portb==68) kp=3;
if(portb==132) kp=13;
portb=8;
if(portb==24) kp=0;
if(portb==40) kp=10;
if(portb==72) kp=11;
if(portb==136) kp=12;
}while(!kp);
if(oldkp!=kp&&kp!=12&&kp!=13&&kp!=14&&kp!=15&&kp!=11)
{
txt[0]=kp%10+48;
Lcd_Out(2, 4+xx,txt);
xx++;
delay_ms(500);
if(xx==4) goto ff;
} kp=0;
goto said;
ff:
if((txt[0]==txt3[0])&&(txt[1]==txt3[1]))
{
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,"ok!");
while(1);
}
else
{
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(2,1,"ERROR!");
while(1);
}
}
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
any suggestions as soon as any one can, thx all ^_^