歡迎,客人 | 請登錄 | 免費注冊 | 忘記密碼?

 
當前位置: 首頁 » 綜合資訊 » 收單pos機 » POS機流量卡 »

液晶顯示源程序代碼及相關(guān)注釋

發(fā)布日期:2012-04-18  中國POS機網(wǎng)

**************************************************
*yj.c
*連線圖:
* DB0---DPROT.0 DB4---DPROT.4 RS-------------P2.5
* DB1---DPROT.1 DB5---DPROT.5 RW-------------P2.6
* DB2---DPROT.2 DB6---DPROT.6 E--------------P2.7
* DB3---DPROT.3 DB7---DPROT.7 VLCD接10K可調(diào)電阻到GND*
*80C51的晶振頻率為12MHz
*液晶顯示程序
***************************************************/
#include "reg51.h"
#include
#include
#define DPORT P0
#define uchar unsigned char
sbit RS = P2^5;
sbit RW = P2^6;
sbit E = P2^7;

uchar XPOS; //列方向地址指針
uchar Ypos; //行方向地址指針


#define NoDisp 0
#define NoCur 1
#define CurNoFlash 2
#define CurFlash 3
/*延時程序
由Delay參數(shù)確定延遲時間
*/

void LcdWcn(uchar);
void LcdWc(uchar);
void WriteChar(uchar);
void LcdPos();
void LcdWd(uchar);
void LcdWdn(uchar);


void mDelay(unsigned int Delay)
{ unsigned int i;
for(;Delay>0;Delay--)
{ for(i=0;i<124;i++)
{;}
}
}

/*光標設置命令
Cur 為設定光標參數(shù)
*/
void SetCur(uchar Cur)
{ switch(Cur)
{ case 0x0:
{ LcdWc(0x08); //關(guān)顯示
break;
}
case 0x1:
{ LcdWc(0x0c); //開顯示但無光標
break;
}
case 0x2:
{ LcdWc(0x0e); //開顯示有光標但不閃爍
break;
}
case 0x3:
{ LcdWc(0x0f); //開顯示有光標且閃爍
break;
}
default: break;
}
}
/*清命令
*/
void ClrLcd()
{ LcdWc(0x01);
}
/*在指定的行與列顯示
*/
void WriteChar(uchar c)
{ LcdPos();
LcdWd(c);
}
/*正常讀寫操作之前檢測LCD控制器
*/
void WaitIdle()
{ uchar tmp;
DPORT=0xff;
RS=0;
RW=1;
E=1;
_nop_();
for(;;)
{ tmp=DPORT;
tmp&=0x80;
if(tmp==0)
break;
}
E=0;
}

/*不檢測忙的寫字符子程序
*/
void LcdWdn(uchar c)
{
RS=1;
RW=0;
DPORT=c; //寫入待寫字符
E=1;
_nop_();E=0;
}
/*帶忙檢測的寫字符子程序
*/
void LcdWd(uchar c)
{ WaitIdle();
LcdWdn(c);
}

/*檢測忙信號的送控制字子程序*/
void LcdWcn(uchar c)
{ RS=0;
RW=0;
DPORT=c;
E=1;
_nop_();
E=0;
}
/*檢測忙信號的送控制字子程序*/
void LcdWc(uchar c)
{ WaitIdle();
LcdWcn(c);
}
void LcdPos()
{ uchar tmp;
Xpos&=0x0f; //16xx型液晶的范圍是0~15
Ypos&=0x01; //Y的范圍是0~1
tmp=Xpos;
if(Ypos==1)
{ tmp+=0x40;
}
tmp|=0x80;
LcdWc(tmp);
}

/*LCD的復位程序
*/
void RstLcd()
{ mDelay(15); //延時15ms
LcdWcn(0x38);
mDelay(5);
LcdWcn(0x38);
mDelay(5);
LcdWcn(0x38);

LcdWc(0x38);
LcdWc(0x08);
LcdWc(0x01);
LcdWc(0x06);
LcdWc(0x0c);
}

void WriteString(char s[])
{ uchar pS=0;
for(;;)
{ WriteChar(s[pS]);
pS++;
if(s[pS]==0)
break;
if(++Xpos>=15) //每行最多顯示16個字符
break;
}
}

void main()
{ uchar s1[]="Hellow World!";
RstLcd(); //復位LCD
ClrLcd();
SetCur(CurFlash); //光標顯示且閃爍
Xpos=2;
Ypos=1;
WriteString(s1);
for(;;)
{;}
}
 

打賞
 
?
免責聲明:
本網(wǎng)站部分內(nèi)容來源于網(wǎng)站會員、合作媒體、企業(yè)機構(gòu)、網(wǎng)友提供和互聯(lián)網(wǎng)的公開資料等,僅供參考。本網(wǎng)站對站內(nèi)所有資訊的內(nèi)容、觀點保持中立,不對內(nèi)容的準確性、可靠性或完整性提供任何明示或暗示的保證。如果有侵權(quán)等問題,請及時聯(lián)系我們,我們將在收到通知后第一時間妥善處理該部分內(nèi)容。

圖文推薦

您在本欄的歷史瀏覽
熱門資訊

中國POS機行業(yè)權(quán)威門戶網(wǎng)站 引領(lǐng)行業(yè)發(fā)展


微信號:pos580com

網(wǎng)站首頁 | 網(wǎng)站地圖 | 誠征英才 | 關(guān)于我們 | 聯(lián)系方式 | 使用協(xié)議 | 版權(quán)隱私 | 排名推廣 | 廣告服務 | 積分換禮 | 網(wǎng)站留言 | RSS訂閱

版權(quán)所有:POS機網(wǎng) 北京瑞紀華人科技有限公司 京ICP證060984  |  京ICP備07503063號

聯(lián)系電話:010-51658061 E-mail:bjsale#pos580.com(請把#替換成@)在線QQ:841617225

站所有信息均屬本站版權(quán)所有,如需轉(zhuǎn)載請注明來源地址 域名:jensthetc.com