你这个问题内容量太大,不可能有谁那么多时间给你开发,我这边有个做过的类似的,代码送你了。
#include
#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;
}
}
我以前写过一个程序,要是找找,还是能找到的,要比你的电路简单多了.
输出就不讲了,输出电平时间是可以设置的.
输入我讲一下,我用的是1个按键,密码输入方法类似摩尔斯码,如输入2,就是连续的按2下,如果输入8,就连续按8下,在这个按键上并一个LED,这个LED为状态显示,当密码输入正确时,LED闪一下.
如果密码都正确,输出脚输出高电平.
这个电路简单吧.
按你说的有点麻烦 不过还是可以完成的
还可以不难
懂事电子设计 Vgz