u16 get_key_val_no_irq (void) { char datac,tstint; int num; U16 keysca; do { do { /* ´Ó¼üÅ̽ÚƬ¶ÁÈ¡¼üÖµ */ if (Key_Read(&datac, 0x0)) printk (KERN_ALERT "Keyb chip read failed.\n"); #ifdef KEYB_DEBUG printk (KERN_ALERT "keyirq: the key is %x\n", keysca); #endif if (datac == 0x0) return 0; num = (int) (datac & 0x3f); keysca = raw2scancode(num); #ifdef __NEW_KB if (keysca == 0x0f) { //mdelay (15000); pkeyb_dev->is_backlight = !at91_get_gpio_value(KEY_BL); at91_set_gpio_value (KEY_BL, pkeyb_dev->is_backlight); //at91_set_gpio_value (KEY_BL, !at91_get_gpio_value (KEY_BL)); } else { if (!at91_get_gpio_value (KEY_SHT)) keysca |= (0x0f << 8); //if (kbufin (keysca)) // printk (KERN_ALERT "petworm: kbufin full.\n"); } #else /* ½«¶ÁÈ¡µÄ¼üÖµ·ÅÈ뻺³åÇø */ if (kbufin (keysca)) printk (KERN_ALERT "petworm: kbufin full.\n"); #endif #ifdef __NET_KB }while (((datac & 0x40) != 0x0) || (datac != 0x0)); #else }while (((datac & 0x40) != 0x0)); #endif Key_Read(&tstint, 0x3); }while ((tstint & 0x80) != 0);
void Key_ActionDetect(void) { uint8_t Key_codeBuf; static uint8_t Key_stateHoldCnt; static uint8_t Key_stateHoldCntExt; Key_codeBuf = Key_Read(); if (Key_Code != Key_codeBuf) { if (Key_codeBuf == KEY_NULL && Key_stateHoldCnt > 5 && Key_stateHoldCnt < 150) { Key_Action = KEY_ACTION_RELEASING; currentState->keyAction_handler(); } Key_Code = Key_codeBuf; } else { if (Key_Code == 0) { Key_stateHoldCnt = 0; Key_stateHoldCntExt = 0; Key_Released = TRUE; } else { Key_Action = KEY_ACTION_UNDEFINE; Key_stateHoldCnt++; Key_stateHoldCntExt++; if (Key_stateHoldCntExt > 60) { Key_stateHoldCntExt = 45; Key_Action = KEY_ACTION_INTERVAL; currentState->keyAction_handler(); } if (Key_stateHoldCnt == 5) { Key_Action = KEY_ACTION_SHORT; } else if (Key_stateHoldCnt == 248) { Key_Action = KEY_ACTION_LONG; } else { if (Key_stateHoldCnt > 250) { Key_stateHoldCnt = 250; } return; } currentState->keyAction_handler(); } } }
void main() { b=1; trisb = 0b00001111; trisc = 0b10000000; portc = 0; ///////////// Store The Password(12345) ////////// Eeprom_Write(0x00,1); Eeprom_Write(0x01,2); Eeprom_Write(0x02,3); Eeprom_Write(0x03,4); Eeprom_Write(0x04,5); ////////////////////////////////////////// Lcd_Init(&portd); S: Lcd_Cmd(Lcd_Clear); Lcd_Out_Cp("Ent Pass:"******"*"); delay_ms(700); do{ K = Key_Read(); } while(k==20); // Lcd_Out_Cp("*"); if(k==10) { ////////////// Detection Process ///////////////////// for(i = 0;i <= 4;i++) { if(sum==0) sum = sum + (Eeprom_Read(i) - Eeprom_Read(i + 5)); } if(sum == 0){ b=1; Lcd_Out(2,1,"OPEN"); portc=1; //do //{ for(x=1000 ; x>2; x--) { delay_ms(10); PORTC=PORTC<<1; if (PORTc.F4) PORTC=1; } delay_ms(5000); for(x=1000; x>2; x--) { delay_ms(10); PORTC=PORTC>>1; if (PORTC==0) PORTc=8; } for(a=0;a<5;a++) { Eeprom_Write(a+5,19); } goto S; } else { Lcd_Out(2,1,"ERORR"); b++; delay_ms(500); if(b==4){ while(1){delay_ms(500); Lcd_Out(2,1,"LOCKED"); }} } } }