?? ufobeloved.c
字號:
#include<reg51.h>
#include<stdio.h>
#define uint unsigned int
#define ulong unsigned long
sbit P0_0=P0^0; //輸0按鍵
sbit P0_1=P0^1; //輸1按鍵
sbit P0_2=P0^2; //輸2按鍵
sbit P0_3=P0^3; //輸3按鍵
sbit P0_4=P0^4; //輸4按鍵
sbit P0_5=P0^5; //輸5按鍵
sbit P0_6=P0^6; //輸6按鍵
sbit P0_7=P0^7; //輸7按鍵
sbit P2_0=P2^0; //輸8按鍵
sbit P2_1=P2^1; //輸9按鍵
sbit P3_0=P3^0; //紅外接口
sbit P3_1=P3^1; //密碼重設鍵
sbit P3_2=P3^2; //報警LED閃耀
sbit P3_3=P3^3; //報警器接口
ulong sec=666666; //初始密碼為111111
ulong input=0; //確認的輸入值
uint num[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; //0-9的led共陽數字顯示碼
uint count=6; //輸入密碼個數
unsigned char temp; //控制輸入
void delay(uint count) //延時1毫秒子程序
{
uint i,j;
for(i=0;i<count;i++)
for(j=0;j<120;j++)
;
}
void alert(void) //報警30秒子程序
{
uint i,k=1;
for(i=0;i<500;i++)
{
P3_3=1;
delay(30);
P3_3=0;
delay(30);
k=-1*k;
if(k==1)
P3_2=1;
else
P3_2=0;
}
}
void cot(void) //檢查并記錄輸入的數字
{
delay(10);
temp=P0+P2;
if(temp!=0)
{
if(P0_0)
{
input=input*10+0;
}
if(P0_1)
{
input=input*10+1;
}
if(P0_2)
{
input=input*10+2;
}
if(P0_3)
{
input=input*10+3;
}
if(P0_4)
{
input=input*10+4;
}
if(P0_5)
{
input=input*10+5;
}
if(P0_6)
{
input=input*10+6;
}
if(P0_7)
{
input=input*10+7;
}
if(P2_0)
{
input=input*10+8;
}
if(P2_1)
{
input=input*10+9;
}
count--;
P0=0;
P2=0;
while(temp!=0)
{
temp=P0+P2;
delay(10);
}
}
}
void abs(void) //輸入密碼解密過程
{
uint i;
uint j;
uint flag=0;
input=0;
P0=0;
P2=0;
for(i=0;flag==0&&i<10;i++)
{
P1=num[9-i];
delay(10);
for(j=0;flag==0&&j<100;j++)
{
delay(10); ///////////////
temp=P0+P2;
if(temp!=0&&count!=0)
cot();
if(sec==input)
{
P1=0xff;
flag=1;
}
count=6;
}
}
}
void set(void) //輸入密碼過程受Resec子函數調用
{
delay(10);
temp=P0+P2;
if(temp!=0)
{
if(P0_0)
{
P1=num[0];
sec=sec*10+0;
}
if(P0_1)
{
P1=num[1];
sec=sec*10+1;
}
if(P0_2)
{
P1=num[2];
sec=sec*10+2;
}
if(P0_3)
{
P1=num[3];
sec=sec*10+3;
}
if(P0_4)
{
P1=num[4];
sec=sec*10+4;
}
if(P0_5)
{
P1=num[5];
sec=sec*10+5;
}
if(P0_6)
{
P1=num[6];
sec=sec*10+6;
}
if(P0_7)
{
P1=num[7];
sec=sec*10+7;
}
if(P2_0)
{
P1=num[8];
sec=sec*10+8;
}
if(P2_1)
{
P1=num[9];
sec=sec*10+9;
}
count--;
P0=0;
P2=0;
while(temp!=0)
{
P0=0;
P2=0;
delay(10);
temp=P0+P2;
}
}
}
void Resec(void) //重設密碼子函數
{
do{
set();
temp=P0+P2;
}while(count!=0);
P1=0xff;
count=6;
}
void main(void) //主函數
{
P0=0x00;
P2_0=0;
P2_1=0;
P3_0=0;
P3_1=0;
P3_2=0;
while(1)
{
P1=0xff;
if(P3_1)
{
P3_1=0;
sec=0;
Resec();
}
else if(P3_0)
{
P3_0=0;
abs();
if(sec!=input)
alert();
P3_2=0;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -