⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 menus._c

📁 环保型IC卡门禁系统的C程序
💻 _C
字号:

#include <iom8v.h>
#include <macros.h>
#include "lcd1602.h"

unsigned char Menu_flag = 0 , Exist_flag = 0 ;

void Menu_Add(void)
{
  unsigned char Total = 0 , i = 0 , j = 0 , k = 0 , tem = 0 ;

  LCD_write_char(0x01,0);  //清屏
  delay_nms(2);
  
  Total = EEPROM_read(511) ;
  if(Total==83)
  {
    LCD_write_string(0,0,"83 Cards Existed");
	LCD_write_string(3,1,"Is Full !!");
	delay_nms(2000);
	Menu_0() ;
  }
  
  LCD_write_string(0,0,"Menu1 : Add Card");
  LCD_write_string(2,1,"Insert  Card");
  
  while(1)
  {
    if(IC_SW==0)
    {
      delay_nms(50);               //   检测是否有卡插入
	  if(IC_SW==0)
	  {
	    Menu_flag = 1 ;
		Exist_flag = 1 ;
        Read_Card();      //  读IC-Card 函数
		Card_Verify();
	  
	    for(i=0;i<83;i++)
	    {
	      tem = EEPROM_read(j);
		
	      if(tem==0)
		  {
		    for(k=0;k<6;k++)
		    {
		      EEPROM_write(j+k, IC_Codes_8[2+k]);
			  if(k==5)
			  {
			    tem =  EEPROM_read(511) + 1 ;
				EEPROM_write(511, tem);
			  
			    LCD_write_string(0,1,"Add Successfully");
			  
			    while(1)
			    {
			      if(IC_SW!=0)
	              {
                    delay_nms(50);               //   检测是否有卡插入
	                if(IC_SW!=0)
	                {
                      Menu_0();
                    }
	              }
			    }
			  }
		    }
		  }
		
		  j = j + 6 ;
	    }	
	  }
	}
  }
}

void Menu_Del(void)
{
  unsigned char Total = 0 , i = 0 , j = 0 , k = 0 , tem = 0 ;

  LCD_write_char(0x01,0);  //清屏
  delay_nms(2);
  
  Total = EEPROM_read(511) ;
  if(Total==0)
  {
	LCD_write_string(0,0,"No Card Existed");
	LCD_write_string(2,1,"Is  Empty !!");
	delay_nms(2000);
	Menu_0() ;
  }
  
  LCD_write_string(0,0,"Menu1 : Del Card");
  LCD_write_string(2,1,"Insert  Card");
  
  while(1)
  {
    if(IC_SW==0)
    {
      delay_nms(50);               //   检测是否有卡插入
	  if(IC_SW==0)
	  {
	    Menu_flag = 1 ;
        Read_Card();      //  读IC-Card 函数
		Card_Verify();
	  }
	}
  }
}

