📄 keyscan119.c
字号:
if(pos_close == 0) //没有到位报警
{
for(i=0;i<3;i++)
sound_buzzer(10);
}
}
sound_buzzer(2);
sound_buzzer(1);
mot_down=0; //反转
mot_up=0; //正转
vcc_kid=0;
}
void initialize(void)
{
WDTCON = 0 ;
INTCON=0x38; //关闭所有中断,B口变位中断允许,int0变化中断允许,TMR0允许
INTCON2=0xFC; //使能B口不上拉,B口中断,int3低优先级上升沿有效,TMR0高优先级
INTCON3=0x38; //int2 int1 低优先级 使能3
RCONbits.IPEN=1; //使能中断优先级
PORTB=PORTB; //读B口的值,为变位中断创造条件*/
T0CON=0x87; //timer0 on, 16bit,内部时钟,256分频 大概3秒
}
void initialize_io (void)
{
//Initialize PORT A INPUT
//RA0低压检测报警,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; //设置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 指纹开关, RB4 键盘开关
//RB5 外部强行闯入 , 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开始(猜测) spiss
//OUT RC2 外盖打开 从sleep恢复 /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 成功标志 录入或登入成功标志
//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 键盘蓝色灯
//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; //设置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; //高优先级中断允许
INTCONbits.PEIE=0; //低优先级中断允许
T0CONbits.TMR0ON =1 ; //开始计时
delay(1000);
if(INTCONbits.INT0IF==1)
{
TMR0H = 0;
TMR0L = 0; //计数器清零
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; //开关门动作之后转入睡眠时间
TMR0L = 0; //计数器清零
sleep_cycle = 2;
INTCONbits.INT0IF =0;
}
if(INTCONbits.T0IF==1)
{
INTCONbits.T0IF =0;
sleep_cycle++;
if(sleep_cycle>=3) //设置睡眠时间
{
sound_buzzer(10);
sleep_prepare(); //睡眠准备
sleep_cycle=0;
TMR0H = 0;
TMR0L = 0; //计数器清零
INTCONbits.GIE=1; //高优先级中断允许
INTCONbits.PEIE=1; //低高优先级中断允许
_asm
sleep
_endasm
}
}
INTCONbits.GIE=1; //高优先级中断允许
INTCONbits.PEIE=1; //低高优先级中断允许
}
void interrupt_handler_low()
{
int i,j;
//判断哪个中断,从而进入相应状态
INTCONbits.PEIE=0; //低优先级中断允许
TMR0H = 0;
TMR0L = 0; //计数器清零
T0CONbits.TMR0ON =1 ; //开始计时
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 键盘开关
{
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; //中断标志清0
if(force_in) //RB5 外部强行闯入
{
force_in_alarm();
}
if (outkey_finger) //RB4 指纹开关
finger_confirm();
}
/* switch(PORTB)
{
case 0x02: //RB1 SW2 D
{
finger_input();
break;
}
case 0x04: //RB2 键盘开关
{
password_confirm();
break;
}
case 0x08: //RB3 SW4 N
{
password_input();
break;
}
case 0x10: //RB4 指纹开关
{
finger_confirm();
break;
}
case 0x20: //RB5 外部强行闯入
{
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; //中断标志清0
PORTB=PORTB; //读B口的值,为变位中断创造条件*/
INTCONbits.GIE=1; //高优先级中断允许
INTCONbits.PEIE=1; //低优先级中断允许
}
char password_confirm()
{
int password_num=0; // 密码计数
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; //重置错误次数
if(pos_close == 1)
mot_move_open();
else
mot_move_close();
return(1);
}
else
{
password_confirm_times++;
if(password_confirm_times>=2) //错误多少次报警
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; // 密码计数
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); //确认正确声音
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 ; //停止计时
}
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--;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -