|
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit rs=P3^5;
sbit wr=P3^6;
sbit lcden=P3^4;
sbit dula=P2^6;
sbit wela=P2^7;
uchar table1[]="nihao";
//uchar table2[]="WWW:51hei:COM";
void delay(uint x)
{
uint a,b;
for(a=x;a>0;a--)
for(b=10;b>0;b--);
}
void write_com(uchar com) //些命令,RS=0
{
P0=com;
wr=0;
rs=0;
lcden=0;
delay(10);
lcden=1;
delay(10);
lcden=0;
}
void write_data(uchar dat) //寫數(shù)據(jù),RS=1
{
P0=dat;
wr=0;
rs=1;
lcden=0;
delay(10);
lcden=1;
delay(10);
lcden=0;
}
void init()
{
dula=0;
wela=0;
write_com(0x38); //顯示模式設(shè)置:16×2顯示,5×7點(diǎn)陣,8位數(shù)據(jù)接口
delay(20);
write_com(0x0f); //顯示模式設(shè)置
delay(20);
write_com(0x06); //顯示模式設(shè)置:光標(biāo)右移,字符不移
delay(20);
write_com(0x01); //清屏幕指令,將以前的顯示內(nèi)容清除
delay(20);
}
void main()
{
uchar a;
init(); //1602初始化
write_com(0x80); //設(shè)置所要顯示字符的位置為第一行第一列
a=0;
while(table1[a]!='\0') //只要沒有寫到結(jié)束標(biāo)志,就繼續(xù)寫
{ //這是寫字符的第一種方法,用while循環(huán)。
write_data(table1[a]);
a++;
}
// write_com(0x80+0x40); //設(shè)置第二行首字符顯示的位置,為第二行,第一列
// a=0;
// for(a=0;a<13;a++) //總共要顯示13個(gè)字符,故循環(huán)十三次。
// { //這是寫字符的第二種方法,用for循環(huán)
// write_data(table2[a]);
// delay(10);
// }
while(1);
}
|
評(píng)分
-
查看全部評(píng)分
|