從零開始學(xué)單片機(七)液晶接口
先看看引腳說明,在開發(fā)板上,D0-D7接到P0口上,RS接到P3.5,使能信號E接到P3.6上,讀寫端RW接地(通常不需要讀),沒有結(jié)背光電源。
本文引用地址:http://m.butianyuan.cn/article/201611/319878.htmRAM要比實際顯示的多很多(16字×2行),將來做平移就比較方便了。
時序圖還是要看的。
1602的指令碼(用于設(shè)置系統(tǒng)屬性的)
顯示模式設(shè)定:
38H(16×2顯示,5×7點陣,8位數(shù)據(jù)接口)
顯示開關(guān)及光標設(shè)置:
08H+x(x=4:開顯示; x=2:顯示光標; x=1:光標閃爍)
04H+x(x=2:讀寫一個字符后地址指針加1,光標加1; x=1:當寫一個字符,整屏左移)
數(shù)據(jù)指針設(shè)置:
80H+地址嗎(0H-27H,40H-67H)
其他:
01H:顯示清屏(數(shù)據(jù)指針清零,顯示清零)
02H:顯示回車(數(shù)據(jù)指針清零,
1602初始化過程
延時15ms
寫指令38H(不檢測忙信號)
延時5ms
寫指令38H(不檢測忙信號)
延時5ms
寫指令38H(不檢測忙信號)
(以后,每次寫指令,讀寫操作都需要檢測忙信號)
寫指令38H:顯示模式設(shè)置
寫指令08H:顯示關(guān)閉
寫指令01H:顯示清屏
寫指令06H:顯示光標移動設(shè)置
寫指令0CH:顯示開及光標設(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;
}
評論