سلام
این سورس یه قفل 4 رقمی به زبان c هستش که نمی دونم چرا در شبیه سازی پروتئوس و عمل جواب نمیده .یه نگاهی بندازین لطفا.
چجوری تو پروتئوس کلاک رو روی سگ نگهبان قرار بدم؟؟
کد:
#include <mega32.h>
#include <lcd.h>
#include <delay.h>
#include <stdlib.h>
#asm
.equ __lcd_port=0x1b
#endasm
int a,b,c,d;
int my_password=1234;
int adad=1,y11,y12,y13,y14,y15;
char password[4];
int key(void)
{
while(1)
{
PORTB.0 = 1 ;
PORTB.1 = 0 ;
PORTB.2 = 0 ;
PORTB.3 = 0 ;
if(PINB.4 == 1){return 1 ; delay_ms(50);}
if(PINB.5 == 1){return 2 ; delay_ms(50);}
if(PINB.6 == 1){return 3 ; delay_ms(50);}
//==========================================
PORTB.0 = 0 ;
PORTB.1 = 1 ;
PORTB.2 = 0 ;
PORTB.3 = 0 ;
if(PINB.4 == 1){return 4 ;delay_ms(50);}
if(PINB.5 == 1){return 5 ;delay_ms(50);}
if(PINB.6 == 1){return 6 ;delay_ms(50);}
//==========================================
PORTB.0 = 0 ;
PORTB.1 = 0 ;
PORTB.2 = 1 ;
PORTB.3 = 0 ;
if(PINB.4 == 1){return 7 ;delay_ms(50);}
if(PINB.5 == 1){return 8 ;delay_ms(50);}
if(PINB.6 == 1){return 9 ;delay_ms(50);}
//==========================================
PORTB.0 = 0 ;
PORTB.1 = 0 ;
PORTB.2 = 0 ;
PORTB.3 = 1 ;
if(PINB.4 == 1){return 10; delay_ms(50);}
if(PINB.6 == 1){return 10; delay_ms(50);}
if(PINB.7 == 1){return 10; delay_ms(50);}
if(PINB.5 == 1){return 0 ; delay_ms(50);}
}
}
void amaliat(int y)
{
if(adad==1)
{a=y;adad++;y11=y;lcd_clear();lcd_putsf("*");}
if(adad==2)
{b=y;adad++;y12=y;lcd_clear();lcd_putsf("**");}
if(adad==3)
{c=y;adad++;y13=y;lcd_clear();lcd_putsf("***");}
if(adad==4)
{
d=y;adad++;y14=y;lcd_clear();lcd_putsf("****");
delay_ms(300);
lcd_clear();
itoa( a , password ) ; lcd_puts(password);
itoa( b , password ) ; lcd_puts(password);
itoa( c , password ) ; lcd_puts(password);
itoa( d , password ) ; lcd_puts(password);
delay_ms(200);
lcd_clear();
y15=y11*1000+y12*100+y13*10+y14;
if(y15==my_password)
{
lcd_gotoxy(0,0);
lcd_putsf("your pass is");
lcd_gotoxy(0,1);
lcd_putsf(" correct");
delay_ms(200);
lcd_clear();
}
else
{
lcd_gotoxy(0,0);
lcd_putsf("your pass is");
lcd_gotoxy(0,1);
lcd_putsf(" incorrect");
delay_ms(300);
lcd_clear();
}
};
}
void main(void)
{
int y;
int y1,y2,y3,y4,y5;
int i=0;
char aray[];
int y6,y7,y8,y9,y10;
DDRB=0x0F;
lcd_init(16);
while(1)
{
y = key();
if(y == 10){i++;delay_ms(100);}
up2:
while(i%2!=0)
{
lcd_clear();
lcd_putsf("reset pass");
delay_ms(200);
lcd_clear();
lcd_gotoxy(0,0);
up:
lcd_putsf("enter old pass:");
lcd_gotoxy(0,1);
y1=key();if(y1==10){i=0;goto up2;}itoa(y1,aray);lcd_puts(aray);delay_ms(100);
y2=key();if(y2==10){i=0;goto up2;}itoa(y2,aray);lcd_puts(aray);delay_ms(100);
y3=key();if(y3==10){i=0;goto up2;}itoa(y3,aray);lcd_puts(aray);delay_ms(100);
y4=key();if(y4==10){i=0;goto up2;}itoa(y4,aray);lcd_puts(aray);delay_ms(100);
y5=y1*1000+y2*100+y3*10+y4;
if(y5==my_password)
{
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf("pass correct");
delay_ms(500);
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf("enter new pass :");
lcd_gotoxy(0,1);
y6=key();if(y6==10){i=0;goto up2;}itoa(y6,aray);lcd_puts(aray);delay_ms(100);
y7=key();if(y7==10){i=0;goto up2;}itoa(y7,aray);lcd_puts(aray);delay_ms(100);
y8=key();if(y8==10){i=0;goto up2;}itoa(y8,aray);lcd_puts(aray);delay_ms(100);
y9=key();if(y9==10){i=0;goto up2;}itoa(y9,aray);lcd_puts(aray);delay_ms(100);
y10=y6*1000+y7*100+y8*10+y9;
my_password=y10;
lcd_clear();
lcd_gotoxy(0,0);lcd_putsf("new pass is : ");
lcd_gotoxy(0,1);itoa(y10,aray);lcd_puts(aray);delay_ms(300);
lcd_clear();
i=0;
}
else
{
lcd_gotoxy(0,0);
lcd_putsf("pass incorrect");
delay_ms(300);
lcd_gotoxy(0,1);
lcd_putsf("please repeat");
delay_ms(300);
lcd_clear();
goto up;
}
}
if(y == 0) {lcd_putchar('0'); delay_ms(50); amaliat(y);}
if(y == 1) {lcd_putchar('1'); delay_ms(50); amaliat(y);}
if(y == 2) {lcd_putchar('2'); delay_ms(50); amaliat(y);}
if(y == 3) {lcd_putchar('3'); delay_ms(50); amaliat(y);}
if(y == 4) {lcd_putchar('4'); delay_ms(50); amaliat(y);}
if(y == 5) {lcd_putchar('5'); delay_ms(50); amaliat(y);}
if(y == 6) {lcd_putchar('6'); delay_ms(50); amaliat(y);}
if(y == 7) {lcd_putchar('7'); delay_ms(50); amaliat(y);}
if(y == 8) {lcd_putchar('8'); delay_ms(50); amaliat(y);}
if(y == 9) {lcd_putchar('9'); delay_ms(50); amaliat(y);}
}
}