51单片机 C语言 数码管 密码锁
密码1参照下面的编程修改#include<reg51.h>#include<INTRINS.H>#definePORT_P0P0#definePORT_P1P1unsig...
密码1 参照下面的编程修改
#include <reg51.h>
#include <INTRINS.H>
#define PORT_P0 P0
#define PORT_P1 P1
unsigned char a[11]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xc0};
sbit hang1=P1^4;
sbit hang2=P1^5;
sbit hang3=P1^6;
sbit hang4=P1^7;
sbit lie1=P1^0;
sbit lie2=P1^1;
sbit lie3=P1^2;
sbit lie4=P1^3;
sbit COM1=P2^5;
sbit COM2=P2^4;
sbit COM3=P2^3;
sbit COM4=P2^2;
sbit COM5=P2^1;
sbit COM6=P2^0;
unsigned int anjian_number=0,hang_number=0;
void delay(unsigned int t)
{
unsigned int i;
while(t--)
{
for (i=0;i<60;i++)
{}
}
}
void disp_number(unsigned long number)
{
unsigned long number1,number2,number3,number4,number5,number6;
number1=(number/100000);
number2=((number/10000)%10);
number3=((number/1000)%10);
number4=((number/100)%10);
number5=((number/10)%10);
number6=(number%10);
COM1=0;
PORT_P0=a[number1];
delay(1);
COM1=1;
COM2=0;
PORT_P0=a[number2];
delay(1);
COM2=1;
COM3=0;
PORT_P0=a[number3];
delay(1);
COM3=1;
COM4=0;
PORT_P0=a[number4];
delay(1);
COM4=1;
COM5=0;
PORT_P0=a[number5];
delay(1);
COM5=1;
COM6=0;
PORT_P0=a[number6];
delay(1);
COM6=1;
}
void anjian()
{
if(lie1==0)
{
delay(20);
if(lie1==0)
{
anjian_number=0+hang_number;
disp_number(anjian_number);
}
while(!lie1);
}
if(lie2==0)
{
delay(20);
if(lie2==0)
{
anjian_number=1+hang_number;
disp_number(anjian_number);
}
while(!lie2);
}
if(lie3==0)
{
delay(20);
if(lie3==0)
{
anjian_number=2+hang_number;
disp_number(anjian_number);
}
while(!lie3);
}
if(lie4==0)
{
delay(20);
if(lie4==0)
{
anjian_number=3+hang_number;
disp_number(anjian_number);
}
while(!lie4);
}
}
void main()
{
P2=0xff;
P1=0xff;
while(1)
{
hang1=0;
hang_number=0;
anjian();
hang1=1;
hang2=0;
hang_number=4;
anjian();
hang2=1;
hang3=0;
hang_number=8;
anjian();
hang3=1;
hang4=0;
hang_number=12;
anjian();
hang4=1;
disp_number(anjian_number);
}
} 展开
#include <reg51.h>
#include <INTRINS.H>
#define PORT_P0 P0
#define PORT_P1 P1
unsigned char a[11]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xc0};
sbit hang1=P1^4;
sbit hang2=P1^5;
sbit hang3=P1^6;
sbit hang4=P1^7;
sbit lie1=P1^0;
sbit lie2=P1^1;
sbit lie3=P1^2;
sbit lie4=P1^3;
sbit COM1=P2^5;
sbit COM2=P2^4;
sbit COM3=P2^3;
sbit COM4=P2^2;
sbit COM5=P2^1;
sbit COM6=P2^0;
unsigned int anjian_number=0,hang_number=0;
void delay(unsigned int t)
{
unsigned int i;
while(t--)
{
for (i=0;i<60;i++)
{}
}
}
void disp_number(unsigned long number)
{
unsigned long number1,number2,number3,number4,number5,number6;
number1=(number/100000);
number2=((number/10000)%10);
number3=((number/1000)%10);
number4=((number/100)%10);
number5=((number/10)%10);
number6=(number%10);
COM1=0;
PORT_P0=a[number1];
delay(1);
COM1=1;
COM2=0;
PORT_P0=a[number2];
delay(1);
COM2=1;
COM3=0;
PORT_P0=a[number3];
delay(1);
COM3=1;
COM4=0;
PORT_P0=a[number4];
delay(1);
COM4=1;
COM5=0;
PORT_P0=a[number5];
delay(1);
COM5=1;
COM6=0;
PORT_P0=a[number6];
delay(1);
COM6=1;
}
void anjian()
{
if(lie1==0)
{
delay(20);
if(lie1==0)
{
anjian_number=0+hang_number;
disp_number(anjian_number);
}
while(!lie1);
}
if(lie2==0)
{
delay(20);
if(lie2==0)
{
anjian_number=1+hang_number;
disp_number(anjian_number);
}
while(!lie2);
}
if(lie3==0)
{
delay(20);
if(lie3==0)
{
anjian_number=2+hang_number;
disp_number(anjian_number);
}
while(!lie3);
}
if(lie4==0)
{
delay(20);
if(lie4==0)
{
anjian_number=3+hang_number;
disp_number(anjian_number);
}
while(!lie4);
}
}
void main()
{
P2=0xff;
P1=0xff;
while(1)
{
hang1=0;
hang_number=0;
anjian();
hang1=1;
hang2=0;
hang_number=4;
anjian();
hang2=1;
hang3=0;
hang_number=8;
anjian();
hang3=1;
hang4=0;
hang_number=12;
anjian();
hang4=1;
disp_number(anjian_number);
}
} 展开
1个回答
展开全部
密码锁制作电路及程序设计流程
http://hi.baidu.com/lsxshaoxin/item/f13aaf1ec38168e45e53b131
--------------------------------------------------------------------------------------------
以下的单片机c语言和电路手册资料值得参考一下。特别适合电子从业人员
不平凡的单片机学习资料,很好的单片机教程,超好用,一个不占内存的教程,有案例。
http://hi.baidu.com/dzkfw/blog/item/4a188216fd986b12c83d6d05.html
1、最新版单片机编程宝典下载地址,学习单片机编程必备手册
2、单片机c语言运用例子
3、十天学会单片机c语言和单片机制作,最好的单片机资料
这款软件也很不错,推荐一下 [特别好用,资料覆盖范围广] :电路公式计算器http://hi.baidu.com/dzkfw/blog/item/7a947b4f588099d1d0c86a3e.html
http://hi.baidu.com/lsxshaoxin/item/f13aaf1ec38168e45e53b131
--------------------------------------------------------------------------------------------
以下的单片机c语言和电路手册资料值得参考一下。特别适合电子从业人员
不平凡的单片机学习资料,很好的单片机教程,超好用,一个不占内存的教程,有案例。
http://hi.baidu.com/dzkfw/blog/item/4a188216fd986b12c83d6d05.html
1、最新版单片机编程宝典下载地址,学习单片机编程必备手册
2、单片机c语言运用例子
3、十天学会单片机c语言和单片机制作,最好的单片机资料
这款软件也很不错,推荐一下 [特别好用,资料覆盖范围广] :电路公式计算器http://hi.baidu.com/dzkfw/blog/item/7a947b4f588099d1d0c86a3e.html
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询