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

📄 key.c

📁 里面包含了LCD显示
💻 C
字号:
//=========================================================
//=========================================================
#define  key_c
#include "io.h"
#include "main.h"
#include "interrupt.h"
#include "key.h"
#include "lme2200.h"
#include "ifr_ir.h"
#include "lcd.h"
#include "stc_eeprom.h"


extern void tx2262(unsigned char d0,d1,d2);
//****************************************************
//function:指示灯的闪烁 
//input   :无
//output  :无
//modify  :2007-8-24 	
//****************************************************
void led_ray1(uchar u)
 { 
    uchar i;
    for(i=0;i<u;i++)
	 {
	   Led_R=0;delay(20000);Led_R=1;delay(20000);
	 }
 }

void led_ray11(uchar u)
 { 
    uchar i;
    for(i=0;i<u;i++)
	 {
	   Led_R=1;delay(20000);Led_R=0;delay(20000);
	 }
 }

//****************************************************
//function:指示灯的闪烁  	 
//input   :无
//output  :无			
//modify  :2007-8-24  	
//****************************************************
void led_ray2(uchar u)
 { 
    uchar i;
    for(i=0;i<u;i++)
	 {
	   Led_G=0;delay(20000);Led_G=1;delay(20000);
	 }
 }

//****************************************************
//function:key init
//input   :无
//output  :无
//modify  :2007-8-24 	
//****************************************************
void key_init(void)
 {
    b_keyonoff = 0;
	b_keypush  = 0;
	b_password = 0;
	b_pwerror  = 0;
	b_pwerror1 = 0;
	cycle      = 0;
	cycle1     = 0;
	b_study    = 0;
	b_err      = 0;
	keyvalue   = 0;
	keybuff    = 0xff;
	b_key_2second  = 0;
	b_key_2second1 = 0;
	b_key_2second2 = 0;
	b_key_5second  = 0;
	Key1_flag=Key2_flag=Key3_flag=0;
 }

//****************************************************
//function:scan key  	  
//input   :无
//output  :无
//modify  :2007-8-24  	  
//****************************************************
void scan_key(void)	
 { 
  
   uchar i=0;
   if(b_keypush==0)
    {
	  P1=0x1F;key9=0;
	  delay(10);
	  if(P1==0x1F)return;
	  delay(500);
	  P1=0x1F;
	  delay(2000);
	  if(P1==0x1F)return;
	  b_keyonoff=0;

      for(i=0;i<4;i++)
	   {
	     if(i==0)
		  {
		    key6=1;key7=1;key8=1;key9=0;
			if(!key1)
			  {keybuff=1;b_keypush=1;i=4;}
			else if(!key2)
			  {keybuff=4;b_keypush=1;i=4;}
			else if(!key3)
			  {keybuff=7;b_keypush=1;i=4;}
			else if(!key4)
			  {keybuff=11;b_keypush=1;i=4;}
			else if(!key5)
			  {keybuff=17;b_keypush=1;Key1_flag=1;second1=0;i=4;} 			  
		  }
		 else if(i==1)
		  {
		   	key6=1;key7=1;key8=0;key9=1;
			if(!key1)
			  {keybuff=2;b_keypush=1;i=4;}
			else if(!key2)
			  {keybuff=5;b_keypush=1;i=4;}
			else if(!key3)
			  {keybuff=8;b_keypush=1;i=4;}
			else if(!key4)
			  {keybuff=0;b_keypush=1;i=4;}
			else if(!key5)
			  {keybuff=18;b_keypush=1;Key2_flag=1;second1=0;i=4;}
		  }
		 else if(i==2)
		  {
		   	key6=1;key7=0;key8=1;key9=1;
			if(!key1)
			  {keybuff=3;b_keypush=1;i=4;}
			else if(!key2)
			  {keybuff=6;b_keypush=1;i=4;}
			else if(!key3)
			  {keybuff=9;b_keypush=1;i=4;}
			else if(!key4)
			  {keybuff=12;b_keypush=1;i=4;}
			else if(!key5)
			  {keybuff=19;b_keypush=1;Key3_flag=1;second1=0;i=4;}
		  }
		 else if(i==3)
		  {
		   key6=0;key7=1;key8=1;key9=1;
			if(!key1)
			  {keybuff=13;b_keypush=1;i=4;}
			else if(!key2)
			  {keybuff=14;b_keypush=1;i=4;}
			else if(!key3)
			  {keybuff=15;b_keypush=1;i=4;}
			else if(!key4)
			  {keybuff=16;b_keypush=1;i=4;}
		  }
	   }
	}
   else
    {  
	  
	  if(key1&&key2&&key3&&key4&&key5)
	   {
	      b_keypush=0;b_keyonoff=1;
		  Key1_flag=Key2_flag=Key3_flag=0;
		  keyID=keybuff;	   
	   }
	}
 }

