從零開(kāi)始學(xué)單片機(jī)(七)液晶接口
這里我買(mǎi)的板子上帶有一個(gè)SMC1602A LCM。使用也很簡(jiǎn)單很方便,但是還是要看它的使用說(shuō)明書(shū)才行。
先看看引腳說(shuō)明,在開(kāi)發(fā)板上,D0-D7接到P0口上,RS接到P3.5,使能信號(hào)E接到P3.6上,讀寫(xiě)端RW接地(通常不需要讀),沒(méi)有結(jié)背光電源。
RAM要比實(shí)際顯示的多很多(16字×2行),將來(lái)做平移就比較方便了。
時(shí)序圖還是要看的。
1602的指令碼(用于設(shè)置系統(tǒng)屬性的)
顯示模式設(shè)定:
38H(16×2顯示,5×7點(diǎn)陣,8位數(shù)據(jù)接口)
顯示開(kāi)關(guān)及光標(biāo)設(shè)置:
08H+x(x=4:開(kāi)顯示; x=2:顯示光標(biāo); x=1:光標(biāo)閃爍)
04H+x(x=2:讀寫(xiě)一個(gè)字符后地址指針加1,光標(biāo)加1; x=1:當(dāng)寫(xiě)一個(gè)字符,整屏左移)
數(shù)據(jù)指針設(shè)置:
80H+地址嗎(0H-27H,40H-67H)
其他:
01H:顯示清屏(數(shù)據(jù)指針清零,顯示清零)
02H:顯示回車(chē)(數(shù)據(jù)指針清零,
1602初始化過(guò)程
延時(shí)15ms
寫(xiě)指令38H(不檢測(cè)忙信號(hào))
延時(shí)5ms
寫(xiě)指令38H(不檢測(cè)忙信號(hào))
延時(shí)5ms
寫(xiě)指令38H(不檢測(cè)忙信號(hào))
(以后,每次寫(xiě)指令,讀寫(xiě)操作都需要檢測(cè)忙信號(hào))
寫(xiě)指令38H:顯示模式設(shè)置
寫(xiě)指令08H:顯示關(guān)閉
寫(xiě)指令01H:顯示清屏
寫(xiě)指令06H:顯示光標(biāo)移動(dòng)設(shè)置
寫(xiě)指令0CH:顯示開(kāi)及光標(biāo)設(shè)置
#include
#define LCD_Data P0
sbit LCD_RS = P3^5;
sbit LCD_E = P3^4;
void delay(unsigned int ms);
void WriteCommand(unsigned char com);
void WriteData(unsigned char chr);
void ini_LCD();
void main(void)
{
ini_LCD();
WriteData('A');
WriteData('B');
WriteData('C');
WriteData('D');
WriteData('E');
while(1)
{
}
}
void delay(unsigned int ms)
{
unsigned int Temp;
while(ms--){Temp=82;while(Temp--);}
}
void ini_LCD()
{
delay(15);
WriteCommand(0x38);
delay(5);
WriteCommand(0x38);
delay(5);
WriteCommand(0x38);
delay(5);
WriteCommand(0x38);
WriteCommand(0x0f);
WriteCommand(0x06);
WriteCommand(0x01);
WriteCommand(0x80);
}
void WriteCommand(unsigned char com)
{
LCD_RS = 0;
LCD_Data = com;
delay(1);
LCD_E = 1;
delay(2);
LCD_E = 0;
LCD_RS = 1;
}
void WriteData(unsigned char chr)
{
LCD_RS = 1;
LCD_Data = chr;
delay(1);
LCD_E = 1;
delay(2);
LCD_E = 0;
LCD_RS = 0;
}
編輯:admin 最后修改時(shí)間:2018-05-19