#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit RS=P1^7;
sbit RW=P1^6;
sbit E=P1^5;
sbit PSB=P0^7; //硬件上的串口,并口选择位,此开发板用的是并口,此位置1为并口
uchar code table_7[]={"("};
uchar code table_8[]={")"};
uchar code table_9[]={" "};
uchar code table_b[]={"请刷卡"};
uchar code table_c[]={"密码错!"};
uchar code table_d[]={"请接射频卡模块!"};
/////延时函数//////////////////////////////////
void delay1(unsigned int z)
{
unsigned int x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
///////////////////////////////////////////////
//////写命令////////////////////////////////////
void WriteCommand(uchar a)
{
E=0; //1读取信息;1-0下降沿执行指令
RS=0; //0=写指令;1=写数据
RW=0; //0=写指令或数据;1=读LCD信息
E=1; //读信息
P2=a; //写指令
delay1(5); //延时
E=0; //执行指令
delay1(5); //延时
}
//////////////////////////////////////////////////
//////写数据//////////////////////////////////////
void WriteData(uchar b)
{
E=0; //执行指令
RS=1; //写数据
RW=0; //写数据
E=1; //读取信息
P2=b; //写数据
delay1(5); //延时
E=0; //执行指令
delay1(5); //延时
}
void initial_LCD()
{
PSB=1; //选择为并口
WriteCommand(0x01); //清屏
WriteCommand(0x30); //功能设置。8字节界面,基本指令集。(0011 x0xx)
WriteCommand(0x0c); //显示设置。整体显示,光标不显示,光标不反向。(0000 1110)
WriteCommand(0x06); //输入方式设置。光标右移,地址位加1;整体右移。(0000 0110)
// WriteCommand(0x14); //光标右移。
}
void LCD_Data(uchar LCDbyte )
{
unsigned char count;
count=(LCDbyte&0xf0)>>4;
if (count>0x9) WriteData(count%9+0x40);
else WriteData(count+0x30);
count=LCDbyte&0x0f;
if (count>9) WriteData(count%9+0x40);
else WriteData(count+0x30);
}
/**********举例:LCD_PutString(1,1,"设置湿度上限");***********/
void LCD_PutString(unsigned char x,unsigned char y,uchar *s)
{
switch(y)
{
case 1: WriteCommand(0x80+x);break;
case 2: WriteCommand(0x90+x);break;
case 3: WriteCommand(0x88+x);break;
case 4: WriteCommand(0x98+x);break;
default:break;
}
while(*s>0)
{
WriteData(*s);
s++;
delay1(10);
}
}
void dis_Request1()
{
uchar i;
WriteCommand(0x9b);
for (i=1;i<=1;i++)
WriteData(table_7[i-1]) ;
WriteCommand(0x9c);
for (i=1;i<=1;i++)
WriteData(table_8[i-1]) ;
}
void dis_Request2()
{
uchar i;
WriteCommand(0x9a);
for (i=1;i<=1;i++)
WriteData(table_7[i-1]) ;
WriteCommand(0x9d);
for (i=1;i<=1;i++)
WriteData(table_8[i-1]) ;
}
void dis_Request3()
{
uchar i;
WriteCommand(0x99);
for (i=1;i<=1;i++)
WriteData(table_7[i-1]) ;
WriteCommand(0x9e);
for (i=1;i<=1;i++)
WriteData(table_8[i-1]) ;
}
void DispalyLcd1()
{
unsigned char i;
WriteCommand(0x98);
for (i=1;i<=16;i++)
WriteData(table_9[i-1]) ;
}
void DispalyLcd_home() //工作模式
{
LCD_PutString(1,1,"门禁卡系统");
LCD_PutString(2,2,"工作模式");
LCD_PutString(2,3,"请刷卡");
}
void DispalyLcd_home1() //注册模式
{
LCD_PutString(1,1,"门禁卡系统");
LCD_PutString(2,2,"注册模式");
LCD_PutString(2,3,"请刷卡");
}
void DispalyLcd_home2() //清除模式
{
LCD_PutString(1,1,"门禁卡系统");
LCD_PutString(2,2,"注销模式");
LCD_PutString(2,3,"请刷卡");
}
void dis_passerror()
{
unsigned char i;
WriteCommand(0x88);
for (i=1;i<=16;i++)
WriteData(table_9[i-1]) ;
DispalyLcd1();
WriteCommand(0x9a);
for (i=1;i<=7;i++)
WriteData(table_c[i-1]) ;
}
|