|
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit led=P1^0;
sbit KEY1=P3^3;
sbit KEY2=P3^4;
sbit ledgree=P3^5;
sbit ledred=P3^6;
sbit beep=P3^7;
bit f;//f為開、閉鎖標(biāo)志
unsigned char duanma[19] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x54,0x5c,0x40};//smg數(shù)組
unsigned char weima[8] = {0xfe, 0xfd, 0xfb, 0xf7, 0xef, 0xdf, 0xbf, 0x7f};//選擇數(shù)碼管幾號(hào)顯示
unsigned char x[4];
unsigned char z[4]={1,1,1,1};
unsigned char pwd1,pwd2;
unsigned char k,j,t,s,a,d,c,p,q;
void delay(uint i);
void weizhi(c,p)
{
switch(c)//位選
{
case 1:P2 = ~weima[0];
break;
case 2:P2 = ~weima[1];
break;
case 3:P2 = ~weima[2];
break;
case 4:P2 = ~weima[3];
break;
}
P0 = ~duanma[p]; //段選
}
void main(void)//主函數(shù)
{
unsigned char i = 0;
uchar pwd1 = 0; // 第一位密碼
uchar pwd2 = 0; // 第2位
t=3;
f=0;
ledred=0;
ledgree=0;
beep=0;
while (1)
{
if(KEY1 == 0)
{ //按鍵1按下
delay(1000); // 延時(shí)去抖動(dòng)
if(KEY1 == 0)
{
pwd1++; // 第一位密碼加1
if(pwd1 > 9) pwd1 = 0; // 如果超過9,則從0開始
}
}
if(KEY2 == 0)
{ //按鍵2按下
delay(1000); // 延時(shí)去抖動(dòng)
if(KEY2 == 0)
{
x[pwd2]=pwd1;
pwd2++;
}
}
if(pwd2==5) //確認(rèn)鍵按下,判斷密碼是否正確
{
pwd2=0;
for(d=0;d<4;d++)
if(x[d]!=z[d])
f=1; //判斷密碼
if(f==1) //密碼錯(cuò),閉鎖
{
ledred=1;
ledgree=0;
f=0;
t=t-1;
q=1;
delay(9000);
}
else
{
ledred=0;//密碼正確,開鎖
ledgree=1;
s=1;
}
}
if(s==1)
{
while(1)
{
weizhi(1,1); //在數(shù)碼管的第1位置顯示1
delay();
P0=~0x00;
weizhi(2,1); //在數(shù)碼管的第2位置顯示1
delay();
P0=~0x00;
weizhi(3,1); //在數(shù)碼管的第3位置顯示1
delay();
P0=~0x00;
weizhi(4,1); //在數(shù)碼管的第4位置顯示1
delay();
P0=~0x00;
}
}
if(t==0&&q==1)
for(i=0;i<9000;i++)
{
weizhi(1,18); //在數(shù)碼管的第1位置顯示-
delay();
P0=~0x00;
weizhi(2,16); //在數(shù)碼管的第2位置顯示n
delay();
P0=~0x00;
weizhi(3,17); //在數(shù)碼管的第3位置顯示o
delay();
P0=~0x00;
weizhi(4,18); //在數(shù)碼管的第4位置顯示-
delay();
P0=~0x00;
beep=~beep;
}
if(s!=1)
for (i=0; i<10; i++)
{
P2 = ~weima[pwd2]; // 依次選擇數(shù)碼管1-8
P0 = ~duanma[pwd1]; // 依次顯示1-9
delay();
P0 = 0x00;
}
}
}
void delay(uint i)//延時(shí)函數(shù)
{
while(i--);
}
|
-
-
MMSAA.zip
2024-6-25 14:48 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
58.43 KB, 下載次數(shù): 8, 下載積分: 黑幣 -5
仿真
評(píng)分
-
查看全部評(píng)分
|