?? keyscan119.c
字號(hào):
if(pos_close == 0) //沒有到位報(bào)警
{
for(i=0;i<3;i++)
sound_buzzer(10);
}
}
sound_buzzer(2);
sound_buzzer(1);
mot_down=0; //反轉(zhuǎn)
mot_up=0; //正轉(zhuǎn)
vcc_kid=0;
}
void initialize(void)
{
WDTCON = 0 ;
INTCON=0x38; //關(guān)閉所有中斷,B口變位中斷允許,int0變化中斷允許,TMR0允許
INTCON2=0xFC; //使能B口不上拉,B口中斷,int3低優(yōu)先級(jí)上升沿有效,TMR0高優(yōu)先級(jí)
INTCON3=0x38; //int2 int1 低優(yōu)先級(jí) 使能3
RCONbits.IPEN=1; //使能中斷優(yōu)先級(jí)
PORTB=PORTB; //讀B口的值,為變位中斷創(chuàng)造條件*/
T0CON=0x87; //timer0 on, 16bit,內(nèi)部時(shí)鐘,256分頻 大概3秒
}
void initialize_io (void)
{
//Initialize PORT A INPUT
//RA0低壓檢測(cè)報(bào)警,RA2 光耦OPEN,RA3 光耦CLOSE,RA4 光耦LOCK
//RA5 SW17 R, RA1不知做什么
PORTA = 0; //Initialize PORTG by clearing output data latches
LATA = 0; //; Alternate method to clear output data latches
ADCON1 = 0x0F; //設(shè)置A位I/O口
TRISA = 0xFF; //Set RA<5:0> as inputs
//Initialize PORT B INPUT
//RB0 SW3 OPEN/CLO, RB1 SW2 D , RB3 SW4 N
//RB2 指紋開關(guān), RB4 鍵盤開關(guān)
//RB5 外部強(qiáng)行闖入 , RB6 仿真,RB7 仿真
PORTB = 0; //Initialize PORTB by clearing output data latches
LATB = 0; //; Alternate method to clear output data latches
TRISB = 0xFF; //PORTGB inputs
/*//Initialize PORT C INPUT
//OUT RC0 讓dsp重置 刪除已有指紋 /reset
//OUT RC1 spi開始(猜測(cè)) spiss
//OUT RC2 外蓋打開 從sleep恢復(fù) /pwr_on
//IN/OUT RC3 spi clock sck
//IN RC4 master in slave out miso
//OUT RC5 slave in master out mosi
// RC6,RC7 不知用途
*/
PORTC = 0; //Initialize PORTC by clearing output data latches
LATC = 0; //; Alternate method to clear output data latches
TRISC = 0x10; //0001 0000
//Initialize PORT D INPUT
//IN RD0 成功標(biāo)志 錄入或登入成功標(biāo)志
//OUT RD7 MOT-
PORTD = 0; //Initialize PORTD by clearing output data latches
LATD = 0; //; Alternate method to clear output data latches
TRISD = 0x01; //0000 0001
//Initialize PORT E INPUT
//RE0 VCC_IO 接通 與VCC_6V 高有效
//RE7 VCC_IO2 接通 與VCC_6V 高有效
//RE2 KID電源 接通 與VCC_6V 恩
//RE1 MOT+
//RE3 BUZZ聲音控制 沒有用到
//RE4 鍵盤面板燈
//RE5 鍵盤藍(lán)色燈
//RE6 下拉了 沒有用
PORTE = 0; //Initialize PORTE by clearing output data latches
LATE = 0; //; Alternate method to clear output data latches
TRISE = 0x00; //output
PORTF = 0; //Initialize PORTF by clearing output data latches
LATF = 0; //; Alternate method to clear output data latches
ADCON1 = 0x0F; //設(shè)置F位I/O口
TRISF = 0xF0; //PORTF 0-3輸出,4-7輸入
//Initialize PORT G
//RG0 buzz聲音控制,RG1 指紋RED, RG2 指紋BLUE
PORTG = 0; //Initialize PORTG by clearing output data latches
LATG = 0; //; Alternate method to clear output data latches
TRISG = 0x00; //PORTG 0-4輸出 沒有6,7 5為MCLR
}
void initialize_eeprom()
{
int i,j;
for(i=0;i<6;i++)
epprom_write(i,i+1); //地址i,寫入i,密碼為123456
epprom_write(6,confim_key); //最后一位停止位10
for(i=0;i<9;i++)
current_password[i] = epprom_read(i);
sound_buzzer(4);
i=0;
while (current_password[i]!=confim_key&¤t_password[i]==epprom_read(i))
{i++;}
if (current_password[i]==confim_key && epprom_read(i)==confim_key)
{
keyboard_blue=1;
delay(10000000);
keyboard_blue=0;
}
}
void interrupt_handler_high()
{
INTCONbits.GIE=0; //高優(yōu)先級(jí)中斷允許
INTCONbits.PEIE=0; //低優(yōu)先級(jí)中斷允許
T0CONbits.TMR0ON =1 ; //開始計(jì)時(shí)
delay(1000);
if(INTCONbits.INT0IF==1)
{
TMR0H = 0;
TMR0L = 0; //計(jì)數(shù)器清零
vcc_io = 1; //低壓+光耦
vcc_io2 = 1; //buzz and dsp
sleep_cycle = 0;
delay(100);
if(pos_close == 1)
mot_move_open();
else
mot_move_close();
TMR0H = 0x00; //開關(guān)門動(dòng)作之后轉(zhuǎn)入睡眠時(shí)間
TMR0L = 0; //計(jì)數(shù)器清零
sleep_cycle = 2;
INTCONbits.INT0IF =0;
}
if(INTCONbits.T0IF==1)
{
INTCONbits.T0IF =0;
sleep_cycle++;
if(sleep_cycle>=3) //設(shè)置睡眠時(shí)間
{
sound_buzzer(10);
sleep_prepare(); //睡眠準(zhǔn)備
sleep_cycle=0;
TMR0H = 0;
TMR0L = 0; //計(jì)數(shù)器清零
INTCONbits.GIE=1; //高優(yōu)先級(jí)中斷允許
INTCONbits.PEIE=1; //低高優(yōu)先級(jí)中斷允許
_asm
sleep
_endasm
}
}
INTCONbits.GIE=1; //高優(yōu)先級(jí)中斷允許
INTCONbits.PEIE=1; //低高優(yōu)先級(jí)中斷允許
}
void interrupt_handler_low()
{
int i,j;
//判斷哪個(gè)中斷,從而進(jìn)入相應(yīng)狀態(tài)
INTCONbits.PEIE=0; //低優(yōu)先級(jí)中斷允許
TMR0H = 0;
TMR0L = 0; //計(jì)數(shù)器清零
T0CONbits.TMR0ON =1 ; //開始計(jì)時(shí)
sleep_cycle = 0;
vcc_io = 1; //低壓+光耦
vcc_io2 = 1; //buzz and dsp
delay(100);
sound_buzzer(1);
if(INTCON3bits.INT1IF==1) //RB1 SW2 D
{
INTCON3bits.INT1IF=0;
finger_input();
}
else if(INTCON3bits.INT2IF==1) //RB2 鍵盤開關(guān)
{
INTCON3bits.INT2IF=0;
password_confirm();
}
else if(INTCON3bits.INT3IF==1) //RB3 SW4 N
{
INTCON3bits.INT3IF=0;
password_input();
}
else if(INTCONbits.RBIF==1)
{
INTCONbits.RBIF =0; //中斷標(biāo)志清0
if(force_in) //RB5 外部強(qiáng)行闖入
{
force_in_alarm();
}
if (outkey_finger) //RB4 指紋開關(guān)
finger_confirm();
}
/* switch(PORTB)
{
case 0x02: //RB1 SW2 D
{
finger_input();
break;
}
case 0x04: //RB2 鍵盤開關(guān)
{
password_confirm();
break;
}
case 0x08: //RB3 SW4 N
{
password_input();
break;
}
case 0x10: //RB4 指紋開關(guān)
{
finger_confirm();
break;
}
case 0x20: //RB5 外部強(qiáng)行闖入
{
for(i=0 ; i<20; i++)
{
if(pos_open == 0)
sound_buzzer(10);
}
break;
}
// case 0x40: //RB6
// case 0x80: //RB7
default:
//add error
break;
}//swich end*/
INTCON3bits.INT1IF=0;
INTCON3bits.INT2IF=0;
INTCON3bits.INT3IF=0;
INTCONbits.RBIF =0; //中斷標(biāo)志清0
PORTB=PORTB; //讀B口的值,為變位中斷創(chuàng)造條件*/
INTCONbits.GIE=1; //高優(yōu)先級(jí)中斷允許
INTCONbits.PEIE=1; //低優(yōu)先級(jí)中斷允許
}
char password_confirm()
{
int password_num=0; // 密碼計(jì)數(shù)
int i=0;
keyboard_blue=1;
while(outkey_keyboard)
{
if(key_scan() )
{
if(current_key!=confim_key)
{
current_password[password_num] = current_key;
sound_buzzer(1);
password_num++;
}
else
{
current_password[password_num] = confim_key;
password_num=0;
sound_buzzer(1);
while (current_password[password_num]!=confim_key
&¤t_password[password_num]==epprom_read(password_num))
{password_num++;}
if (current_password[password_num]==confim_key && epprom_read(password_num)==confim_key)
{
keyboard_red=1;
delay(100000000);
keyboard_red=0;
keyboard_blue=0;
password_confirm_times=0; //重置錯(cuò)誤次數(shù)
if(pos_close == 1)
mot_move_open();
else
mot_move_close();
return(1);
}
else
{
password_confirm_times++;
if(password_confirm_times>=2) //錯(cuò)誤多少次報(bào)警
for(i=0;i<4;i++)
sound_buzzer(1);
keyboard_blue=0;
return(0);
}
}
delay(10);
//delay(10000000);
}
}
delay(10);
keyboard_blue=0;
return(0);
}
char password_input()
{
int i=0,j=0;
int password_num=0; // 密碼計(jì)數(shù)
keyboard_blue=1;
while(outkey_keyboard)
{
if(key_scan())
{
if(current_key!=confim_key)
{
current_password[password_num] = current_key;
sound_buzzer(1);
password_num++;
}
else
{
current_password[password_num] = confim_key;
if(password_num < 9&& password_num > 5) //6到8位密碼
{
for(i=0;i<9;i++)
epprom_write(i,current_password[i]);
sound_buzzer(3); //確認(rèn)正確聲音
keyboard_red=1;
delay(100000000);
keyboard_red=0;
password_num=0;
keyboard_blue=0;
return(1);
}
else
{
sound_buzzer(10);
password_num=0;
keyboard_blue=0;
return(0);
}
}
}
}
keyboard_blue=0;
return(0);
}
void sleep_prepare()
{
vcc_io = 0; //低壓+光耦
vcc_io2 = 1; //buzz and dsp
vcc_kid = 0;
PORTFbits.RF1 = 0;
PORTFbits.RF2 = 0;
PORTFbits.RF3 = 0;
keyboard_red = 0;
keyboard_blue= 0;
buzz = 0;
finger_red = 0;
finger_blue = 0;
mot_up = 0;
mot_down = 0;
T0CONbits.TMR0ON =0 ; //停止計(jì)時(shí)
}
void finger_confirm()
{
finger_blue = finger_blue^1;
delay(100000);
}
void finger_input() //指紋輸入
{
finger_red = finger_red^1;
}
void finger_del() //指紋刪除
{
}
void force_in_alarm()
{
int i;
for(i=0 ; i<20; i++)
sound_buzzer(10);
}
void delay(int delaytime)
{
while(delaytime)
delaytime--;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -