專注電子技術(shù)學(xué)習(xí)與研究
當(dāng)前位置:單片機(jī)教程網(wǎng) >> MCU設(shè)計(jì)實(shí)例 >> 瀏覽文章

單片機(jī)LCD1602液晶顯示

作者:李俊軒   來源:本站原創(chuàng)   點(diǎn)擊數(shù):  更新時(shí)間:2013年07月18日   【字體:

  單片機(jī)LCD的顯示比起數(shù)碼管用起來簡單很多,而且實(shí)用性更強(qiáng),所以我覺得學(xué)單片機(jī)學(xué)好液晶的顯示也是一個(gè)很重要的模塊。下面我就用1062顯示我的名字以及PLAY UP。佑停┌伞:呛。是參考的這篇:http://www.torrancerestoration.com/mcu/827.html 里面有很詳細(xì)的液晶的資料.隨著學(xué)習(xí)的深入,感覺單片機(jī)越來越好玩了,雖然現(xiàn)在學(xué)的都還很膚淺,但覺得每次可以把自己學(xué)到的東西,用文字記錄下來也是一種享受。

 

程序:#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int

sbit LCDRS=P3^0;
sbit LCDR_W=P3^1;
sbit LCDE=P3^2;

uchar num[]="Li Junxuan ";
uchar num1[]="play up!";

void delay(uchar z)

{
 int i,j;
 for(i=0;i<z;i++);
 for(j=0;j<120;j++);
}
void write_com(uchar com)
{
 LCDRS=0;

 P2=com; 

 delay(5);

 LCDR_W=0;

 LCDE=1;

 delay(5);
 LCDE=0;

}
void write_dat(uchar dat)

{
 LCDRS=1;

 P2=dat; 

 delay(5);
 LCDR_W=0;
 LCDE=1;
 delay(5);
 LCDE=0;
}

void main()
{
 int x,y;
 LCDE=0;
  
 write_com(0x3c);

 write_com(0x14);

    write_com(0x0f);

 for(x=0;x<10;x++)

 {
 write_dat(num[x]);}

 write_com(0x80+0x40);
 for(y=0;y<8;y++)
 {
 write_dat(num1[y]);

 }

 
 while(1);
 
}

關(guān)閉窗口

相關(guān)文章