main.c
#include <reg51.h>
#include <intrins.h>
#include <string.h>
#include <stdio.h>
#include "kenscan.h"
#include "config.h"
#include "anjian.h"
sbit DX=P2^0;
sbit WX=P2^1;
sbit BEEP=P2^3;
sbit green=P2^6;
sbit red=P2^7;
unsigned char password[8]={16,16,16,16,16,16,16,16};
u8 code key[]={'0','1','2','3','4','5','6','7','8','9','*','#'};
unsigned char admin[8]={1,9,9,8,0,4,2,2};
unsigned char code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,0x00};
u8 keynum;
u8 flag=0,esc=0;
void led8_display()
{
u8 i;
u8 temp=0xfe;
unsigned char tag=0;
for(i=1;i<=8;i++)
{
P0=0xff;
WX=1;
P0=temp;
WX=0;
temp=_crol_(temp,1);
P0=0x00;
DX=1;
P0=table[password[i-1]];
DX=0;
delay(1);
}
}
void init()
{
TMOD=0x01;
EA=1;
ET0=1;
TR0=0;
}
void anjiansound()
{
TR0=1;
sound(keynum);
delay(300);
BEEP=1;
TR0=0;
}
/******************密码验证********************************************/
unsigned char cmpstr(unsigned char p[],unsigned char q[])
{
u8 j=1;
int i;
for(i=7;i>=0;i--)
if(p[i]!=q[i])
{
j=0;
break;
}
return j;
}
/******************清除输入********************************************/
void clear()
{
unsigned char i;
for(i=0;i<8;i++)
password[i]=16;
led8_display();
}
void main()
{
unsigned char i;
init();
while(1){
keynum=keyscanphone();
if(keynum<12)
{
if(keynum<10){
for(i=0;i<7;i++)
password[i]=password[i+1];
password[7]=keynum;
}
if(keynum==10){
if(cmpstr(password,admin)==1)
{
green=0;
delay(3000);
green=1;
}
else
{
red=0;
delay(3000);
red=1;
}
clear();
}
if(keynum==11){
clear();
}
anjiansound();
}
led8_display();
}
}
void Time0() interrupt 1
{
TH0 = TH00;
TL0 = TL00;
BEEP=~BEEP;
}