这儿我买的板子上带有一个SMC1602A LCM。运用也很简单很便利,可是仍是要看它的运用阐明书才行。
先看看引脚阐明,在开发板上,D0-D7接到P0口上,RS接到P3.5,使能信号E接到P3.6上,读写端RW接地(一般不需求读),没有结背光电源。
RAM要比实践显现的多许多(16字×2行),将来做平移就比较便利了。
时序图仍是要看的。
1602的指令码(用于设置体系特点的)
显现形式设定:
38H(16×2显现,5×7点阵,8位数据接口)
显现开关及光标设置:
08H+x(x=4:开显现; x=2:显现光标; x=1:光标闪耀)
04H+x(x=2:读写一个字符后地址指针加1,光标加1; x=1:当写一个字符,整屏左移)
数据指针设置:
80H+地址吗(0H-27H,40H-67H)
其他:
01H:显现清屏(数据指针清零,显现清零)
02H:显现回车(数据指针清零,
1602初始化进程
延时15ms
写指令38H(不检测忙信号)
延时5ms
写指令38H(不检测忙信号)
延时5ms
写指令38H(不检测忙信号)
(今后,每次写指令,读写操作都需求检测忙信号)
写指令38H:显现形式设置
写指令08H:显现封闭
写指令01H:显现清屏
写指令06H:显现光标移动设置
写指令0CH:显现开及光标设置
#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;
}