微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 门禁系统项目驱动程序

门禁系统项目驱动程序

时间:11-30 来源:互联网 点击:

/******************************DS1302时钟程序*******************************/

void DS1302_WriteByte(uchar WData){ //写入一个字节
uchar Cnt;
for(Cnt=0;Cnt<8;Cnt++){
WData >>= 1;//写入数据时先写低位再写高位(D0---D7)
CLK_1302 = 0;
IO_1302 = CY;
CLK_1302 = 1; //上升沿将数据写入1302
}
}
uchar DS1302_ReadByte(){ //读出一个字节
uchar Cnt,RData = 0;
for(Cnt = 0;Cnt < 8;Cnt ++){
RData >>= 1;//读数据时先读低位再读高位(D0---D7)
CLK_1302 = 1;
CLK_1302 = 0; //下降沿将数据读出来
if(IO_1302)
RData |= 0x80;
elseRData &= 0x7f;
}
return RData;
}
void DS1302_WriteData(uchar Waddr,uchar Wdata){ //向某地址中写入一个字节的数据
RST_1302 = 0;
CLK_1302 = 0;
RST_1302 = 1;
DS1302_WriteByte(Waddr);//写入地址
DS1302_WriteByte(Wdata);//写入数据
CLK_1302 = 0;
RST_1302 = 0;
}
uchar DS1302_ReadData(uchar RAddr){ //读取1302某地址中一个字节的数据
uchar Rdata;
RST_1302 = 0;
CLK_1302 = 0;
RST_1302 = 1;
DS1302_WriteByte(RAddr);//写入读取数据的地址
Rdata = DS1302_ReadByte();//读取数据
RST_1302 = 0;
IO_1302 = 1;
return(Rdata);
}
void DS1302_SetTime(){ //设置1302时间
uchar Cnt,Add = 0x80;//秒 寄存器的写地址0x80
// 秒 分 时 日 月 星期 年
uchar STime[7] = {0x00,0x19,0x14,0x18,0x07,5,0x08};

DS1302_WriteData(0x8e,0x00);//禁止写保护(可写入数据)
for(Cnt = 0;Cnt < 7;Cnt ++,Add += 2)//循环写入秒,分,时,日,月,星期,年
DS1302_WriteData(Add,STime[Cnt]);
DS1302_WriteData(0x8e,0x80);//写保护(不能写入数据)
}
void DS1302_GetTime(){ //读取1302中当前时间
uchar Cnt,Addr = 0x81;//秒 寄存器的读地址0x81
for(Cnt = 0;Cnt < 7;Cnt ++,Addr += 2)//循环读取秒,分,时,日,月,星期,年
GetTime[Cnt] = DS1302_ReadData(Addr);
}

/**************************液晶屏显示程序******************************/

void LCD_DisTime(){//显示从1302读取的时间
DS1302_GetTime();
LCD_Data_DisNum(32,0,num[GetTime[6] >> 4]);//年(由1302循环读出显示)
LCD_Data_DisNum(38,0,num[GetTime[6] & 0x0f]);
LCD_Data_DisNum(50,0,num[GetTime[4] >> 4]);//月
LCD_Data_DisNum(56,0,num[GetTime[4] & 0x0f]);
LCD_Data_DisNum(68,0,num[GetTime[3] >> 4]);//日
LCD_Data_DisNum(74,0,num[GetTime[3] & 0x0f]);
LCD_Data_DisNum(122,0,num[GetTime[5]]);//星期
LCD_Data_DisNum(32,2,num[GetTime[2] >> 4]);//时
LCD_Data_DisNum(38,2,num[GetTime[2] & 0x0f]);
LCD_Data_DisNum(50,2,num[GetTime[1] >> 4]);//分
LCD_Data_DisNum(56,2,num[GetTime[1] & 0x0f]);
LCD_Data_DisNum(68,2,num[GetTime[0] >> 4]);//秒
LCD_Data_DisNum(74,2,num[GetTime[0] & 0x0f]);
}
void LCD_DisCell(){//显示固定不变的内容(日期,时间等汉字及符号的显示)(图1~4)
LCD_Data_DisWord(2,0,ri);
LCD_Data_DisWord(14,0,qi);
LCD_Data_DisNum(26,0,maohao);
LCD_Data_DisNum(44,0,heng);
LCD_Data_DisNum(62,0,heng);
LCD_Data_DisWord(92,0,xing);
LCD_Data_DisWord(104,0,qi);
LCD_Data_DisNum(116,0,maohao);
LCD_Data_DisWord(2,2,shi);
LCD_Data_DisWord(14,2,jian);
LCD_Data_DisNum(26,2,maohao);
LCD_Data_DisNum(44,2,heng);
LCD_Data_DisNum(62,2,heng);
}
void LCD_Display1(){//无操作状态时显示内容
LCD_DisCell();
LCD_Data_DisWord(34,4,wu);//无操作状态
LCD_Data_DisWord(46,4,cao);
LCD_Data_DisWord(58,4,zuo);
LCD_Data_DisWord(70,4,zhuang);
LCD_Data_DisWord(82,4,tai);
}
void LCD_Display2(){//刷卡后显示此卡有效或无效
LCD_Data_DisWord(2,4,ka);//显示刷卡后的卡号
LCD_Data_DisWord(14,4,hao);
LCD_Data_DisNum(26,4,maohao);
}
void LCD_Display3(){//显示电机状态:打开或关闭
//LCD_DisCell();//显示固定不变的内容
LCD_Data_DisWord(2,4,dian);//电机状态
LCD_Data_DisWord(14,4,ji);
LCD_Data_DisWord(26,4,zhuang);
LCD_Data_DisWord(38,4,tai);
LCD_Data_DisNum(50,4,maohao);
}
void LCD_Display4(){//显示数据上传过程:上传成功或失败
LCD_Data_DisWord(2,4,shu);//数据上传
LCD_Data_DisWord(14,4,ju);
LCD_Data_DisWord(26,4,shang);
LCD_Data_DisWord(38,4,chuan);
LCD_Data_DisNum(50,4,maohao);

LCD_Data_DisWord(56,4,kuang1);
LCD_Data_DisWord(68,4,kuang1);
LCD_Data_DisWord(80,4,kuang1);
LCD_Data_DisWord(92,4,kuang1);
LCD_Data_DisWord(104,4,kuang1);
LCD_Data_DisWord(116,4,kuang1);

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top