新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 44780 16x2 字符液晶屏驅(qū)動演示程序總線方式

44780 16x2 字符液晶屏驅(qū)動演示程序總線方式

作者: 時(shí)間:2011-04-01 來源:網(wǎng)絡(luò) 收藏

連接線圖:LCM-------51 LCM-------51 LCM--------51
DB0-----P0.0 DB4-----P0.4 RW-------P2.0
DB1-----P0.1 DB5-----P0.5 RC-------P2.1
DB2-----P0.2 DB6-----P0.6 E--------P2.7 =>74ls00+wr+rd
DB3-----P0.3 DB7-----P0.7 VLCD接1K2電阻到GND

本文引用地址:http://www.butianyuan.cn/article/150900.htm

[注]:AT89C51的晶振頻率為12MHz
//#pragma src// 產(chǎn)生匯編文件
#include reg51.h>
#includeintrins.h>

變量類型標(biāo)識的宏定義
#defineUchar unsigned char
#define Uint unsigned int

LCM1602A端口地址定義

char xdata Lcd1602CmdPort _at_ 0x7cff;//E=1 RS=0 RW=0
char xdata Lcd1602WdataPort _at_ 0x7eff;//E =1 RS=1 RW=0
char xdata Lcd1602StatusPort _at_ 0x7dff;//CS=1 RS=0 RW=1

#define Busy0x80 // 忙判別位


code char exampl[]=For an example. - By xiaoqin;

void Delay400Ms(void);
void Delay5Ms(void);
void LcdWriteData( char dataW );
void LcdWriteCommand( Uchar CMD,Uchar AttribC );
void LcdReset( void );
void Display( Uchar dd );
void DispOneChar(Uchar x,Uchar y,Uchar Wdata);
void ePutstr(Uchar x,Uchar y, Uchar code *ptr);

測試主

void main(void)
{
Uchar temp;

Delay400Ms();// 啟動時(shí)必須的延時(shí),等待lcm進(jìn)入工作狀態(tài)

LcdReset(); // 這也是必需的....初始化
temp = 32;
ePutstr(0,0,exampl);// 上面一行顯示一個(gè)預(yù)定

Delay400Ms(); // 保留顯示內(nèi)容
Delay400Ms();
Delay400Ms();
Delay400Ms();
Delay400Ms();
Delay400Ms();
Delay400Ms();
Delay400Ms();

while(1)
{
temp = 0x7f;// 只顯示ASCII

if (temp32)temp=32;// 屏蔽控制,不予顯示
Display( temp++ );

Delay400Ms();
}
}
顯示字符串
void ePutstr(Uchar x,Uchar y, Uchar code *ptr) {
Uchar i,l=0;
while (ptr[l] >31){l++;};
for (i=0;il;i++) {
DispOneChar(x++,y,ptr[i]);
if ( x == 16 ){
x = 0; y ^= 1;
}
}
}

一行連續(xù)字符串,配合上位移動字串
void Display( Uchar dd ) {

Uchar i;

for (i=0;i16;i++) {

DispOneChar(i,1,dd++);

dd = 0x7f;
if (dd32) dd=32;
}
}

顯示光標(biāo)定位
void LocateXY( char posx,char posy) {

Uchar temp;

temp = posx 0xf;
posy = 0x1;
if ( posy )temp |= 0x40;
temp |= 0x80;
LcdWriteCommand(temp,0);
}

按指定位置顯示數(shù)出一個(gè)字符
void DispOneChar(Uchar x,Uchar y,Uchar Wdata) {

LocateXY( x, y );// 定位顯示地址
LcdWriteData( Wdata );// 寫字符
}
初始化, 必須按照產(chǎn)品資料介紹的初始化過程進(jìn)行
void LcdReset( void ) {

LcdWriteCommand( 0x38, 0);// 顯示模式設(shè)置(不檢測忙信號)
Delay5Ms();
LcdWriteCommand( 0x38, 0);// 共三次
Delay5Ms();
LcdWriteCommand( 0x38, 0);
Delay5Ms();

LcdWriteCommand( 0x38, 1);// 顯示模式設(shè)置(以后均檢測忙信號)
LcdWriteCommand( 0x08, 1);// 顯示關(guān)閉
LcdWriteCommand( 0x01, 1);// 顯示清屏
LcdWriteCommand( 0x06, 1);// 顯示光標(biāo)移動設(shè)置
LcdWriteCommand( 0x0c, 1);// 顯示開及光標(biāo)設(shè)置
}


寫控制字符子程序: E=1 RS=0 RW=0
void LcdWriteCommand( Uchar CMD,Uchar AttribC ) {

if (AttribC) while( Lcd1602StatusPort Busy );// 檢測忙信號?
Lcd1602CmdPort = CMD;
}

當(dāng)前位置寫字符子程序: E =1 RS=1 RW=0
void LcdWriteData( char dataW ) {

while( Lcd1602StatusPort Busy );// 檢測忙信號
Lcd1602WdataPort = dataW;
}

// 短延時(shí)
void Delay5Ms(void)
{
Uint i = 5552;
while(i--);
}

//長延時(shí)
void Delay400Ms(void)
{
Uchar i = 5;
Uint j;
while(i--)
{
j=7269;
while(j--);
};
}



評論


相關(guān)推薦

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

關(guān)閉