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

📄 switch.c

📁 Interface 4x4 matrix keypad with 8051 IO
💻 C
📖 第 1 页 / 共 2 页
字号:
							AddQueue(c13,&key_buff);
							} else { 
								surekey=toupper(c13);
								AddQueue(toupper(c13),&key_buff);
							}
						 }
			             break;
				case 14: if (!scrollmode) {
							surek=1; 
							//AddQueue(0x0D,&key_buff);
							//surekey=0x0D;
							surekey=c14;
							AddQueue(c14,&key_buff);
						 }
						 break;
				case 15: if (!scrollmode) {
							surek=1; 
							if (!big) {
							surekey=c15;
							AddQueue(c15,&key_buff);
							} else { 
								surekey=toupper(c15);
								AddQueue(toupper(c15),&key_buff);
							}
						 }
			             break;
			}
		} // if (newp_l&a)
		a=a<<1;
	} // for (b=0;b<16;b++)
   }  // if(newp_l)    
}

void keyscan(void) small using 3
{

  u8  j;
  u16 i;

  switch(rowcnt) {
    case 0: I2C_Write_Keypad(0x7F); //01111111b row3
	        break;
    case 1: I2C_Write_Keypad(0xBF); //10111111b row2
   		    break;
    case 2: I2C_Write_Keypad(0xDF); //11011111b row1
			break;
    case 3: I2C_Write_Keypad(0xEF); //11101111b row0
		    break;
  }
  newscan=(newscan<<4)|(I2C_Read_Keypad()&0x0F);
  rowcnt++;
  if(rowcnt==4) {
    rowcnt=0;
    if(newscan!=oldscan) {
      newpush=(oldscan^newscan)&oldscan;
    
	  if (newrelease!=newpush) {					//detect other key
          if (!numkey) {
		  storekey(newrelease, *(smallkeys[0]+k), *(smallkeys[1]+k), *(smallkeys[2]+k), *(smallkeys[3]+k), 
				               *(smallkeys[4]+k), *(smallkeys[5]+k), *(smallkeys[6]+k), *(smallkeys[7]+k),
					           *(smallkeys[8]+k), *(smallkeys[9]+k), *(smallkeys[10]+k), *(smallkeys[11]+k),
							   *(smallkeys[12]+k), *(smallkeys[13]+k), *(smallkeys[14]+k), *(smallkeys[15]+k)); 
		  k=0;
		  } else storekey(newrelease, '1', '2', '3', '#', '4', '5', '6','$', '7', '8', '9', '%', '^', '0', '@', '_');
	  }  
   	  if ((newrelease==newpush)&&newpush) k++;     //detect same key

	  newrelease=(oldscan^newscan)&newscan;
      if(newpush) {
		i=1;		
		for (j=0;j<16;j++) {
		  if (newpush&i) {
			  switch(j) {
			    case 0: if (scrollmode) scrollhome=1;
					    else { 
							tempk=1;
							fastkey='1';
							if (*(smallkeys[0]+k)==0) k=0;
							if (!numkey) {
							if (!big)
							tempkey=*(smallkeys[0]+k);
							else tempkey=toupper(*(smallkeys[0]+k));
							} else tempkey='1';
							printf("%c\n",tempkey);
						}
				        break;
			    case 1: if (scrollmode) scrollup=1;
						else { 
							tempk=1;
							fastkey='2';
							if (*(smallkeys[1]+k)==0) k=0;
							if (!numkey) {
							if (!big)
							tempkey=*(smallkeys[1]+k);
							else tempkey=toupper(*(smallkeys[1]+k));
							} else tempkey='2';
							printf("%c\n",tempkey);
						}
				        break;
			    case 2: if (scrollmode) scrollpup=1;
						else {
							tempk=1;
							fastkey='3';
							if (*(smallkeys[2]+k)==0) k=0;
							if (!numkey) {
							if (!big)
							tempkey=*(smallkeys[2]+k);
							else tempkey=toupper(*(smallkeys[2]+k));
							} else tempkey='3';
							printf("%c\n",tempkey);
						}
						break;
				case 3: if (!scrollmode) menu=1;	
						break;
				case 4: if (scrollmode) scrollleft=1;
						else {
							tempk=1;
							fastkey='4';
							if (*(smallkeys[4]+k)==0) k=0;
							if (!numkey) {
							if (!big)
							tempkey=*(smallkeys[4]+k);
							else tempkey=toupper(*(smallkeys[4]+k));
							} else tempkey='4';
							printf("%c\n",tempkey);
						}
				        break;
				case 5: if (!scrollmode) {
							tempk=1;
							fastkey='5';
							if (*(smallkeys[5]+k)==0) k=0;
							if (!numkey) {
							if (!big)
							tempkey=*(smallkeys[5]+k);
							else tempkey=toupper(*(smallkeys[5]+k));
							} else tempkey='5';
							printf("%c\n",tempkey);
						}
				        break;
				case 6: if (scrollmode) scrollright=1;
						else {
							tempk=1;
							fastkey='6';
							if (*(smallkeys[6]+k)==0) k=0;
							if (!numkey) {
							if (!big)
							tempkey=*(smallkeys[6]+k);
							else tempkey=toupper(*(smallkeys[6]+k));
							} else tempkey='6';
							printf("%c\n",tempkey);
						}
				        break;
				case 7: switch (n) {
						case 0: big=1;numkey=0;scrollmode=0;n=1;
							    break;
						case 1: big=0;numkey=1;scrollmode=0;n=2;
								break;
						case 2: big=0;numkey=0;scrollmode=1;n=3;
//     							send_command(T1G1);         // Text on, Graphic on, Cursor off
	    						break;
						case 3: big=0;numkey=0;scrollmode=0;n=0;
//								send_command(T1G1|C1B1);    // Text on, Graphic on, Cursor on, Blink on
								break;
//						case 0: big=1;numkey=1;scrollmode=0;n=1;
//							    break;
//						case 1: big=1;numkey=0;scrollmode=1;n=2;
//								send_command(T1G1);         // Text on, Graphic on, Cursor off
//								break;
//						case 2: big=1;numkey=0;scrollmode=0;n=0;
//								send_command(T1G1|C1B1);    // Text on, Graphic on, Cursor on, Blink on
//								break;
						};
						//if (big==0)
						//	 if (numkey==0) big=1;
						//	 else {numkey=0;big=0;}
						//	 else if (numkey==0){big=0;numkey=1;}
						  //        else numkey=0;							 
//						 printf("big=%bd",big?1:0);
//						 printf("numkey=%bd",numkey?1:0);
						break;
				case 8: if (scrollmode) scrollend=1;
						else {
							tempk=1;
							fastkey='7';
							if (*(smallkeys[8]+k)==0) k=0;
							if (!numkey) {
							if (!big)
							tempkey=*(smallkeys[8]+k);
							else tempkey=toupper(*(smallkeys[8]+k));
							} else tempkey='7';
							printf("%c\n",tempkey);
						}
				        break;
			    case 9: if (scrollmode) scrolldown=1;
						else {
							tempk=1;
							fastkey='8';
							if (*(smallkeys[9]+k)==0) k=0;
							if (!numkey) {
							if (!big)
							tempkey=*(smallkeys[9]+k);
							else tempkey=toupper(*(smallkeys[9]+k));
							} else tempkey='8';
							printf("%c\n",tempkey);
						}
				        break;
				case 10: if (scrollmode) scrollpdown=1;
						 else {
							tempk=1;
							fastkey='9';
							if (*(smallkeys[10]+k)==0) k=0;
							if (!numkey) {
							if (!big)
							tempkey=*(smallkeys[10]+k);
							else tempkey=toupper(*(smallkeys[10]+k));
							} else tempkey='9';
							printf("%c\n",tempkey);
						 }
				         break;
 				case 11: if (!scrollmode)
						 previous=1;
						 if (tempk) tempk=0;
						 else tempk=1;
                         tempk=1;
					     tempkey=0x5F;
						 AddQueue('%',&key_buff);
					     break;
				case 12: if (!scrollmode)
						 backsp=1;
						 if (tempk) tempk=0;
						     else tempk=1;
                         tempk=1;
					     tempkey=0x5F;
						 AddQueue(0x08,&key_buff);
					     break;
				case 13: if (!scrollmode) { 
							tempk=1;
							fastkey='0';
 							if (*(smallkeys[13]+k)==0) k=0;
							if (!numkey) {
							if (!big)
							tempkey=*(smallkeys[13]+k);
							else tempkey=toupper(*(smallkeys[13]+k));
							} else tempkey='0';
							printf("%c\n",tempkey);
						 }
				         break;
				case 14: if (!scrollmode) 
						 enter=1;
		//				 if (tempk) tempk=0;
		//				     else tempk=1;
						 big=1;numkey=0;scrollmode=0;n=0;	// Go to normal mode after enter
//						 send_command(T1G1|C1B1);			// Text on, Graphic on, Cursor on, Blink on				 tempk=1;
					     tempkey=0x5F;
						 AddQueue(0x0D,&key_buff);
		                 break;
				case 15: if (!scrollmode)
						 next=1;
						 if (tempk) tempk=0;
						 else tempk=1;
                         tempk=1;
					     tempkey=0x5F;
						 AddQueue('_',&key_buff);
					     break;
			  }
          } // if (newpush&i)
		  i=i<<1;
		}  // for (j=0;j<16;j++)
      } // if(newpush)
      oldscan=newscan;
	  l=0;
    } //if(newscan!=oldscan)

	l++;
	if (l==15) {
		l=0;
		if (!numkey) {
		  storekey(newrelease, *(smallkeys[0]+k), *(smallkeys[1]+k), *(smallkeys[2]+k), *(smallkeys[3]+k), 
				               *(smallkeys[4]+k), *(smallkeys[5]+k), *(smallkeys[6]+k), *(smallkeys[7]+k),
					           *(smallkeys[8]+k), *(smallkeys[9]+k), *(smallkeys[10]+k), *(smallkeys[11]+k),
							   *(smallkeys[12]+k), *(smallkeys[13]+k), *(smallkeys[14]+k), *(smallkeys[15]+k)); 
		newrelease=0;
		} else { 
			storekey(newrelease, '1', '2', '3', '#', '4', '5', '6','$', '7', '8', '9', '%', '^', '0', '@', '_');
		    newrelease=0;    
		}

	}
   
  } //if(rowcnt==4)
}
#endif
// ~10 ms
bit oneSecInt = 0;
//bit tenSecInt = 0;
//bit oneMinInt = 0;
//bit tenMinInt = 0;
//extern bit DecodeKb;
extern u8 bitCounter;

