LCD12864液晶基本程序
2012-09-15 来源:51hei
#include
#include
#define uchar unsingned char
#define uint unsigned int
sbit rs=P2^4;
sbit rw=P2^5;
sbit e=P2^6;
sbit psb=P2^7;
uchar table[]="20100419";
write_12864com(uchar com);
write_12864dat(uchar dat);
void initinal(void);
void display1(void);
void display2(void);
void display3(void);
void delay50us(uint t)//延时函数
{ uint j;
for(;t>0;t--)
for(j=6245;j>0;j--);
}
void main()
{
initnal();
while(1)
{
display1();
display2();
while(1);
}
}
write_12864com(uchar com) //写程序函数
{
rw=0;
rs=0; //表明写程序
delay_50us(1);
P0=com;
delay_50us(10);
E=0;
delay_50us(2);
}
write_12864dat(uchar dat) //写数据函数
{
rw=0;
rs=1;//表明写数据
delay_50us(1);
P0=dat;
delay_50us(10);
E=0;
delay_50us(2);
}
void initinal(void) //初始化函数
{ delay_50us(1);//等待100毫秒
write_2864com(0x30);
delay_50us(4);
write_2864com(0x30);
delay_50us(4);
write_2864com(0x0f);
delay_50us(4);
write_2864com(0x01);//清平显示
delay_50us(240);
write_2864com(0x06);
delay_50us(10);
}
void display1(void)//显示码
{ uchar a, i;
write_12864com(0x80); //写地址
delay_50us(1);
for(i=0;i<16:i++)
{
write_12864dat(a); //写数据
delay_50us(1);
a++;
}
}
void display2(void)//显示汉字
{ uchar a,b,i;
write_12864com(0xBA); //写地址
write_12864com(0xC0);
delay_50us(1);
for(i=0;i<16:i++)
{
write_12864dat(a);
write_12864dat(b); //写数据
delay_50us(1);
b++;
}
}
void display3(void)//更简单的显示函数
{ uchar i;
write_12864com(0x80); //写地址
for(i=0;i<16:i++)
{
write_12864dat(table[i]);
delay_50us(1);
i++;
}
}
进入单片机查看更多内容>>
#include
#define uchar unsingned char
#define uint unsigned int
sbit rs=P2^4;
sbit rw=P2^5;
sbit e=P2^6;
sbit psb=P2^7;
uchar table[]="20100419";
write_12864com(uchar com);
write_12864dat(uchar dat);
void initinal(void);
void display1(void);
void display2(void);
void display3(void);
void delay50us(uint t)//延时函数
{ uint j;
for(;t>0;t--)
for(j=6245;j>0;j--);
}
void main()
{
initnal();
while(1)
{
display1();
display2();
while(1);
}
}
write_12864com(uchar com) //写程序函数
{
rw=0;
rs=0; //表明写程序
delay_50us(1);
P0=com;
delay_50us(10);
E=0;
delay_50us(2);
}
write_12864dat(uchar dat) //写数据函数
{
rw=0;
rs=1;//表明写数据
delay_50us(1);
P0=dat;
delay_50us(10);
E=0;
delay_50us(2);
}
void initinal(void) //初始化函数
{ delay_50us(1);//等待100毫秒
write_2864com(0x30);
delay_50us(4);
write_2864com(0x30);
delay_50us(4);
write_2864com(0x0f);
delay_50us(4);
write_2864com(0x01);//清平显示
delay_50us(240);
write_2864com(0x06);
delay_50us(10);
}
void display1(void)//显示码
{ uchar a, i;
write_12864com(0x80); //写地址
delay_50us(1);
for(i=0;i<16:i++)
{
write_12864dat(a); //写数据
delay_50us(1);
a++;
}
}
void display2(void)//显示汉字
{ uchar a,b,i;
write_12864com(0xBA); //写地址
write_12864com(0xC0);
delay_50us(1);
for(i=0;i<16:i++)
{
write_12864dat(a);
write_12864dat(b); //写数据
delay_50us(1);
b++;
}
}
void display3(void)//更简单的显示函数
{ uchar i;
write_12864com(0x80); //写地址
for(i=0;i<16:i++)
{
write_12864dat(table[i]);
delay_50us(1);
i++;
}
}
上一篇:单片机+1602液晶显示设计
下一篇:PID参数的确定及实际应用
相关文章