#include<reg51.h>
#include<intrins.h>
#include<stdlib.h>
#define uchar unsigned char
#define uint unsigned int
#define LCD_data P0
/*uchar code dis1[]="0123456789";*/
uchar code dis2[]="www.12345.com";
uchar code dis3[]="学单片机";
uchar code dis4[]="--------";
uchar unm;
sbit dula=P2^6;
sbit wela=P2^7;
sbit lcdrs=P3^5;
sbit lcden=P3^4;
sbit lcdrw=P3^6;
sbit lcdPSB=P3^7;
void delay(uint x)
{
uint i,j;
for(i=x;i>0;i--)
for(j=110;j>0;j--);
}
void write_com(uint com)
{
lcdrs=0;
lcdrw=0;
P0=com;
delay(10);
lcden=1;
delay(10);
lcden=0;
}
void write_data(uint dat)
{
lcdrs=1;
lcdrw=0;
P0=dat;
delay(10);
lcden=1;
delay(10);
lcden=0;
}
void init()
{
lcdPSB=1;
write_com(0x30);
delay(5);
write_com(0x0c);
delay(5);
write_com(0x0c);
delay(5);
write_com(0x01);
}
void pos(uchar x,uchar y)
{
uchar pos;
if(x==0)
{x=0x80;}
else if(x==1)
{x=0x90;}
else if(x==2)
{x=0x88;}
else if(x==3)
{x=0x98;}
pos=x+y;
write_com(pos);
}
/*void makerand()
{
uint ran;
ran=rand();
dis1[0]=ran/10000+0x30;
dis1[1]=ran%10000/1000+0x30;
dis1[2]=ran%1000/100+0x30;
dis1[3]=ran%100/10+0x30;
dis1[4]=ran%10+0x30;
ran=rand();
dis1[5]=ran/10000+0x30;
dis1[6]=ran%10000/1000+0x30;
dis1[7]=ran%1000/100+0x30;
dis1[8]=ran%100/10+0x30;
dis1[9]=ran%10+0x30;
}*/
void main()
{ uchar i;
dula=0;
wela=0;
delay(10);
init();
pos(1,0);
i=0;
while(dis2[i]!='\0')
{
write_data(dis2[i]);
i++;
}
pos(2,0);
i=0;
while(dis3[i]!='\0')
{
write_data(dis3[i]);
i++;
}
pos(3,0);
i=0;
while(dis4[i]!='\0')
{
write_data(dis4[i]);
i++;
}
while(1);
/*{
pos(0,0);
makerand();
for(i=0;i<10;i++)
{
write_data(dis1[i]);
}
}*/
}
|