//***************************************************##########################################
//****************************************************
//function:	  
//input   :无
//output  :无
//modify  :2007-9-11	
//*****************************************************
bit Find_ifrcode(void)
 {
   temp[4]=eeprom_read(0x8000);temp[5]=eeprom_read(0x8001);
   if((temp[4]==ifr_buf[0])&&(temp[5]==ifr_buf[1]))
	  {
		return 1;
      }
   else 
     {
	   return 0;
	 }

 }

//****************************************************
//function:学习红外   	
//input   :无
//output  :无	   
//modify  :2007-9-11  	 
//*****************************************************

void study_code(void)
  {
	 uchar b,a=0;
	 bit b_value=0;
	 if(!b_ifr)return;
     b_ifr=0;
	 if(Find_ifrcode())
	   {
	     b=eeprom_read(0x8200);
		 led_ray11(1);
		 for(a=2;a<b;a++)
		   {	
		     if(eeprom_read(0x8000+a)==ifr_buf[2])
			   {
			      
				  b_value=1;
			   }
			 if(!b_value)
			   {
			     eeprom_eares(0x8200);
				 eeprom_write(0x8200,b+1);
				 eeprom_write(0x8000+b,ifr_buf[2]);
			   }
		   }
	   }
	 else
	   {  
		 eeprom_eares(0x8000);
		 eeprom_write(0x8000,ifr_buf[0]);
		 eeprom_write(0x8001,ifr_buf[1]);		  
		 eeprom_write(0x8002,ifr_buf[2]);
		 eeprom_eares(0x8200);
		 eeprom_write(0x8200,3);
		 led_ray11(3);
	   }

  }		
//****************************************************
//function:keyexe 	  
//input   :无	 		  
//output  :无			
//modify  :2007-9-11  
//****************************************************
void keyexe(void)
 {
   if(!b_password)return;
   if(!b_key_2second)return;
   if(keybuff!=17)return;
   if(keybuff==17)
     {
	   Led_R=0;
	   while(!b_keyonoff) //等待按键放手
		 {scan_key();}
	   b_key_2second=0;keybuff=0xff;b_keyonoff=0;
	   while(1)
	    {
		   scan_key();
		   ifr_irn();
		   study_code();
		   if(b_key_2second)
		     {
			    Led_R=1;
				while(!b_keyonoff)
				  {scan_key();}
				b_key_2second=0;
				keybuff=0xff;
				b_keyonoff=0;
				return;
			 }
		}
	 }
     
 }

//****************************************************
//function:keyexe1   
//input   :无	 		  
//output  :无			
//modify  :2007-9-10	
//****************************************************
void keyexe1(void)
 {
   if(!b_password)return;
   if(!b_key_2second1)return;
   if(keybuff!=18)return;
   if(keybuff==18)
     {
	   Led_R=0;
	   b_study=1;
	   while(!b_keyonoff) //等待按键放手
		 {scan_key();}
	   b_key_2second1=0;keybuff=0xff;b_keyonoff=0;
	   while(1)
	    {
		   scan_key();
		   ifr_irn();
		   ifr_administer();
		   if(b_keyonoff)
			 {
			   b_keyonoff=0;
			   if(keyID>=13)break;
			   b_send=1;
			   checkok(keyID);
			}

			if(b_key_2second1)
			   {
			   	   Led_R=1;
				   b_study=0;
	               while(!b_keyonoff) //等待按键放手
		             {scan_key();}
	               b_key_2second1=0;cycle1=0;
				   keybuff=0xff;b_keyonoff=0;				 
				   return;

			   }

		}
	 }
     
 }