void Menu_PSW(void)
{
  unsigned char Key = 0 , i = 0 , PSW_1[8] = { 0 } , PSW_2[8] = { 0 } ;
  
  LCD_write_char(0x01,0);  //清屏
  delay_nms(2);
  LCD_write_char(0x0f,0);   // 显示光标
  
  LCD_write_string(1,0,"Insert New PSW");
  LCD_write_string(0,1,"New PSW:");
  
  
  while(1)
  {
    Key = Key_Scan() ;
	
	if ( (Key>0) && (i<8) && (Key<11) )
	{
	  if(i>0)
      {
		display(16 , 23+i);
	  }
	  
	  if (Key==10)
	  {
	    Key = 0;
	  }
	  
	  display(Key , 24+i);
	  
	  PSW_1[i] = Key ;
	  i++ ;
    }
	  
	if ( Key==11 )
	{
	  Menu_0();
	}
	
	if ( (Key==12) && (i==8) )
	{
	  LCD_write_char(0x01,0);  //清屏
      delay_nms(2);
  
      LCD_write_string(2,0,"Insert Again");
      LCD_write_string(0,1,"New PSW:");
	  
	  i = 0 ;
	  while(1)
      {
        Key = Key_Scan() ;
	
	    if ( (Key>0) && (i<8) && (Key<11) )
	    {
	      if(i>0)
          {
		    display(16 , 23+i);
	      }
	  
	      if (Key==0)
	      {
	        Key = 0;
	      }
		  
		  display(Key , 24+i);
	  
	      PSW_2[i] = Key ;
	      i++ ;
        }
	  
	    if ( Key==11 )
	    {
	      Menu_0();
	    }
		
		if ( (Key==12) && (i==8) )
		{
		  LCD_write_char(0x01,0);  //清屏
          delay_nms(2);
		  LCD_write_char(0x0c,0);  //关光标
		
		  if(PSW_1[0]==PSW_2[0])
		  {
		    if(PSW_1[1]==PSW_2[1])
			{
			  if(PSW_1[2]==PSW_2[2])
			  {
			    if(PSW_1[3]==PSW_2[3])
				{
				  if(PSW_1[4]==PSW_2[4])
				  {
				    if(PSW_1[5]==PSW_2[5])
					{
					  if(PSW_1[6]==PSW_2[6])
					  {
					    if(PSW_1[7]==PSW_2[7])
						{
						  for(i=0;i<8;i++)
						  {
						    EEPROM_write(503+i,  PSW_2[i]);
						  }
						
                          LCD_write_string(1,0,"PSW Is Changed");
                          LCD_write_string(2,1,"Remember It!");
						  
						  delay_nms(2000);
						  Menu_0();
						}
					  }
					}
				  }
				}
			  }
			}
		  }
		  
		  LCD_write_string(1,0,"Twice PSW Is XXX");
          LCD_write_string(2,1,"Insert Again");
						  
		  delay_nms(2000);
		  Menu_PSW();
		}
	  }
	}
  }
}


void Menu_0(void)
{
  unsigned char Key = 0 ;

  LCD_write_char(0x01,0);  //清屏
  delay_nms(2);
  
  LCD_write_string(0,0,"1: Add    2: Del");
  LCD_write_string(0,1,"3: PSW  4: Exist");
  
  while(1)
  {
    Key = Key_Scan();
  
    switch (Key)
	{
	  case 1 : Menu_Add(); break ;
	  case 2 : Menu_Del(); break ;
	  case 3 : Menu_PSW(); break ;
	  case 4 : menu_Init(); break ;
	  case 11 : menu_Init(); break ;
	  default : break ;
	}
  }  
}

void Menu(void)
{
  unsigned char Key = 0 , i = 0 , PSW[8] = {0} ;
  
  Key = Key_Scan();
  
  if( Key != 0 )
  {CLI();
    LCD_write_char(0x01,0);  //清屏
    delay_nms(2);
  
    LCD_write_string(2,0,"Setting Menu");
	LCD_write_string(1,1,"PSW : ");
	LCD_write_char(0x0f,0);   // 显示光标
	
	while(1)
	{
	  Key = Key_Scan();
	   
	  if ( (Key>0) && (i<8) && (Key<11) )
	  {
	    if(i>0)
		{
		  display(16 , 22+i);
		}
	  
	    if (Key==10)
	    {
	      Key = 0;
	    }
		
		display(Key , 23+i);
		
		PSW[i] = Key ;
		i++ ;
	  }
	  
	  if ( Key==11 )
	  {
	    menu_Init();
	  }
	  
	  if ( (Key==12) && (i==8) )
	  {
	    LCD_write_char(0x0c,0);   // 关闭光标
	    delay_nms(10);
		
	    if( PSW[0] == EEPROM_read(503) )
		{
		  if( PSW[1] == EEPROM_read(504) )
		  {
		    if( PSW[2] == EEPROM_read(505) )
			{
			  if( PSW[3] == EEPROM_read(506) )
			  {
			    if( PSW[4] == EEPROM_read(507) )
				{
				  if( PSW[5] == EEPROM_read(508) )
				  {
				    if( PSW[6] == EEPROM_read(509) )
					{
					  if( PSW[7] == EEPROM_read(510) )
					  {
					    Menu_0();
					  }
					}
				  }
				}
			  }
			}
		  }
		}
		
		LCD_write_char(0x01,0);  //清屏
        delay_nms(2);
  
        LCD_write_string(3,0,"Wrong  PSW");
	    LCD_write_string(4,1,"Sorry !!");
		delay_nms(2000);
		menu_Init();
	  }
	}
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -