关于51单片机C语言 数码管 4*4按键 简单的密码锁 10
密码是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);
}
} 展开
3个回答
意法半导体(中国)投资有限公司
2023-06-12 广告
2023-06-12 广告
STM32F103是一款高性能的嵌入式芯片,由意法半导体(STMicroelectronics)公司生产。它是STM32系列芯片之一,具有紧凑、低功耗、高性能等特点,被广泛应用于嵌入式系统中。STM32F103的主要特点包括:1. 集成了A...
点击进入详情页
本回答由意法半导体(中国)投资有限公司提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询