<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>

新聞中心

EEPW首頁(yè) > 嵌入式系統 > 設計應用 > 【C51】源碼 5 -- LCD 1602 顯示字符

【C51】源碼 5 -- LCD 1602 顯示字符

作者: 時(shí)間:2016-11-17 來(lái)源:網(wǎng)絡(luò ) 收藏
LCD 1602,正式說(shuō)法叫 LCM 1602(包括了一些外圍電路),一般用來(lái)顯示簡(jiǎn)單的字符,也可以通過(guò)自定義的方式“造字”。

剛學(xué)會(huì )基本的字符顯示,僅僅是字符顯示就大量應用了各種指令格式,姑且在這個(gè)階段寫(xiě)個(gè)程序,總結一下:

本文引用地址:http://dyxdggzs.com/article/201611/315361.htm

程序功能:在 LCD 正中央顯示字符:“Hello World”、“By Fate”

注:LCD 1602 的使用:http://gaebolg.blog.163.com/blog/static/198269068201231665524137/

附上源碼:(初出茅廬,難免有寫(xiě)的不好的地方,僅作備份之用,歡迎指點(diǎn),噴子退散……)

/*------------------------------------------------------------------------------------
LCD 1602 顯示字符,在正中央顯示“Hello World”、“By Fate”
-------------------------------------------------------------------------------------*/

#include
#include // 各種函數,這里使用了 空函數 _nop_()

sbitRS = P2^4;
sbitRW = P2^5;
sbitEN = P2^6;

#defineDataPort P0

voidInit_LCD(void);// 初始化 LCD 顯示

voidLCD_Write_Com(unsigned charc);// 向 LCD 寫(xiě)指令
voidLCD_Write_Data(unsigned chard);// 向 LCD 寫(xiě)數據

bitLCD_Busy(void);// LCD 忙檢測函數,忙 返回 1,閑 返回 0
voidLCD_Clear(void);// 清屏

/*-------------------------------------------------------------------------------------
LCD 參數設定:DL 0 = 數據總線(xiàn)為 4 位 1 = 數據總線(xiàn)為 8 位
    N 0 = 顯示 1 行 1 = 顯示 2 行
   F 0 = 5x7 點(diǎn)陣/每字符1 = 5x10 點(diǎn)陣/每字符
--------------------------------------------------------------------------------------*/
voidLCD_Set_Argument(unsigned charDL,unsigned charN,unsigned charF);

/*-----------------------------------------------------------------------------------------------------------------------------------
LCD 輸入模式設定:ID 0 = 寫(xiě)入新數據后光標左移 1 = 寫(xiě)入新數據后光標右移
   S0 = 寫(xiě)入新數據后顯示屏不移動(dòng)1 = 寫(xiě)入新數據后顯示屏整體右移 1 個(gè)字
------------------------------------------------------------------------------------------------------------------------------------*/
voidLCD_Set_InputMode(unsigned charID,unsigned charS);

/*-----------------------------------------------------------------------
LCD 顯示設定:D 0 = 顯示功能關(guān) 1 = 顯示功能開(kāi)
    C 0 = 無(wú)光標 1 = 有光標
    B 0 = 光標不閃爍 1 = 光標閃爍
------------------------------------------------------------------------*/
voidLCD_Set_DisplayMode(unsigned charD,unsigned charC,unsigned charB);

/*-----------------------------------------------------------
在第 row 行,第 col 列的位置,顯示字符 c
------------------------------------------------------------*/
voidLCD_Write_Char(unsigned charrow,unsigned charcol,unsigned charc);

/*-----------------------------------------------------------
從第 row 行,第 col 列開(kāi)始,顯示字符串 s
------------------------------------------------------------*/
voidLCD_Write_String(unsigned charrow,unsigned charcol,unsigned char*s);

voidDelay(unsigned intt);
voidDelay_ms(unsigned intt); // 延遲 t ms

