#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit rs= P2^0; //0输入指令,1输入数据
sbit rw = P2^1; //0向lcd写入指令或者数据,1从lcd读取信息
sbit en= P2^2; //1时读取信息,下降沿执行指令
sbit key1 = P2^4;
sbit key2 = P2^5;
sbit key3 = P2^6;
sbit key4 = P2^7;
uchar code table2[]={0x0f,0x09,0x0f,0x09,0x0f,0x09,0x13,0x00,
0x1f,0x11,0x11,0x1f,0x11,0x11,0x1f,0x00};//月,日
uchar code table3[]={0x00,0x00,0x00,0x02,0x02,0x02,0x02,0x02,
0x00,0x00,0x00,0x08,0x08,0x08,0x08,0x08,
0x1f,0x07,0x0a,0x12,0x02,0x02,0x02,0x02,
0x1f,0x1c,0x0a,0x09,0x08,0x08,0x08,0x08};//林
uchar code table4[]={0x0a,0x1f,0x0a,0x0e,0x0a,0x0e,0x1f,0x1f,
0x00,0x09,0x05,0x09,0x05,0x01,0x1f,0x1f,
0x16,0x16,0x19,0x10,0x1f,0x00,0x00,0x00,
0x01,0x01,0x01,0x01,0x01,0x00,0x00,0x00};//斟
uchar code table5[]={ 0x04,0x16,0x0d,0x04,0x14,0x0f,0x04,0x00,
0x11,0x15,0x19,0x11,0x11,0x1d,0x11,0x00,
0x04,0x05,0x0e,0x14,0x04,0x04,0x00,0x00,
0x11,0x1b,0x15,0x11,0x11,0x11,0x00,0x00};//渊
unsigned char code dis1[] = {"electrical"};
unsigned char code dis2[] = {"engineering"};
unsigned char code dis3[] = {"201736110116"};
void delay(uint n) //延时函数
{
uint x,y;
for(x=n;x>0;x--)
for(y=110;y>0;y--);
}
void lcd_wcom(uchar com) //指令写入函数
{
rs=0; //输入指令
rw=0;
P0=com;
delay(5);
en=1;
en=0;
}
void lcd_wdat(uchar dat) //数据写入函数
{
rs=1; //输入数据
rw=0;
P0=dat;
delay(5);
en=1;
en=0;
}
void lcd_init() //1602lcd初始化函数
{
lcd_wcom(0x38); //功能设定指令:1.数据总线8位 2.显示两行 3. 5*8总线字符
lcd_wcom(0x0c); //控制整体显示并且关闭光标
lcd_wcom(0x06); //屏幕上的文字左移或者右移无效
lcd_wcom(0x01); //清显示,光标复位到地址00H位置
}
void main()
{
char m,i,j,k=0;
lcd_init(); //初始化lcd
//日期显示
while(key1==0&&key2==1&&key3==1&&key4==1) //如果key1按下
{
lcd_wcom(0x40); //设定CGRAM地址
for(m=0;m<16;m++) //将字符“日,月”代码写入CGRAM中
{
lcd_wdat(table2[m]);
}
lcd_wcom(0x86);//指定显示位置
lcd_wdat(0x33);//3
lcd_wcom(0x87); //指定显示位置
lcd_wdat(0); //月
lcd_wcom(0x88);//指定显示位置
lcd_wdat(0x31);//1
lcd_wcom(0x89);//指定显示位置
lcd_wdat(0x38);//8
lcd_wcom(0x8a);//指定显示位置
lcd_wdat(1); //日
if(key1==1&&key2==1&&key3==1&&key4==1)
break;
}
//专业显示
while(key1==1&&key2==0&&key3==1&&key4==1)
{
lcd_wcom(0x80);
while(dis1[i] != '\0')
{
lcd_wdat(dis1[i]);
i++;
}
lcd_wcom(0xc0);
while(dis2[j] != '\0')
{
lcd_wdat(dis2[j]);
j++;
}
if(key1==1&&key2==1&&key3==1&&key4==1)
break;
}
//学号显示
while(key1==1&&key2==1&&key3==0&&key4==1)
{
lcd_wcom(0x80);
while(dis3[k] != '\0')
{
lcd_wdat(dis3[k]);
k++;
}
if(key1==1&&key2==1&&key3==1&&key4==1)
break;
}
//姓名显示
while(key1==1&&key2==1&&key3==1&&key4==0) //如果key4按下
{
while(1){
lcd_wcom(0x40); //设定CGRAM地址
for(m=0;m<32;m++)
{
lcd_wdat(table3[m]);
}
//显示“林”
lcd_wcom(0x83);
lcd_wdat(0);
lcd_wcom(0x84);
lcd_wdat(1);
lcd_wcom(0xc3);
lcd_wdat(2);
lcd_wcom(0xc4);
lcd_wdat(3);
delay(500);
//在原来显示“林”的位置用空字符代替,下面同理
lcd_wcom(0x83);
lcd_wdat(0x20);
lcd_wcom(0x84);
lcd_wdat(0x20);
lcd_wcom(0xc3);
lcd_wdat(0x20);
lcd_wcom(0xc4);
lcd_wdat(0x20);
lcd_wcom(0x40);
for(m=0;m<32;m++)
{
lcd_wdat(table4[m]);
}
lcd_wcom(0x86);
lcd_wdat(0);
lcd_wcom(0x87);
lcd_wdat(1);
lcd_wcom(0xc6);
lcd_wdat(2);
lcd_wcom(0xc7);
lcd_wdat(3);
delay(500);
lcd_wcom(0x86);
lcd_wdat(0x20);
lcd_wcom(0x87);
lcd_wdat(0x20);
lcd_wcom(0xc6);
lcd_wdat(0x20);
lcd_wcom(0xc7);
lcd_wdat(0x20);
lcd_wcom(0x40);
for(m=0;m<32;m++)
{
lcd_wdat(table5[m]);
}
lcd_wcom(0x89);
lcd_wdat(0);
lcd_wcom(0x8a);
lcd_wdat(1);
lcd_wcom(0xc9);
lcd_wdat(2);
lcd_wcom(0xca);
lcd_wdat(3);
delay(500);
lcd_wcom(0x89);
lcd_wdat(0x20);
lcd_wcom(0x8a);
lcd_wdat(0x20);
lcd_wcom(0xc9);
lcd_wdat(0x20);
lcd_wcom(0xca);
lcd_wdat(0x20);
if(key1==1&&key2==1&&key3==1&&key4==1)
break;
}
break;
}
}
评论0