//****************************************************####################################################
//****************************************************####################################################
//****************************************************
//function:password_exit	 
//input   :无	 		  
//output  :无			
//modify  :2007-9-10  	  
//****************************************************
void password_exit(void)
 {

   if(!b_password)return;
   if(!b_key_2second2)return;
   if(keybuff!=19)return;
   b_err=0;
   if(keyID==19)
     {
	   Led_R=0;
	   cycle=0;
	   password_d();
	   while(!b_keyonoff) //等待按键放手
		 {scan_key();}
	   b_key_2second2=0;keybuff=0xff;b_keyonoff=0;
	   while(1)
	    {
		   scan_key();

		   if(b_keyonoff)
		     {
			   b_keyonoff=0;
			   if(keyID==16){if(cycle>=1){b_pwerror=1;password_d1();cycle--;}}
			   else
			     {
			       switch(cycle)
			        {
				      case 0:temp[0]=keyID<<4;if(keyID>9)b_err=1;break;
				      case 1:temp[0]=temp[0]+keyID;if(keyID>9)b_err=1;break;
				      case 2:temp[1]=keyID<<4;if(keyID>9)b_err=1;break;
				      case 3:temp[1]=temp[1]+keyID;if(keyID>9)b_err=1;break;
				      case 4:temp[2]=keyID<<4;if(keyID>9)b_err=1;break;
				      case 5:temp[2]=temp[2]+keyID;if(keyID>9)b_err=1;break;
				      case 6:if(keyID!=12){b_err=1;break;}
				             if((temp[0]==0x12)&&(temp[1]==0x34)&&(temp[2]==0x56))
				                {zhuti();Led_R=1;cycle=0;b_password=0;return;}
						      else
						        {b_err=1;}break; 
				   } 
			      cycle++;
				  password_d1();
			   }

			 }
		  	if(b_err)
			 {
			   b_err=0;
			   cycle=0;
			   b_pwerror1=1;
			   password_d1();
			   led_ray11(4);
			 }

		}
	 }
     
 }

//****************************************************
//function:key execute	  
//input   :无	 		
//output  :无  
//modify  :2007-8-24  	
//****************************************************
void key_odd(void)
 {

     uchar iii=0;
  	if(keyID>=13)return;
    if(!b_keyonoff)return;
    b_keyonoff=0;

	b_send=1;
    checkok(keybuff);
	if(iii)
	 {
       tx2262(0xaa,0xaa,0xaa);
       led_ray2(0);
	 }
 }

//****************************************************
//function:key execute	 
//input   :无	 		   
//output  :无  		
//modify  :2007-8-24  	
//****************************************************
void key_odd1(void)
 {
    if(keybuff!=19)return;
	if(!b_key_5second)return;
	if(b_password)return;
	if(keybuff==19)
	 {
	   password_d();
       while(!b_keyonoff) //等待按键放手
		 {scan_key();}
	   b_key_5second=0;keybuff=0xff;b_keyonoff=0;

	   while(1)
	    {
		   scan_key();

		   if((b_keyonoff)&&(!b_password))
		     {
			   b_keyonoff=0;
			   if(keyID==16){if(cycle>=1){b_pwerror=1;password_d1();cycle--;}}
			   else
			     {
			       switch(cycle)
			        {
				      case 0:temp[0]=keyID<<4;if(keyID>9)b_err=1;break;
				      case 1:temp[0]=temp[0]+keyID;if(keyID>9)b_err=1;break;
				      case 2:temp[1]=keyID<<4;if(keyID>9)b_err=1;break;
				      case 3:temp[1]=temp[1]+keyID;if(keyID>9)b_err=1;break;
				      case 4:temp[2]=keyID<<4;if(keyID>9)b_err=1;break;
				      case 5:temp[2]=temp[2]+keyID;if(keyID>9)b_err=1;break;
				      case 6:if(keyID!=12){b_err=1;break;}
				             if((temp[0]==0x12)&&(temp[1]==0x34)&&(temp[2]==0x56))
				                {dele_zero();function_a();function_b();
								  Led_R=1;cycle=0;b_password=1;}
						      else
						        {b_err=1;}break; 
				   } 
			      cycle++;
				  if(!b_password)
				    password_d1();
			   }
			 }
		  	if(b_err)
			 {
			   b_err=0;
			   cycle=0;
			   b_pwerror1=1;
			   password_d1();
			   led_ray1(4);
			 }
		   if((b_keyonoff)&&(b_password))
		     {
			   b_keyonoff=0;
			   if(keyID==2){function_c();}
			   else if(keyID==8){function_a();function_b();}
			 }
		}
	}
 }

////////////////////////////////////////////////////////////////
//////////   ******  **   **  *****    /////////////////////////
//////////   **      ***  **  **  **   /////////////////////////
//////////   ******  ** * **  **   **  /////////////////////////
//////////   **      **  ***  **  **   /////////////////////////
//////////   ******  **   **  *****    /////////////////////////
////////////////////////////////////////////////////////////////

⌨️ 快捷键说明

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