voidmain (void)
{
Init_LCD();
LCD_Write_Char(1, 3, H);
LCD_Write_Char(1, 4, e);
LCD_Write_Char(1, 5, l);
LCD_Write_Char(1, 6, l);
LCD_Write_Char(1, 7, o);
LCD_Write_String(1, 9, "World!");
LCD_Write_String(2, 5, "By Fate!");
while(1);
}

voidInit_LCD(void)
{
LCD_Set_Argument(1, 1, 0);// 設定基礎參數:數據總線(xiàn) 8 位、顯示 2 行、5x7 點(diǎn)陣/字符
LCD_Set_DisplayMode(0, 0, 0);// 設定顯示模式:關(guān)顯示、關(guān)光標顯示、關(guān)光標閃爍
LCD_Set_InputMode(1, 0);// 設定輸入模式:每輸入一個(gè)字符,光標右移、屏幕不動(dòng)
LCD_Clear();// 清屏
LCD_Set_DisplayMode(1, 0, 0);// 開(kāi)顯示
}

voidLCD_Write_Com(unsigned charc)
{
while(LCD_Busy());
RS = 0;
RW = 0;
EN = 1;
DataPort = c;
_nop_();// 小延時(shí),比 Delay() 小得多,目的:使總線(xiàn)上數據變穩定
EN = 0;// 寫(xiě)操作是 EN 下降沿驅動(dòng)
}

voidLCD_Write_Data(unsigned chard)
{
while(LCD_Busy());
RS = 1;
RW = 0;
EN = 1;
DataPort = d;
_nop_();
EN = 0;
}

bitLCD_Busy(void)
{
DataPort = 0xFF;
RS = 0;
RW = 1;
EN = 0;
_nop_();
EN = 1;// 讀操作是 EN = 1 驅動(dòng)
return(bit)(DataPort & 0x80);// 強制轉換到 bit 時(shí),除非原數據等于 0,bit = 0,否則 bit = 1
}

voidLCD_Clear(void)
{
LCD_Write_Com(0x01);
Delay_ms(5);
}

voidLCD_Set_Argument(unsigned charDL,unsigned charN,unsigned charF)
{
DL <<= 4;// 指令格式?jīng)Q定了要移位,具體看指令格式要求
N <<= 3;
F <<= 2;
LCD_Write_Com(0x20 | DL | N | F);
Delay_ms(5);
}

voidLCD_Set_InputMode(unsigned charID,unsigned charS)
{
ID <<= 1;
LCD_Write_Com(0x04 | ID | S);
Delay_ms(5);
}

voidLCD_Set_DisplayMode(unsigned charD,unsigned charC,unsigned charB)
{
D <<= 2;
C <<= 1;
LCD_Write_Com(0x08 | D | C | B);
Delay_ms(5);
}

voidLCD_Write_Char(unsigned charrow,unsigned charcol,unsigned charc)
{
if(row == 1) LCD_Write_Com(0x80 + col - 0x01); // 由指令格式可知,DB7 = 1,因此要加上 80H
else if(row == 2) LCD_Write_Com(0xC0 + col - 0x01);
LCD_Write_Data(c);
}

voidLCD_Write_String(unsigned charrow,unsigned charcol,unsigned char*s)
{
if(row == 1) LCD_Write_Com(0x80 + col - 0x01);
else if(row == 2) LCD_Write_Com(0xC0 + col - 0x01);
while(*s) {
LCD_Write_Data(*s);
s++;
}
}

voidDelay(unsigned intt)
{
while(t--);
}

voidDelay_ms(unsigned intt)// 根據測試,可以相當近似的表示 t ms
{
while(t--) {
Delay(245);
Delay(245);
}
}



關(guān)鍵詞: C51LCD1602顯示字

評論


技術(shù)專(zhuān)區

關(guān)閉
国产精品自在自线亚洲|国产精品无圣光一区二区|国产日产欧洲无码视频|久久久一本精品99久久K精品66|欧美人与动牲交片免费播放
<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>