#define keyscanivl  -34300
void timer1(void) small interrupt 3 using 3
{
	static u8 oneSec=0;
//	static u16 tenSec=0;
//	static u16 oneMin=0;
//	static u16 tenMin=0;
   	TH1=keyscanivl>>8;
	TL1=keyscanivl&0x00FF;
	//bitCounter=11;	//Workaround
	if(bitCounter==11) ScanSwitch();	//Scan Switch only when no keyboard interrupt
	//ScanSwitch();
   //if(!KbInt) ScanSwitch();
	oneSec++;
	if(oneSec==100) {
		oneSecInt=1;
		oneSec=0;
		
		//if(DecodeKb||(bitCounter==10)) {		
		 //	bitCounter=11;
		//	DecodeKb=0;
		//}

	}
//	tenSec++;
//	if(tenSec==1000) {
//		tenSecInt=1;
//		tenSec=0;
//	}
//	oneMin++;
//	if(oneMin==6000) {
//		oneMinInt=1;
//		oneMin=0;
//	}
//	tenMin++;
//	if(tenMin==60000) {
//		tenMinInt=1;
//		tenMin=0;
//	}
//	keyscan();
//  oneminute++;
//  if (oneminute==1000) {
//  if (oneminute==60000) {		//ten minutes
//	  oneminute=0;
//	  standby=1;
//  }
}

void init_switch(void)
{
  TMOD |= 0x10;               // Timer 1, Mode 1, 16-bit
  TH1   = keyscanivl>>8;
  TL1   = keyscanivl&0x00FF;
  ET1   = 1;                  // Enable Timer 1 Overflow Interrupt
  TR1   = 1;                  // Timer 1 Run
  Init_queue(&switch_buff);
//  Init_queue(&key_buff);
//  I2C_Write_Keypad(0xff);

}





//#endif 
/*------------------------------------------------------------------*-
  ---- END OF FILE -------------------------------------------------
-*------------------------------------------------------------------*/




⌨️ 快捷键说明

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