📄 menu.h
字号:
BYTE Check_Key_Card_valid(BYTE stat)
{
BYTE k;
if(stat&1){
if(Key_stat==2){ // Key_in
k=Key_index[Key-1];
Key_stat=3;
return k;
}
}
if((stat&2)&&(Menu_stat!=1)){
Check_IDcard();
if(b_Card_In){
b_Card_In=0;
return 0xFF;
}
}
return 0;
}
void Show_mainmenu(void)
{
Menu_stat=1;
LCD_clrscr();
#ifdef CHINESE
mystrcpy(" 1. 增加用户 ");
LCD_writeline(0);
mystrcpy(" 2. 设置时间 ");
LCD_writeline(2);
mystrcpy(" 3. 通讯格式 ");
LCD_writeline(4);
mystrcpy(" 4. 删除用户 ");
// mystrcpy(" 4. 删仇用户 ");
// LCD_buf[8]=0xFD; // Bug of Keil C51,could not show 0xFD
LCD_writeline(6);
#else
mystrcpy(" 1. Add User ");
LCD_writeline(0);
mystrcpy(" 2. Set Time ");
LCD_writeline(2);
mystrcpy(" 3. Comm Format");
LCD_writeline(4);
mystrcpy(" 4. Del User ");
LCD_writeline(6);
#endif
}
BYTE Wait_for_numbers(BYTE n) // number input in line 6
{ // if num=0 then only wait ESC or OK
BYTE k,num,stat;
if(n&0x80)
stat=3; // Enable ID card and key input
else
stat=1; // Enable key input only
Key_p=0;
num=n&0x7F;
if(num>0)
LCD_clearline(6);
while(1){
k=Check_Key_Card_valid(stat);
if(k==0xFF){ // ID card input
return 0xFF;
}else if(k=='C'){ // ESC key
return 0;
}else if(k=='D'){ // OK key
return 1;
}else if(k=='*'){ // BACK key
if(Key_p>0){ // at lease 1 digit valid
Key_p--;
LCD_fillbuf(0xFF);
LCD_buf[Key_p+(16-num)/2]=' ';
LCD_writeline(6);
}
}else if((k>='0')&&(k<='9')&&(Key_p<num)){
Key_buf[Key_p]=k-'0';
LCD_fillbuf(0xFF);
LCD_buf[Key_p+(16-num)/2]=k;
LCD_writeline(6);
Key_p++;
}
}
}
WORD Mult_index[]={10000,1000,100,10,1};
void Menu_adduser(void)
{
BYTE i,k;
WORD User_id;
LCD_clrscr();
#ifdef CHINESE
mystrcpy(" 增加用户 ");
LCD_writeline(0);
mystrcpy(" 请刷卡 ");
LCD_writeline(2);
#else
mystrcpy(" Add User ");
LCD_writeline(0);
mystrcpy(" Show Your Card ");
LCD_writeline(2);
#endif
while(1){ // Wait for ID card input or ESC quit
k=Check_Key_Card_valid(3); // Wait for ID card and key input
if(k=='C'){ // ESC pressed
goto Menu_adduser_ret;
}else if(k==0xFF){ // ID card valid
LCD_Show_Card_no(); // Write in line 2
if(Find_User()){ // User already exist
LCD_Show_User(); // Write in line 4
#ifdef CHINESE
mystrcpy(" 用户已经存在 ");
#else
mystrcpy(" User Exist! ");
#endif
LCD_writeline(6);
}else{
if(Total_User>1900){
#ifdef CHINESE
mystrcpy(" 用户已满1900 ");
#else
mystrcpy(" User Over 1900 ");
#endif
LCD_writeline(6);
}else
break;
}
}
}
#ifdef CHINESE
mystrcpy(" 请输入工号 ");
#else
mystrcpy(" Iuput User ID: ");
#endif
LCD_writeline(4);
while(1){
if(Wait_for_numbers(5)==1){ // Max 5 digits, OK pressed
if(Key_p==0) // no numbers input
continue;
if((Key_p==5)&&(Key_buf[0]>=6)){ // 工号 >= 60000
continue;
}else{ // number input ok
User_id=0;
for(i=0; i<Key_p; i++)
User_id+=(Key_buf[i]*Mult_index[5-Key_p+i]);
if(Find_User_id(User_id%256, User_id/256)){ // User_id already exist
#ifdef CHINESE
mystrcpy("工号已用 请重输");
#else
mystrcpy("ID exist, Retry!");
#endif
LCD_writeline(4);
continue;
}
Flash_adduser(User_id&0xFF, User_id/256);
#ifdef CHINESE
mystrcpy(" 增加用户成功 ");
#else
mystrcpy(" User Added ");
#endif
LCD_writeline(6);
Wait_for_numbers(0);
goto Menu_adduser_ret;
}
}else{ // ESC pressed
Menu_adduser_ret:
Show_mainmenu();
return;
}
}
}
BYTE BCD_to_NUM(BYTE bcd)
{
BYTE num;
num=(bcd>>4)*10+(bcd&0xF);
return num;
}
void Menu_settime(void)
{
BYTE code mons[]={31,29,31,40,31,30,31,31,30,31,30,31};
// 1 2 3 4 5 6 7 8 9 10 11 12
BYTE t,dd,mm;
LCD_clrscr();
#ifdef CHINESE
mystrcpy(" 设置时间 ");
LCD_writeline(0);
mystrcpy("请按以下格式输入");
LCD_writeline(2);
mystrcpy("年月日星期时分秒");
LCD_writeline(4);
#else
mystrcpy(" Set Time ");
LCD_writeline(0);
mystrcpy(" Input Format ");
LCD_writeline(2);
mystrcpy(" YYMMDDWhhmmss ");
LCD_writeline(4);
#endif
while(1){
if(Wait_for_numbers(13)==1){ // Max 13 digits, OK pressed
if(Key_p==13){
Time_buf[0]=((Key_buf[11]<<4)&0x70)+Key_buf[12]; // 秒
Time_buf[1]=((Key_buf[9]<<4)&0x70)+Key_buf[10]; // 分
Time_buf[2]=((Key_buf[7]<<4)&0x30)+Key_buf[8]; // 时
Time_buf[3]=((Key_buf[4]<<4)&0x30)+Key_buf[5]; // 日
Time_buf[4]=((Key_buf[2]<<4)&0x10)+Key_buf[3]; // 月
Time_buf[5]=Key_buf[6]&7; // 星期
Time_buf[6]=(Key_buf[0]<<4)+Key_buf[1]; // 年
t=BCD_to_NUM(Time_buf[0]);
if(t>59){
#ifdef CHINESE
mystrcpy(" 秒出错 请重输 ");
#else
mystrcpy(" Sec err, Retry ");
#endif
LCD_writeline(2);
continue;
}
t=BCD_to_NUM(Time_buf[1]);
if(t>59){
#ifdef CHINESE
mystrcpy(" 分出错 请重输 ");
#else
mystrcpy(" Min err, Retry ");
#endif
LCD_writeline(2);
continue;
}
t=BCD_to_NUM(Time_buf[2]);
if(t>23){
#ifdef CHINESE
mystrcpy(" 时出错 请重输 ");
#else
mystrcpy(" Hour err, Retry");
#endif
LCD_writeline(2);
continue;
}
dd=BCD_to_NUM(Time_buf[3]);
if((dd==0)||(dd>31)){
#ifdef CHINESE
mystrcpy(" 日出错 请重输 ");
#else
mystrcpy(" Day err, Retry ");
#endif
LCD_writeline(2);
continue;
}
mm=BCD_to_NUM(Time_buf[4]);
if((mm==0)||(mm>12)){
#ifdef CHINESE
mystrcpy(" 月出错 请重输 ");
#else
mystrcpy(" Mon err, Retry ");
#endif
LCD_writeline(2);
continue;
}
if(dd>mons[mm]){
#ifdef CHINESE
mystrcpy("月日出错 请重输");
#else
mystrcpy(" Date err, Retry");
#endif
LCD_writeline(2);
continue;
}
t=BCD_to_NUM(Time_buf[5]);
if((t==0)||(t>7)){
#ifdef CHINESE
mystrcpy("星期出错 请重输");
#else
mystrcpy(" Week err, Retry");
#endif
LCD_writeline(2);
continue;
}
t=BCD_to_NUM(Time_buf[6]);
if(((t%4)!=0)&&(mm==2)&&(dd==29)){
#ifdef CHINESE
mystrcpy("闰月出错 请重输");
#else
mystrcpy(" L/M err, Retry ");
#endif
LCD_writeline(2);
continue;
}
HT1380_WriteTime(); // 时间格式(BCD): 秒 分 时 日 月 星期 年
#ifdef CHINESE
mystrcpy(" 时间修改完成 ");
#else
mystrcpy(" Set Time OK! ");
#endif
LCD_writeline(6);
Wait_for_numbers(0);
goto Menu_settime_ret;
}
}else{ // ESC pressed
Menu_settime_ret:
Show_mainmenu();
return;
}
}
}
void Menu_serial(void)
{
BYTE i,num;
LCD_clrscr();
#ifdef CHINESE
mystrcpy(" 请输入本机地址 ");
LCD_writeline(0);
mystrcpy("485方式为101-132");
LCD_writeline(2);
mystrcpy("其它为RS232方式 ");
LCD_writeline(4);
#else
mystrcpy("Set Device Addr ");
LCD_writeline(0);
mystrcpy("485 Addr=101-132");
LCD_writeline(2);
mystrcpy(" Other is RS232 ");
LCD_writeline(4);
#endif
while(1){
if(Wait_for_numbers(3)==1){ // Max 3 digits, OK pressed
if(Key_p>0){ // at lease 1 digit input
num=0;
for(i=0; i<Key_p; i++)
num+=(Key_buf[i]*Mult_index[5-Key_p+i]);
Set_28F040_Page(1);
for(i=0; i<16; i++)
LCD_buf[i]=Flash[0x2400+i];
LCD_buf[0]=num;
Flash_p=0x2400;
Erase_28F040(1); // Auto set 28F040 Page(1)
for(i=0; i<16; i++)
Write_28F040(0x2400+i, LCD_buf[i]);
Serial_init();
#ifdef CHINESE
mystrcpy("通讯格式设置完成");
#else
mystrcpy("Comm. Setup done");
#endif
LCD_writeline(6);
Wait_for_numbers(0);
goto Menu_serial_ret;
}
}else{ // ESC pressed
Menu_serial_ret:
Show_mainmenu();
return;
}
}
}
void Menu_deluser(void)
{
BYTE i,k;
WORD User_id;
LCD_clrscr();
#ifdef CHINESE
mystrcpy(" 删除用户 ");
// mystrcpy(" 删仇用户 ");
// LCD_buf[7]=0xFD; // Bug of Keil C51,could not show 0xFD
LCD_writeline(0);
mystrcpy("请刷卡或输入工号");
LCD_writeline(2);
#else
mystrcpy(" Del User ");
LCD_writeline(0);
mystrcpy("Get Card/UserID ");
LCD_writeline(2);
#endif
while(1){
k=Wait_for_numbers(0x85); // Wait for ID card or max 5 digits k
if(k==0xFF){ // ID card input
LCD_Show_Card_no(); // Write in line 2
if(Find_User()){ // User already exist
Menu_deluser_1:
LCD_Show_User(); // Write in line 4
#ifdef CHINESE
mystrcpy("ESC取消 OK删除");
// mystrcpy("ESC取消 OK删仇");
// LCD_buf[15]=0xFD; // Bug of Keil C51,could not show 0xFD
#else
mystrcpy("ESC-Quit OK-Del");
#endif
LCD_writeline(6);
if(Wait_for_numbers(0)==1){// OK key
Flash_deluser();
#ifdef CHINESE
mystrcpy(" 删除用户成功 ");
// mystrcpy(" 删仇用户成功 ");
// LCD_buf[5]=0xFD; // Bug of Keil C51,could not show 0xFD
#else
mystrcpy(" User Deleted! ");
#endif
LCD_writeline(6);
Wait_for_numbers(0);
goto Menu_deluser_ret;
}else // ESC key
goto Menu_deluser_ret;
}
}else if(k==1){ // OK pressed
if(Key_p==0) // no numbers input
continue;
if((Key_p==5)&&(Key_buf[0]>=6)){ // 工号 >= 60000
continue;
}else{ // number input ok
User_id=0;
for(i=0; i<Key_p; i++)
User_id+=(Key_buf[i]*Mult_index[5-Key_p+i]);
if(Find_User_id(User_id%256, User_id/256)) // User exist
goto Menu_deluser_1;
}
}else{
Menu_deluser_ret:
Show_mainmenu();
return;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -