新聞中心

LCD12864液晶基本程序

作者: 時間:2012-09-15 來源:網(wǎng)絡(luò) 收藏
#includereg52.h>
#includeintrins.h>
#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)//延時函數(shù)
{ 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) //寫程序函數(shù)
{
rw=0;
rs=0; //表明寫程序
delay_50us(1);
P0=com;
delay_50us(10);
E=0;
delay_50us(2);


}
write_12864dat(uchar dat) //寫數(shù)據(jù)函數(shù)
{
rw=0;
rs=1;//表明寫數(shù)據(jù)
delay_50us(1);
P0=dat;
delay_50us(10);
E=0;
delay_50us(2);

}

void initinal(void) //初始化函數(shù)
{ 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;i16:i++)
{
write_12864dat(a); //寫數(shù)據(jù)
delay_50us(1);
a++;
}


}
void display2(void)//顯示漢字
{ uchar a,b,i;
write_12864com(0xBA); //寫地址
write_12864com(0xC0);
delay_50us(1);
for(i=0;i16:i++)
{
write_12864dat(a);
write_12864dat(b); //寫數(shù)據(jù)
delay_50us(1);
b++;

}


}

void display3(void)//更簡單的顯示函數(shù)
{ uchar i;
write_12864com(0x80); //寫地址
for(i=0;i16:i++)
{
write_12864dat(table[i]);

delay_50us(1);
i++;

}


}

pid控制相關(guān)文章:pid控制原理




關(guān)鍵詞: LCD12864液晶 基本程序

評論


技術(shù)專區(qū)

關(guān)閉