求教以下程序有13处警告 , 新手求解, 关于电子密码锁的,警告在最后
- #include <reg51.h>
- #include <string.h>
- #define uchar unsigned char
- #define unit unsigned int
- uchar Pre_KeyNo = 16, KeyNo = 16;
- uchar code Title_Text[] = "Your Password...";
- uchar DSY_BUFFER[10] = " ";
- uchar UserPassword[10] = " ";
- void LCD_Init();
- void Display_String(uchar * str,uchar LineNo);
- void IIC_24C04_Init();
- void Beep();
- uchar RecString(uchar Slave,uchar Subaddr,uchar *Buffer,uchar N);
- uchar SendString(uchar Slave,uchar Subaddr,uchar *Buffer,uchar N);
- uchar Keys_Scan();
- sbit LED_OPEN = P2^7;
- sbit BEEP = P3^7;
-
- void DelayMS(int x )
- {
- uchar i;
- while (x--) for (i = 0;i<120;i++);
- }
- void Beep()
- {
- uchar i;
- for (i=0;i<100;i++)
- {
- DelayMS(1);BEEP= ~BEEP;
- }
- BEEP=0;
- }
- void Clear_Password()
- {
- UserPassword[0] = '\0';
- DSY_BUFFER[0] = '\0';
- }
- void main()
- {
- uchar i = 0;
- uchar IIC_Password[10];
- uchar IS_Valid_User = 0;
- P0 = 0xFF;
- P1 = 0xFF;
- P2 = 0xFF;
- TMOD = 0x02; //T0设置为8位自动重装模式
- TH0 = 175;
- TL0 = 175;
- TR0 = 1; //启动T0
- DelayMS(10);
- LCD_Init(); //初始化LCD
-
- IIC_24C04_Init(); //初始化24C04
-
- Display_String(Title_Text,0x00); //在第1行显示标题
-
- //24C04的内容已由初始化BIN文件导入
- //将24C04中预先写入的密码读入pass
- RecString(0xa0, 0 , IIC_Password, 6);
- IIC_Password[6] = '\0';
- while(1)
- {
- P1 = 0xF0;
- if(P1 != 0xF0) KeyNo = Keys_Scan(); //扫描键盘获取键序号KeyNo
-
- switch ( KeyNo )
- {
- case 0: case 1: case 2: case 3: case 4:
- case 5: case 6: case 7: case 8: case 9:
-
- if ( i<= 5 ) //密码限制在6位以内
- {
- //如果i为0则执行一次清屏
- if (i ==0) Display_String(" ",0x40);
-
- UserPassword[i] = KeyNo + '0';
- UserPassword[i+1] = '\0';
-
- DSY_BUFFER[i] = '*';
- DSY_BUFFER[i+1] = '\0';
-
- Display_String(DSY_BUFFER,0x40);
-
- i++;
- }
- break;
-
- case 10: //按A键开锁
- if (strcmp(UserPassword,IIC_Password) == 0)
- {
- LED_OPEN = 0; //点亮LED
- Clear_Password();
- Display_String("Unlock OK! ",0x40);
- IS_Valid_User = 1;
- }
- else
- {
- LED_OPEN =1; //关闭LED
- Clear_Password();
- Display_String("ERROR ! ",0x40);
- IS_Valid_User = 0;
- }
- i = 0;
- break;
-
- case 11: //按B键上锁
- LED_OPEN =1;
- Clear_Password();
- Display_String(Title_Text,0x00);
- Display_String(" ",0x40);
- i = 0;
- IS_Valid_User = 0;
- break;
-
- case 12: //按C键设置新密码
- //如果是合法用户则提示输入新密码
- if ( !IS_Valid_User ) Display_String("No rights !",0x40);
- else
- {
- i = 0;
- Display_String("New Password: ",0x00);
- Display_String(" ",0x40);
- }
-
- break;
-
- case 13: //按D键保存新密码
- if ( !IS_Valid_User ) Display_String("No rights !",0x40);
- else
- {
- SendString(0xa0, 0 , UserPassword, 6);
-
- //重新读入刚写的密码
- RecString(0xa0, 0 , IIC_Password, 6);
- IIC_Password[6] = '\0';
-
- i = 0;
- Display_String(Title_Text,0x00);
- Display_String("Password Saved! ",0x40);
- }
-
- break;
-
- case 14: //按E键消除所有输入
- i = 0;
- Clear_Password();
- Display_String(" ",0x40);
- }
-
- Beep();
- DelayMS(100);
- P1= 0xF0;
- while (P1 != 0xF0); //如果有键未释放则等待
- while (P1 == 0xF0); //如果没有再次按下按键则等待
- }
- }
复制代码
警告
|