电子密码锁完整代码
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
#include
#include
#include
#include "VIIC_C51.h"
#define uchar unsigned char
#define uint unsigned int
#define CSI24WC02 0XA0
#define uchar unsigned char
sbit lcdrs=P2^0;
sbit lcdrw=P2^1;
sbit lcden=P2^2;
sbit alarm=P2^3;
sbit red=P2^7;
sbit green=P2^6;
sbit KEY_INT=P3^2;
//led test
sbit LED1=P3^5;
sbit LED2=P3^1;
uchar hour,min,sec,us;
uchar flag=1,canscan=0,lock=0;
uchar password[8]={0,0,0,0,0,0,0,0};
uchar input[8]={0,1,2,3,4,5,6,7};
uchar code a[]={0xF7,0xFB,0xFD,0xFE};
unsigned char DelayNS(unsigned char no) {
unsigned char i,j;
for(; no>0; no--)
{
for(i=0; i<100; i++)
for(j=0; j<100; j++);
}
return 0;
}
unsigned char delay_eep(unsigned char j) {
unsigned char k,l;
for(l=0;l<=j;l++)
for(k=0;k<=250;k++);
return 0;
}
void t0_init()
{
TMOD=0x01;
TL0=0xb0;
TH0=0x3c;
TR0=0;
EA=1;
ET0=1;
}
void delay(uchar n)
{
uchar i;
while(n--)
for(i=125;i>0;i--);
}
//lcd 写命令
void write_com(uchar com) {
lcdrs=0;
lcdrw=0;
P0=com;
delay(2);
lcden=1;
delay(2);
lcden=0;
}
//lcd 写数据
void write_data(uchar date) {
lcdrs=1;
lcdrw=0;
P0=date;
delay(2);
lcden=1;
delay(2);
lcden=0;
//lcd 的初始化
void init_lcd()
{
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
}
// lcd 清屏
void clearscn()
{
write_com(0x06);
write_com(0x01);
}
//lcd 显示坐标
void gotoxy(uchar x,uchar y) {
if(x==1)
write_com(0x80+y);
if(x==2)
write_com(0xc0+y);
}
//写lcd字符串
void write_str(uchar *str) {
while(*str!='\0')
{
write_data(*str);
delay(2);
str++;
}
}
//写一位数字
void write_num(uchar num) {
write_data(0x30+num);
}
//写两位数
void write_num2(uchar num)
uchar x,y;
x=num/10;
y=num%10;
write_num(x);
write_num(y);
}
// 矩阵键盘扫描函数
uchar scan(void)
{
uchar row,col;
uchar j,m;
P1=0xF0;
if((P1&0xF0)!=0xF0)
{
delay(1);
if((P1&0xF0)!=0xF0)
col=~(P1|0x0F);
j=0;
P1=a[j];
while(j<=3)
{
if((P1&0xF0)!=0xF0)
{
row=~a[j];
break;
}
else
{j++;P1=a[j];}
}
m=row+col;
return(m);
}
else
return(0);
}
uchar coding(uchar m)
{
uchar k;
switch(m)
{
case(0x08+0x80):k=0;break;
case(0x08+0x40):k=1;break;