你这个问题内容量太大,不可能有谁那么多时间给你开发,我这边有个做过的类似的,代码送你了。
#include?<msp430x14x.h>
#include?"Delay.h"
#include?"x24c02.h"
#include?"LCD1602.h"
uchar?LCD_ID_1[16]?=?{"Password:?------"};
uchar?LCD_ID_2[16]?=?{"Old?Code:?------"};
uchar?LCD_ID_3[16]?=?{"????????"};
uchar?LCD_ID_4[16]?=?{"New?Code:?------"};
#define?JI_OPEN?P3OUT|=BIT6
#define?JI_CLOSE?P3OUT&=~BIT6
uchar?a=10,b=10+0x40,c=0,i=0,j=0,k=0,super=0;
uchar?flag=0;
uchar?table1[6]={1,2,3,4,5,6};
uchar?table2[6]={0,0,0,0,0,0};
uchar?table3[6]={0,0,0,0,0,0};
uchar?supercode[6]={8,8,8,8,8,8};
//SCL时钟线
#define?SCO_SET?P1OUT|=BIT3//输出高
#define?SCO_RESET?P1OUT&=(~BIT3)//输出低
#define?SCO_IN?(P1IN&BIT3)//输出
#define?SCOIN?P1DIR&=(~BIT3)//设置输入
#define?SCOOUT?P1DIR|=BIT3//设置输出
//SDA数据线
#define?SDO_SET?P1OUT|=BIT2
#define?SDO_RESET?P1OUT&=(~BIT2)
#define?SDO_IN?(P1IN&BIT2)
#define?SDOIN?P1DIR&=(~BIT2)
#define?SDOOUT?P1DIR|=BIT2
void?shuru(void);
void?shezhi(void);
void?bijiao(void);
uchar?chumo_read(void)
{
?uchar?i,dat;
?SCOOUT;//设置输出
?SCO_RESET;//输出低
?
?SDOOUT;
?SDO_SET;
?delay_us(93);
?SDO_RESET;
?delay_us(10);
?SDOIN;
?
?for(i=0;i<16;i++)
?{
??SCO_SET;
??delay_us(5);
??
??if(SDO_IN!=0)
??{
???dat=i+1;
??}
??
??SCO_RESET;
??delay_us(5);
?}
?delay_ms(2);
?return?dat;
}??
void?OPEN(void)
{
?P1OUT?|=?BIT4;
?P3OUT?&=~BIT5;
?delay_ms(1000);delay_ms(1000);
?P3OUT?&=~BIT5;
?P1OUT?&=~BIT4;
}
void?CLOSE(void)
{
?P3OUT?|=?BIT5;
?P1OUT?&=~BIT4;
?delay_ms(1000);delay_ms(1000);
?P3OUT?&=~BIT5;
?P1OUT?&=~BIT4;
}
void?main(?void?)
{
?//系统初始化
?WDT_Init();?//STOP?WDT
?MCLK_Init();?//MCLK=8M
?Port_Init();?//CLOSE?ALL?PORT
?
?P3DIR?|=?BIT5;
?P1DIR?|=?BIT4;
?P3OUT?&=~BIT5;
?P1OUT?&=~BIT4;
?d24c_init();
?
?L1602_Init();
?L1602_string(1,?1,?LCD_ID_1);
?
?P3DIR|=BIT6;
?P3DIR&=~BIT7;
?P6DIR|=BIT2;
?JI_CLOSE;
?
?delay_ms(10);
?table1[0]=d24c_read(1);
?delay_ms(20);
?table1[1]=d24c_read(2);
?delay_ms(20);
?table1[2]=d24c_read(3);
?delay_ms(20);
?table1[3]=d24c_read(4);
?delay_ms(20);
?table1[4]=d24c_read(5);
?delay_ms(20);
?table1[5]=d24c_read(6);
?delay_ms(500);
?
?while(1)
?{
??delay_ms(100);
??shuru();
??shezhi();
??bijiao();
?}
}
void?shuru(void)
{
?wcmd(0x80+a+c);
?wcmd(0x0f);
?
?if((chumo_read()!=0)&&(chumo_read()<11))
?{
??delay_ms(10);
??if(chumo_read()!=0)
??{
???table2[c]=chumo_read();
???L1602_char(1,a+c+1,(chumo_read()%10)+0X30);
???c++;
???delay_ms(500);
???if(c==6)
???{
????c=0;
????L1602_string(1,?1,?LCD_ID_1);
???}
??}
?}
?
?j=0;
?for(i=0;i<6;i++)
?{
??if(table1[i]!=table2[i])
??{
???j=1;
???break;
??}
?}?
?if(chumo_read()==13)

?{
??delay_ms(10);
??if(chumo_read()==13)
??{
???c=0;
???L1602_string(1,?1,?LCD_ID_1);
???delay_ms(1000);
??}
?}
}
void?shezhi(void)
{
?if(chumo_read()==16)
?{
??delay_ms(10);
??if(chumo_read()==16)
??{
???L1602_string(1,?1,?LCD_ID_3);
???L1602_string(2,?1,?LCD_ID_2);
???flag=1;
???c=0;
???delay_ms(500);
??}
?}
?while(flag==1)
?{
??wcmd(0x80+0x40+a+c);
??wcmd(0x0f);
??
???if((chumo_read()!=0)&&(chumo_read()<11))
?{
??delay_ms(10);
??if(chumo_read()!=0)
??{
???table2[c]=chumo_read();
???L1602_char(2,a+c+1,(chumo_read()%10)+0X30);
???c++;
???delay_ms(500);
???if(c==6)
???{
????c=0;
????L1602_string(2,?1,?LCD_ID_2);
?????super=1;
?????for(i=0;i<6;i++)
?????{
??????if(supercode[i]!=table2[i])
??????{
???????super=0;
???????break;
??????}
?????}?
???}
??}
?}
?
?k=1;
?for(i=0;i<6;i++)
?{
??if(table1[i]!=table2[i])
??{
???k=0;
???break;
??}
?}?
?if(chumo_read()==13)
?{
??delay_ms(10);
??if(chumo_read()==13)
??{
???c=0;
???L1602_string(2,?1,?LCD_ID_2);
???delay_ms(1000);
??}
?}
??
?if(k==1?||?super?==?1)
?{
???L1602_string(2,?1,?LCD_ID_4);
?}
??while(k==1?||?super==1)
??{
???wcmd(0x80+0x40+a+c);
???wcmd(0x0f);
???if((chumo_read()!=0)&&(chumo_read()<11))
???{
????delay_ms(10);
????if(chumo_read()!=0)
????{
?????table1[c]=chumo_read();
?????L1602_char(2,a+c+1,(chumo_read()%10)+0X30);
?????c++;
?????if(c==6)
?????{
??????delay_ms(1000);
??????c=0;
??????flag=0;
??????k=0;
??????super?=?0;
??????d24c_write(1,table1[0]);
??????delay_ms(30);
??????d24c_write(2,table1[1]);
??????delay_ms(30);
??????d24c_write(3,table1[2]);
??????delay_ms(30);
??????d24c_write(4,table1[3]);
??????delay_ms(30);?
??????d24c_write(5,table1[4]);
??????delay_ms(30);
??????d24c_write(6,table1[5]);
??????delay_ms(30);??
?
??????L1602_string(1,?1,?LCD_ID_1);
??????L1602_string(2,?1,?LCD_ID_3);
??????}
?????}
?????delay_ms(400);
???}
???delay_ms(100);
???if(chumo_read()==13)
???{
????delay_ms(10);
????if(chumo_read()==13)
????{
?????c=0;
?????L1602_string(2,?1,?LCD_ID_2);
?????delay_ms(500);
????}
???}
??}
?}
}
void?bijiao()
{
?if((j==0)||((P3IN&BIT7)!=0))
?{
??JI_OPEN;
??P6OUT&=~BIT2;
??OPEN();
??delay_ms(2000);
??L1602_string(1,?1,?LCD_ID_1);
??for(i=0;i<6;i++)
??{
???table2[i]=0;
??}
??JI_CLOSE;
??CLOSE();
?}
?else
?{
??P6OUT|=BIT2;

?}
}
CD4017的10个输出端按照密码的编排与响应的10歌按键连接。计数器的10个输出端,每个输出信号同时又作为下一个密码的输入控制信号。接通电源后,电源经R5、C2形成清零脉冲输入IC1的R端,使计数器清零,Q0输出高电平。该电路预置密码为302706249,共9位。按照密码的顺序依次按下密码输入按键:先按下SB3,由图可知,SB3是和IC1的Q0端相连,由于Q0为高电平,这一高电平通过SB3加至晶体管VT的基极,使VT导通,其集电极电压下降。当松开SB3时,VT基极因失去基极电压而截止,它的集电极电压立即上升,这就形成了脉冲的上升沿并输入IC1的CP端,计数器计数一次,输出端前移一位,由Q0至Q1。Q1和SB0相连,当按下SB0时,计数器又输入一个计数脉冲,它的输出端又前移一位,由Q1至Q2.这样按照密码顺序依次按下SB2、SB7、、、SB9,当按下最后一位SB9时,由于SB9与Q8相连,前移一位即为Q9,这最后一位输出的高电平就可作为开锁控制信号输出至执行电路。
电路中还有一个开关SA,它是一只总开关,可根据需要安装在远离键盘的 隐蔽处。正常使用时为打开状态,当需要时即可将其闭合。这时,按动任何按键都无效。
在输入按键中,SB1、SB5、Sb8及SB均为伪码按键,按动后无效。有效按键中,SB2、SB0各重复使用一次,因此用7位按键组成了9位密码开关。由于在键盘中的按键总数为11键,在计算开锁几率时,不应只按有效键来计算,而应将伪码键合并在一起计算


