我做的是密码锁,删除数据不能全部删除,会有一位乱的数据遗留,这是怎么回事啊
以下是我的程序
- #include<reg52.h>
- #include"1602.h"
- #include"delay.h"
- #include"keyboard.h"
- sbit LED1=P2^0;
- sbit LED2=P2^1;
- sbit beep=P1^5;
- unsigned char data password[]={1,2,3,4,5,6};
- void sound()
- {
- int t=2000;
- while(t--)
- {
- beep=~beep;
- delay(50);
- }
- }
- /*------------------------------------------------
- Ö÷³ÌÐò
- ------------------------------------------------*/
- main()
- {
- unsigned char num,i,j;
- unsigned char passwordtemp[6],inputtimes;
- unsigned char passwordlength,PLEN;
- bit Flag;
-
- PLEN=sizeof(password)/sizeof(password[0]);
-
- LCD_Init();
- DelayMs(10);
- LCD_Clear();
- LCD_Write_String(0,0," Welcome! ");
- LCD_Write_String(0,1,"Input password!");
- while (1)
- {
- num=KeyPro();
- if(num!=0xff)
- {
- if(i==0)
- LCD_Write_String(0,1," ");
- if(i<6)
- {
- passwordtemp[i]=num;
- LCD_Write_Char(i,1,num+'0');
- }
- if(num=='A')
- {
- i=0;
- LCD_Clear();
- LCD_Init();
- LCD_Write_Char(i,1,num+'0');
- passwordtemp[i]=0;
- }
- i++;
- if(i==7)
- {
- passwordlength=i-1;
- i=0;
- if(passwordlength==PLEN)
- {
- Flag=1;
- for(j=0;j<PLEN;j++)
- Flag=Flag&&(passwordtemp[j]==password[j]);
- }
- if(Flag)
- {
- LCD_Write_String(0,1," ");
- LCD_Write_String(0,1," Lock open!");
- LED1=0;
- LED2=0;
- inputtimes=0;
- Flag=0;
- }
- else
- {
- LCD_Write_String(0,1," ");
- LCD_Write_String(0,1," try again!!!");
- sound();
- inputtimes++;
- if(inputtimes==3)
- {
- LCD_Write_String(0,1," ");
- LCD_Write_String(0,1,"Wrong 3 times!");
- while(1);
- }
- }
- }
- }
- }
- }
复制代码
|