LCD 1602 液晶也叫LCD1602 字符型液晶,它是一种专门用来显示字母,数字,符号等的点阵型液晶模块。 一:实验器件 1.pcDuino实验平台 2.LCD1602液晶模块:1块 3.可调电位器:1个 4.导线 5.面包板:1块 二:连接图
具体关系对应下: 1 LCD模块的D4(也就是接口11)连到 pcDuino D4(数字4) 2 LCD模块的D5(也就是接口12)连到 pcDuino D5(数字5) 3 LCD模块的D6(也就是接口13)连到 pcDuino D6(数字6) 4 LCD模块的D7(也就是接口14)连到 pcDuino D7(数字7) 5 LCD模块的RS(也就是接口4)连到 pcDuino D8(数字8) 6 LCD模块的E(也就是接口6)连到 pcDuino D9(数字9) 7 可调电位器我选用的是三孔的,插在面包板的26-28这个位置,同时分别连接两根导线,一根插正极,一根插负极 8 LCD接口3我连接在面包板的27号位置 9 面包板1-2接口(1连接负极,2连接正极) 10 面包板5接口插负极 11 面包板15号连接正极,16号插负极 12 在正负极上连接两根导线,正极连接pcDuino的5V,负极连接pcDuino的GND
三:输入代码 打开Arduino IDE ,代码如下: #include "core.h"
#define RS 8
#define EN 9
#define backlight 10
#define RS_L digitalWrite(RS,LOW)
#define RS_H digitalWrite(RS,HIGH)
#define EN_L digitalWrite(EN,LOW)
#define EN_H digitalWrite(EN,HIGH)
int DB[] = {7,6,5,4};
/********************************************************************/
void write_command(int command)
{
int i,temp;
RS_L;
EN_L;
temp=command & 0xf0;
for (i=0; i < 4; i++)
{
if(temp&0x80)
digitalWrite(DB,HIGH);
else digitalWrite(DB,LOW);
temp <<= 1;
delayMicroseconds(10);
}
EN_H;
delay(1);
EN_L;
temp=(command & 0x0f)<<4;
for (i=0; i < 4; i++)
{
if(temp&0x80)
digitalWrite(DB,HIGH);
else digitalWrite(DB,LOW);
temp <<= 1;
delayMicroseconds(10);
}
EN_H;
delay(1);
EN_L;
}
/********************************************************************/
void write_data(int dat)
{
int i=0,temp;
RS_H;
EN_L;
temp=dat & 0xf0;
for (i=0; i < 4; i++)
{
if(temp&0x80)
digitalWrite(DB,HIGH);
else digitalWrite(DB,LOW);
temp <<= 1;
delayMicroseconds(10);
}
EN_H;
delay(1);
EN_L;
temp=(dat & 0x0f)<<4;
for (i=0; i < 4; i++)
{
if(temp&0x80)
digitalWrite(DB,HIGH);
else digitalWrite(DB,LOW);
temp <<= 1;
delayMicroseconds(10);
}
EN_H;
delay(1);
EN_L;
}
/********************************************************************/
void LCD_write_char( int x,int y,int dat)
{
int address;
if (x ==0) address = 0x80 + y;
else address = 0xC0 + y;
write_command(address);
write_data(dat);
delayMicroseconds(10);
}
/********************************************************************/
void lcd1602_init()
{
int i = 0;
pinMode(RS,OUTPUT);
pinMode(EN,OUTPUT);
pinMode(backlight,OUTPUT);
digitalWrite(backlight,HIGH);
for (i=0; i < 4; i++)
{
pinMode(DB,OUTPUT);
}
delay(100);
write_command(0x28);
delay(50);
write_command(0x06);
delay(50);
write_command(0x0c);
delay(50);
write_command(0x80);
delay(50);
write_command(0x01);
delay(100);
}
/********************************************************************/
void setup (void)
{
lcd1602_init();
}
/********************************************************************/
void loop (void)
{
write_command(0x02);
LCD_write_char(0,2,'W');
LCD_write_char(0,3,'e');
LCD_write_char(0,4,'l');
LCD_write_char(0,5,'c');
LCD_write_char(0,6,'o');
LCD_write_char(0,7,'m');
LCD_write_char(0,8,'e');
LCD_write_char(0,10,'t');
LCD_write_char(0,11,'o');
LCD_write_char(1,4,'p');
LCD_write_char(1,5,'c');
LCD_write_char(1,6,'D');
LCD_write_char(1,7,'u');
LCD_write_char(1,8,'i');
LCD_write_char(1,9,'n');
LCD_write_char(1,10,'o');
//while(1)
delay(100);
}
四:实验结果
哈哈 大功告成 要是想要换其他字母或者数字可以直接在代码里面改哦!
|